@@ -1895,12 +1895,14 @@ public function isReference($stackPtr)
1895
1895
* Returns the content of the tokens from the specified start position in
1896
1896
* the token stack for the specified length.
1897
1897
*
1898
- * @param int $start The position to start from in the token stack.
1899
- * @param int $length The length of tokens to traverse from the start pos.
1898
+ * @param int $start The position to start from in the token stack.
1899
+ * @param int $length The length of tokens to traverse from the start pos.
1900
+ * @param int $origContent Whether the original content or the tab replaced
1901
+ * content should be used.
1900
1902
*
1901
1903
* @return string The token contents.
1902
1904
*/
1903
- public function getTokensAsString ($ start , $ length )
1905
+ public function getTokensAsString ($ start , $ length, $ origContent = false )
1904
1906
{
1905
1907
$ str = '' ;
1906
1908
$ end = ($ start + $ length );
@@ -1909,7 +1911,13 @@ public function getTokensAsString($start, $length)
1909
1911
}
1910
1912
1911
1913
for ($ i = $ start ; $ i < $ end ; $ i ++) {
1912
- $ str .= $ this ->tokens [$ i ]['content ' ];
1914
+ // If tabs are being converted to spaces by the tokeniser, the
1915
+ // original content should be used instead of the converted content.
1916
+ if ($ origContent === true && isset ($ this ->tokens [$ i ]['orig_content ' ]) === true ) {
1917
+ $ str .= $ this ->tokens [$ i ]['orig_content ' ];
1918
+ } else {
1919
+ $ str .= $ this ->tokens [$ i ]['content ' ];
1920
+ }
1913
1921
}
1914
1922
1915
1923
return $ str ;
0 commit comments