1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-09 19:23:13 +02:00

Add function utf8_strndup to C plugin API

This commit is contained in:
Sebastien Helleu
2008-11-15 18:28:36 +01:00
parent da748fc653
commit fdf827d31f
5 changed files with 62 additions and 0 deletions
+36
View File
@@ -1545,6 +1545,42 @@ char *weechat_utf8_pos (const char *string, int real_pos);
</para>
</section>
<section id="secPluginCApi_weechat_utf8_strndup">
<title>weechat_utf8_strndup</title>
<para>
Prototype:
<programlisting>
char *weechat_utf8_strndup (const char *string, int max_chars);
</programlisting>
</para>
<para>
Return duplicate string, with max N chars.
</para>
<para>
Arguments:
<itemizedlist>
<listitem>
<para>
<option>string</option>: string
</para>
</listitem>
<listitem>
<para>
<option>max_chars</option>: max chars
</para>
</listitem>
</itemizedlist>
</para>
<para>
Return value: duplicated string, NULL if error.
</para>
<para>
Example:
<screen>char *string = weechat_utf8_strndup ("chêne", 3); /* returns "chê" */</screen>
</para>
</section>
</section>
<!-- ===========================[ directories ]========================== -->
+23
View File
@@ -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);
}
+1
View File
@@ -47,5 +47,6 @@ extern int utf8_char_size_screen (const char *string);
extern char *utf8_add_offset (const char *string, int offset);
extern int utf8_real_pos (const char *string, int pos);
extern int utf8_pos (const char *string, int real_pos);
extern char *utf8_strndup (const char *string, int max_chars);
#endif /* wee-utf8.h */
+1
View File
@@ -360,6 +360,7 @@ plugin_load (const char *filename)
new_plugin->utf8_add_offset = &utf8_add_offset;
new_plugin->utf8_real_pos = &utf8_real_pos;
new_plugin->utf8_pos = &utf8_pos;
new_plugin->utf8_strndup = &utf8_strndup;
new_plugin->mkdir_home = &util_mkdir_home;
new_plugin->mkdir = &util_mkdir;
+1
View File
@@ -171,6 +171,7 @@ struct t_weechat_plugin
char *(*utf8_add_offset) (const char *string, int offset);
int (*utf8_real_pos) (const char *string, int pos);
int (*utf8_pos) (const char *string, int real_pos);
char *(*utf8_strndup) (const char *string, int max_chars);
/* directories */
int (*mkdir_home) (const char *directory, int mode);