[dev] Patch: plain.php (take 2)
Marc Jauvin
marc at register4less.com
Thu May 29 10:43:45 PDT 2003
OK, here is a "smarter" way of fixing tab expansion.
Please, let me know if this is not acceptable.
--
Marc Jauvin
450-441-5458
http://register4less.com
-------------- next part --------------
Index: plain.php
===================================================================
RCS file: /repository/imp/lib/MIME/Viewer/plain.php,v
retrieving revision 1.21
diff -u -r1.21 plain.php
--- plain.php 16 May 2003 15:26:13 -0000 1.21
+++ plain.php 29 May 2003 17:40:00 -0000
@@ -84,8 +84,11 @@
// Filter bad language.
$text = IMP::filterText($text);
+ // Expand Tabs with respect to tab stops
+ $tabstop = 8; // FIXME: we could add that as a user preference
+ $text = $this->smartExpandTabs($text,$tabstop);
+
// Wordwrap.
- $text = str_replace("\t", ' ', $text);
$text = str_replace(' ', ' ', $text);
$text = str_replace("\n ", "\n ", $text);
if ($text{0} == ' ') {
@@ -154,4 +157,16 @@
}
}
+ function smartExpandTabs($text, $tabstop=8)
+ {
+ $lines = explode("\n", $text);
+ for ($i = 0; $i < sizeof($lines); $i++) {
+ while ($pos=strpos($lines[$i], "\t")) {
+ $n_space = $tabstop - ($pos % $tabstop);
+ $new_str = str_repeat(" ", $n_space);
+ $lines[$i] = substr_replace($lines[$i], $new_str, $pos, 1);
+ }
+ }
+ return implode("\n", $lines);
+ }
}
More information about the dev
mailing list