diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2008-11-15 18:28:36 +0100 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2008-11-15 18:28:36 +0100 |
commit | fdf827d31f655f693e4273a23538c5d605f71931 (patch) | |
tree | 19e237f7b2b8b61dd62353ee8cfed665782e5d23 /src/core/wee-utf8.c | |
parent | da748fc653a4d35cc24a7b9dd1c25a4a3b07f4ee (diff) | |
download | weechat-fdf827d31f655f693e4273a23538c5d605f71931.zip |
Add function utf8_strndup to C plugin API
Diffstat (limited to 'src/core/wee-utf8.c')
-rw-r--r-- | src/core/wee-utf8.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/core/wee-utf8.c b/src/core/wee-utf8.c index 9e134b69a..65e73d92f 100644 --- a/src/core/wee-utf8.c +++ b/src/core/wee-utf8.c @@ -452,3 +452,26 @@ utf8_pos (const char *string, int real_pos) } return count; } + +/* + * utf8_strndup: return duplicate string, with max N UTF-8 chars + */ + +char * +utf8_strndup (const char *string, int max_chars) +{ + const char *end; + char *result; + + if (!string || (max_chars < 0)) + return NULL; + + if (max_chars == 0) + return strdup (""); + + end = utf8_add_offset (string, max_chars); + if (!end || (end == string)) + return strdup (string); + + return string_strndup (string, end - string); +} |