Browse Source

move a lonely function to unicode support file

pull/1/head
Sami Vaarala 12 years ago
parent
commit
20ce4e6095
  1. 1
      src/duk_unicode.h
  2. 23
      src/duk_unicode_support.c

1
src/duk_unicode.h

@ -48,6 +48,7 @@ int duk_unicode_get_xutf8_length(duk_u32 x);
size_t duk_unicode_encode_xutf8(duk_u32 x, duk_u8 *out);
size_t duk_unicode_encode_cesu8(duk_u32 x, duk_u8 *out);
duk_u32 duk_unicode_xutf8_get_u32(duk_hthread *thr, duk_u8 **ptr, duk_u8 *ptr_start, duk_u8 *ptr_end);
duk_u32 duk_unicode_unvalidated_utf8_length(duk_u8 *data, duk_u32 blen);
int duk_unicode_is_whitespace(int x);
int duk_unicode_is_line_terminator(int x);
int duk_unicode_is_identifier_start(int x);

23
src/duk_unicode_support.c

@ -215,6 +215,29 @@ duk_u32 duk_unicode_xutf8_get_u32(duk_hthread *thr, duk_u8 **ptr, duk_u8 *ptr_st
return 0; /* never here */
}
/* (extended) utf-8 length without codepoint encoding validation, used
* for string interning (should probably be inlined).
*/
duk_u32 duk_unicode_unvalidated_utf8_length(duk_u8 *data, duk_u32 blen) {
duk_u8 *p = data;
duk_u8 *p_end = data + blen;
duk_u32 clen = 0;
while (p < p_end) {
duk_u8 x = *p++;
if (x < 0x80) {
clen++;
} else if (x >= 0xc0 ) {
/* 10xxxxxx = continuation chars (0x80...0xbf), above that
* initial bytes.
*/
clen++;
}
}
return clen;
}
/*
* Unicode range matcher
*

Loading…
Cancel
Save