diff --git a/include/cyclone/runtime.h b/include/cyclone/runtime.h index 21b204c5..119338e9 100644 --- a/include/cyclone/runtime.h +++ b/include/cyclone/runtime.h @@ -719,6 +719,7 @@ uint32_t Cyc_utf8_decode(uint32_t* state, uint32_t* codep, uint32_t byte); int Cyc_utf8_count_code_points(uint8_t* s); uint32_t Cyc_utf8_validate_stream(uint32_t *state, char *str, size_t len); uint32_t Cyc_utf8_validate(char *str, size_t len); +int uint32_num_bytes(uint32_t val); /**@}*/ #endif /* CYCLONE_RUNTIME_H */ diff --git a/runtime.c b/runtime.c index da3f255c..79badbf9 100644 --- a/runtime.c +++ b/runtime.c @@ -178,6 +178,7 @@ void pack_env_variables(void *data, object k) svar->hdr.grayed = 0; svar->tag = string_tag; svar->len = eqpos - e; + svar->num_cp = svar->len; // TODO: proper UTF-8 support! svar->str = alloca(sizeof(char) * (svar->len)); strncpy(svar->str, e, svar->len); (svar->str)[svar->len] = '\0'; @@ -189,6 +190,7 @@ void pack_env_variables(void *data, object k) sval->hdr.grayed = 0; sval->tag = string_tag; sval->len = strlen(eqpos); + sval->num_cp = sval->len; // TODO: proper UTF-8 support! sval->str = eqpos; set_pair(tmp, svar, sval); set_pair(p, tmp, NULL); @@ -6553,4 +6555,12 @@ uint32_t Cyc_utf8_validate(char *str, size_t len) { return state; } +int uint32_num_bytes(uint32_t x) { + // TODO: could compute log(val) / log(256) + if (x < 0x100) return 1; + if (x < 0x10000) return 2; + if (x < 0x1000000) return 3; + return 4; +} + ////////////// END UTF-8 Section //////////////