mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-14 08:17:35 +02:00
Added utility function and stubs
This commit is contained in:
parent
6c4dd4b740
commit
13e260300f
2 changed files with 11 additions and 0 deletions
|
@ -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 */
|
||||
|
|
10
runtime.c
10
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 //////////////
|
||||
|
|
Loading…
Add table
Reference in a new issue