diff options
author | John MacFarlane <jgm@berkeley.edu> | 2014-09-29 22:59:46 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2014-09-29 22:59:46 -0700 |
commit | d9f7581443bd786e7d17532f6678efd2ee77c26f (patch) | |
tree | 831a33dc8990e3b85ea068b361750702f8e3f40a /src/detab.c | |
parent | de1e28217f0da80b928bca0ca09541c0401314ee (diff) | |
parent | c006aececef112f61dd44cad43f0596221f29700 (diff) |
Merge branch 'master' into newemphasis
Conflicts:
Makefile
js/stmd.js
Diffstat (limited to 'src/detab.c')
-rw-r--r-- | src/detab.c | 48 |
1 files changed, 0 insertions, 48 deletions
diff --git a/src/detab.c b/src/detab.c deleted file mode 100644 index e03fcf7..0000000 --- a/src/detab.c +++ /dev/null @@ -1,48 +0,0 @@ -#include "bstrlib.h" - -// UTF-8 aware detab: assumes s has no newlines, or only a final newline. -// Return 0 on success, BSTR_ERR if invalid UTF-8. -extern int bdetab(bstring s, int utf8) -{ - unsigned char c; - int pos = 0; // a count of characters - int byte = 0; // a count of bytes - int high_chars_to_skip = 0; - int numspaces = 0; - while ((c = bchar(s, byte))) { - if (utf8 && high_chars_to_skip > 0) { - if (c >= 0x80) { - high_chars_to_skip--; - byte++; - } else { - return BSTR_ERR; // invalid utf-8 - } - } else if (c == '\t') { - bdelete(s, byte, 1); // delete tab character - numspaces = 4 - (pos % 4); - binsertch(s, byte, numspaces, ' '); - byte += numspaces; - pos += numspaces; - } else if (c <= 0x80 || !utf8) { - byte++; - pos++; - } else { // multibyte utf8 sequences - if (c >> 1 == 0176) { - high_chars_to_skip = 5; - } else if (c >> 2 == 076) { - high_chars_to_skip = 4; - } else if (c >> 3 == 036) { - high_chars_to_skip = 3; - } else if (c >> 4 == 016) { - high_chars_to_skip = 2; - } else if (c >> 5 == 06) { - high_chars_to_skip = 1; - } else { - return BSTR_ERR; // invalid utf-8 - } - pos++; - byte++; - } - } - return 0; -} |