/** * Preprocess the text. * * This unifies line endings and replaces tabs by spaces. * * @param Text $text * @return void */ protected function prepare(Text $text) { // Unify line endings $text->replaceString("\r\n", "\n"); $text->replaceString("\r", "\n"); // Replace tabs by spaces $text->replace('/(.*?)\\t/', function (Text $whole, Text $string) { $tabWidth = 4; return $string . str_repeat(' ', $tabWidth - $string->getLength() % $tabWidth); }); }
public function handleBackslashes(Text $content) { $content->replaceString(['\\\\', '\\!', '\\"', '\\#', '\\$', '\\%', '\\&', '\\\'', '\\(', '\\)', '\\*', '\\+', '\\,', '\\-', '\\.', '\\/', '\\:', '\\;', '\\<', '\\=', '\\>', '\\?', '\\@', '\\[', '\\]', '\\^', '\\_', '\\`', '\\{', '\\|', '\\}', '\\~'], ['\\', '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '=', '>', '?', '@', '[', ']', '^', '_', '`', '{', '|', '}', '~']); }