diff options
author | Patrick McCarty <pnorcks@gmail.com> | 2009-10-29 15:46:01 -0700 |
---|---|---|
committer | Patrick McCarty <pnorcks@gmail.com> | 2009-11-12 16:37:48 -0800 |
commit | f781f3307435c46ed3ff21708f75261dc30d2e37 (patch) | |
tree | 24e87dd6be604910f431c97bf965117e871676a1 /lily/misc.cc | |
parent | 164cdde840c75ff40af84c951a4436f94a194ea0 (diff) |
Move UTF-8 char length routine into separate function.
Diffstat (limited to 'lily/misc.cc')
-rw-r--r-- | lily/misc.cc | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lily/misc.cc b/lily/misc.cc index ee55a00c7e..2499a09e37 100644 --- a/lily/misc.cc +++ b/lily/misc.cc @@ -9,6 +9,7 @@ #include "misc.hh" +#include "warn.hh" /* Return the 2-log, rounded down @@ -86,3 +87,22 @@ camel_case_to_lisp_identifier (string in) return result; } +vsize +utf8_char_len (char current) +{ + vsize char_len = 1; + + // U+10000 - U+10FFFF + if ((current & 0xF0) == 0xF0) + char_len = 4; + // U+0800 - U+FFFF + else if ((current & 0xE0) == 0xE0) + char_len = 3; + // U+0080 - U+07FF + else if ((current & 0xC0) == 0xC0) + char_len = 2; + else if (current & 0x80) + programming_error ("invalid UTF-8 string"); + + return char_len; +} |