mirror of
https://github.com/deltachat/deltachat-core.git
synced 2025-10-03 17:59:19 +02:00
add utf8-len function
This commit is contained in:
parent
01a20fbf21
commit
77a714a1d3
3 changed files with 13 additions and 3 deletions
|
@ -619,6 +619,9 @@ void stress_functions(dc_context_t* context)
|
||||||
assert( !DC_EVENT_RETURNS_STRING(100) );
|
assert( !DC_EVENT_RETURNS_STRING(100) );
|
||||||
assert( !DC_EVENT_RETURNS_STRING(300) );
|
assert( !DC_EVENT_RETURNS_STRING(300) );
|
||||||
assert( !DC_EVENT_RETURNS_STRING(400) );
|
assert( !DC_EVENT_RETURNS_STRING(400) );
|
||||||
|
|
||||||
|
assert( dc_utf8_strlen("c")==1 && strlen("c")==1 );
|
||||||
|
assert( dc_utf8_strlen("ä")==1 && strlen("ä")==2 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* test dc_array_t
|
/* test dc_array_t
|
||||||
|
|
|
@ -420,9 +420,12 @@ error:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if 0 /* not needed at the moment */
|
size_t dc_utf8_strlen(const char* s)
|
||||||
static size_t dc_utf8_strlen(const char* s)
|
|
||||||
{
|
{
|
||||||
|
if (s==NULL) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
size_t j = 0;
|
size_t j = 0;
|
||||||
while (s[i]) {
|
while (s[i]) {
|
||||||
|
@ -432,11 +435,14 @@ static size_t dc_utf8_strlen(const char* s)
|
||||||
}
|
}
|
||||||
return j;
|
return j;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
static size_t dc_utf8_strnlen(const char* s, size_t n)
|
static size_t dc_utf8_strnlen(const char* s, size_t n)
|
||||||
{
|
{
|
||||||
|
if (s==NULL) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
size_t j = 0;
|
size_t j = 0;
|
||||||
while (i < n) {
|
while (i < n) {
|
||||||
|
|
|
@ -41,6 +41,7 @@ char* dc_binary_to_uc_hex (const uint8_t* buf, size_t bytes);
|
||||||
void dc_remove_cr_chars (char*); /* remove all \r characters from string */
|
void dc_remove_cr_chars (char*); /* remove all \r characters from string */
|
||||||
void dc_unify_lineends (char*);
|
void dc_unify_lineends (char*);
|
||||||
void dc_replace_bad_utf8_chars (char*); /* replace bad UTF-8 characters by sequences of `_` (to avoid problems in filenames, we do not use eg. `?`) the function is useful if strings are unexpectingly encoded eg. as ISO-8859-1 */
|
void dc_replace_bad_utf8_chars (char*); /* replace bad UTF-8 characters by sequences of `_` (to avoid problems in filenames, we do not use eg. `?`) the function is useful if strings are unexpectingly encoded eg. as ISO-8859-1 */
|
||||||
|
size_t dc_utf8_strlen (const char*);
|
||||||
void dc_truncate_str (char*, int approx_characters);
|
void dc_truncate_str (char*, int approx_characters);
|
||||||
void dc_truncate_n_unwrap_str (char*, int approx_characters, int do_unwrap);
|
void dc_truncate_n_unwrap_str (char*, int approx_characters, int do_unwrap);
|
||||||
carray* dc_split_into_lines (const char* buf_terminated); /* split string into lines*/
|
carray* dc_split_into_lines (const char* buf_terminated); /* split string into lines*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue