summaryrefslogtreecommitdiff
path: root/src/core/wee-utf8.c
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2008-11-15 18:28:36 +0100
committerSebastien Helleu <flashcode@flashtux.org>2008-11-15 18:28:36 +0100
commitfdf827d31f655f693e4273a23538c5d605f71931 (patch)
tree19e237f7b2b8b61dd62353ee8cfed665782e5d23 /src/core/wee-utf8.c
parentda748fc653a4d35cc24a7b9dd1c25a4a3b07f4ee (diff)
downloadweechat-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.c23
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);
+}