From 6be17ac2635614c6a63c9266df324f725e07087c Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Sat, 27 Jul 2013 18:21:50 +0200 Subject: [PATCH] api: add new function strlen_screen --- ChangeLog | 3 +- doc/en/weechat_plugin_api.en.txt | 42 +++++++++++++++++++++++ doc/fr/weechat_plugin_api.fr.txt | 43 +++++++++++++++++++++++ doc/it/weechat_plugin_api.it.txt | 45 +++++++++++++++++++++++++ src/plugins/guile/weechat-guile-api.c | 15 +++++++++ src/plugins/lua/weechat-lua-api.c | 18 ++++++++++ src/plugins/perl/weechat-perl-api.c | 15 +++++++++ src/plugins/plugin.c | 1 + src/plugins/python/weechat-python-api.c | 17 ++++++++++ src/plugins/ruby/weechat-ruby-api.c | 20 +++++++++++ src/plugins/tcl/weechat-tcl-api.c | 20 +++++++++++ src/plugins/weechat-plugin.h | 5 ++- 12 files changed, 242 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5e2468e8d..192f409f4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,7 @@ WeeChat ChangeLog ================= Sébastien Helleu -v0.4.2-dev, 2013-07-24 +v0.4.2-dev, 2013-07-27 This document lists all changes for each version. @@ -45,6 +45,7 @@ Version 0.4.2 (under dev!) "layout_window" * core: fix line alignment when option weechat.look.buffer_time_format is set to empty string +* api: add new function strlen_screen * aspell: rename option aspell.look.color to aspell.color.misspelled, add option aspell.color.suggestions * aspell: add support of enchant library (patch #6858) diff --git a/doc/en/weechat_plugin_api.en.txt b/doc/en/weechat_plugin_api.en.txt index d25e38c96..d1a5aef8c 100644 --- a/doc/en/weechat_plugin_api.en.txt +++ b/doc/en/weechat_plugin_api.en.txt @@ -790,6 +790,48 @@ char *pos = weechat_strcasestr ("aBcDeF", "de"); /* result: pointer to "DeF" */ [NOTE] This function is not available in scripting API. +weechat_strlen_screen +^^^^^^^^^^^^^^^^^^^^^ + +_New in version 0.4.2._ + +Return number of chars needed on screen to display UTF-8 string. +Non-printable chars have a width of 1 (this is the difference with the function +<<_weechat_utf8_strlen_screen,weechat_utf8_strlen_screen>>). + +Prototype: + +[source,C] +---------------------------------------- +int weechat_strlen_screen (const char *string); +---------------------------------------- + +Arguments: + +* 'string': string + +Return value: + +* number of chars needed on screen to display UTF-8 string + +C example: + +[source,C] +---------------------------------------- +int length_on_screen = weechat_strlen_screen ("é"); /* == 1 */ +---------------------------------------- + +Script (Python): + +[source,python] +---------------------------------------- +# prototype +length = weechat.strlen_screen(string) + +# example +length = weechat.strlen_screen("é") # 1 +---------------------------------------- + weechat_string_match ^^^^^^^^^^^^^^^^^^^^ diff --git a/doc/fr/weechat_plugin_api.fr.txt b/doc/fr/weechat_plugin_api.fr.txt index 70f5d328a..9ddb8226e 100644 --- a/doc/fr/weechat_plugin_api.fr.txt +++ b/doc/fr/weechat_plugin_api.fr.txt @@ -798,6 +798,49 @@ char *pos = weechat_strcasestr ("aBcDeF", "de"); /* résultat : pointeur vers "D [NOTE] Cette fonction n'est pas disponible dans l'API script. +weechat_strlen_screen +^^^^^^^^^^^^^^^^^^^^^ + +_Nouveau dans la version 0.4.2._ + +Retourne le nombre de caractères nécessaires pour afficher la chaîne UTF-8 +sur l'écran. +Les caractères non affichables ont une longueur de 1 (c'est la différence avec +la fonction <<_weechat_utf8_strlen_screen,weechat_utf8_strlen_screen>>). + +Prototype : + +[source,C] +---------------------------------------- +int weechat_strlen_screen (const char *string); +---------------------------------------- + +Paramètres : + +* 'string' : chaîne + +Valeur de retour : + +* nombre de caractères nécessaires pour afficher la chaîne UTF-8 sur l'écran + +Exemple en C : + +[source,C] +---------------------------------------- +int length_on_screen = weechat_strlen_screen ("é"); /* == 1 */ +---------------------------------------- + +Script (Python): + +[source,python] +---------------------------------------- +# prototype +length = weechat.strlen_screen(string) + +# exemple +length = weechat.strlen_screen("é") # 1 +---------------------------------------- + weechat_string_match ^^^^^^^^^^^^^^^^^^^^ diff --git a/doc/it/weechat_plugin_api.it.txt b/doc/it/weechat_plugin_api.it.txt index cf5bd9fb2..496d4e35a 100644 --- a/doc/it/weechat_plugin_api.it.txt +++ b/doc/it/weechat_plugin_api.it.txt @@ -804,6 +804,51 @@ char *pos = weechat_strcasestr ("aBcDeF", "de"); /* risultato: puntatore a "DeF" [NOTE] Questa funzione non è disponibile nelle API per lo scripting. +weechat_strlen_screen +^^^^^^^^^^^^^^^^^^^^^ + +_Novità nella versione 0.4.2._ + +Restituisce il numero di caratteri necessari per visualizzare la stringa +UTF-8 su schermo. +// TRANSLATION MISSING +Non-printable chars have a width of 1 (this is the difference with the function +<<_weechat_utf8_strlen_screen,weechat_utf8_strlen_screen>>). + +Prototipo: + +[source,C] +---------------------------------------- +int weechat_strlen_screen (const char *string); +---------------------------------------- + +Argomenti: + +* 'string': stringa + +Valore restituito: + +* numero di caratteri necessari per visualizzare la stringa UTF-8 +su schermo + +Esempio in C: + +[source,C] +---------------------------------------- +int length_on_screen = weechat_strlen_screen ("é"); /* == 1 */ +---------------------------------------- + +Script (Python): + +[source,python] +---------------------------------------- +# prototipo +length = weechat.strlen_screen(string) + +# esempio +length = weechat.strlen_screen("é") # 1 +---------------------------------------- + weechat_string_match ^^^^^^^^^^^^^^^^^^^^ diff --git a/src/plugins/guile/weechat-guile-api.c b/src/plugins/guile/weechat-guile-api.c index 8f6e99873..5142eb862 100644 --- a/src/plugins/guile/weechat-guile-api.c +++ b/src/plugins/guile/weechat-guile-api.c @@ -317,6 +317,20 @@ weechat_guile_api_ngettext (SCM single, SCM plural, SCM count) API_RETURN_STRING(result); } +SCM +weechat_guile_api_strlen_screen (SCM string) +{ + int value; + + API_FUNC(1, "strlen_screen", API_RETURN_INT(0)); + if (!scm_is_string (string)) + API_WRONG_ARGS(API_RETURN_INT(0)); + + value = weechat_strlen_screen (API_SCM_TO_STRING(string)); + + API_RETURN_INT(value); +} + SCM weechat_guile_api_string_match (SCM string, SCM mask, SCM case_sensitive) { @@ -4586,6 +4600,7 @@ weechat_guile_api_module_init (void *data) API_DEF_FUNC(iconv_from_internal, 2); API_DEF_FUNC(gettext, 1); API_DEF_FUNC(ngettext, 3); + API_DEF_FUNC(strlen_screen, 1); API_DEF_FUNC(string_match, 3); API_DEF_FUNC(string_has_highlight, 2); API_DEF_FUNC(string_has_highlight_regex, 2); diff --git a/src/plugins/lua/weechat-lua-api.c b/src/plugins/lua/weechat-lua-api.c index ba9b089bb..e60f2d3b3 100644 --- a/src/plugins/lua/weechat-lua-api.c +++ b/src/plugins/lua/weechat-lua-api.c @@ -276,6 +276,23 @@ weechat_lua_api_ngettext (lua_State *L) API_RETURN_STRING(result); } +static int +weechat_lua_api_strlen_screen (lua_State *L) +{ + const char *string; + int value; + + API_FUNC(1, "strlen_screen", API_RETURN_INT(0)); + if (lua_gettop (L) < 1) + API_WRONG_ARGS(API_RETURN_INT(0)); + + string = lua_tostring (L, -1); + + value = weechat_strlen_screen (string); + + API_RETURN_INT(value); +} + static int weechat_lua_api_string_match (lua_State *L) { @@ -5070,6 +5087,7 @@ const struct luaL_Reg weechat_lua_api_funcs[] = { API_DEF_FUNC(iconv_from_internal), API_DEF_FUNC(gettext), API_DEF_FUNC(ngettext), + API_DEF_FUNC(strlen_screen), API_DEF_FUNC(string_match), API_DEF_FUNC(string_has_highlight), API_DEF_FUNC(string_has_highlight_regex), diff --git a/src/plugins/perl/weechat-perl-api.c b/src/plugins/perl/weechat-perl-api.c index 11d3f1c8c..19cb70ec8 100644 --- a/src/plugins/perl/weechat-perl-api.c +++ b/src/plugins/perl/weechat-perl-api.c @@ -278,6 +278,20 @@ XS (XS_weechat_api_ngettext) API_RETURN_STRING(result); } +XS (XS_weechat_api_strlen_screen) +{ + int value; + dXSARGS; + + API_FUNC(1, "strlen_screen", API_RETURN_INT(0)); + if (items < 1) + API_WRONG_ARGS(API_RETURN_INT(0)); + + value = weechat_strlen_screen (SvPV_nolen (ST (0))); /* string */ + + API_RETURN_INT(value); +} + XS (XS_weechat_api_string_match) { int value; @@ -4823,6 +4837,7 @@ weechat_perl_api_init (pTHX) API_DEF_FUNC(iconv_from_internal); API_DEF_FUNC(gettext); API_DEF_FUNC(ngettext); + API_DEF_FUNC(strlen_screen); API_DEF_FUNC(string_match); API_DEF_FUNC(string_has_highlight); API_DEF_FUNC(string_has_highlight_regex); diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c index 3ad99bd68..4051689fa 100644 --- a/src/plugins/plugin.c +++ b/src/plugins/plugin.c @@ -510,6 +510,7 @@ plugin_load (const char *filename, int argc, char **argv) new_plugin->strncasecmp_range = &string_strncasecmp_range; new_plugin->strcmp_ignore_chars = &string_strcmp_ignore_chars; new_plugin->strcasestr = &string_strcasestr; + new_plugin->strlen_screen = &gui_chat_strlen_screen; new_plugin->string_match = &string_match; new_plugin->string_replace = &string_replace; new_plugin->string_expand_home = &string_expand_home; diff --git a/src/plugins/python/weechat-python-api.c b/src/plugins/python/weechat-python-api.c index e2d776d69..6e2d39722 100644 --- a/src/plugins/python/weechat-python-api.c +++ b/src/plugins/python/weechat-python-api.c @@ -260,6 +260,22 @@ weechat_python_api_ngettext (PyObject *self, PyObject *args) API_RETURN_STRING(result); } +static PyObject * +weechat_python_api_strlen_screen (PyObject *self, PyObject *args) +{ + char *string; + int value; + + API_FUNC(1, "strlen_screen", API_RETURN_INT(0)); + string = NULL; + if (!PyArg_ParseTuple (args, "s", &string)) + API_WRONG_ARGS(API_RETURN_INT(0)); + + value = weechat_strlen_screen (string); + + API_RETURN_INT(value); +} + static PyObject * weechat_python_api_string_match (PyObject *self, PyObject *args) { @@ -4975,6 +4991,7 @@ PyMethodDef weechat_python_funcs[] = API_DEF_FUNC(iconv_from_internal), API_DEF_FUNC(gettext), API_DEF_FUNC(ngettext), + API_DEF_FUNC(strlen_screen), API_DEF_FUNC(string_match), API_DEF_FUNC(string_has_highlight), API_DEF_FUNC(string_has_highlight_regex), diff --git a/src/plugins/ruby/weechat-ruby-api.c b/src/plugins/ruby/weechat-ruby-api.c index 9888e5a93..6246ee76f 100644 --- a/src/plugins/ruby/weechat-ruby-api.c +++ b/src/plugins/ruby/weechat-ruby-api.c @@ -295,6 +295,25 @@ weechat_ruby_api_ngettext (VALUE class, VALUE single, VALUE plural, API_RETURN_STRING(result); } +static VALUE +weechat_ruby_api_strlen_screen (VALUE class, VALUE string) +{ + char *c_string; + int value; + + API_FUNC(1, "strlen_screen", API_RETURN_INT(0)); + if (NIL_P (string)) + API_WRONG_ARGS(API_RETURN_INT(0)); + + Check_Type (string, T_STRING); + + c_string = StringValuePtr (string); + + value = weechat_strlen_screen (c_string); + + API_RETURN_INT(value); +} + static VALUE weechat_ruby_api_string_match (VALUE class, VALUE string, VALUE mask, VALUE case_sensitive) @@ -5918,6 +5937,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat) API_DEF_FUNC(iconv_from_internal, 2); API_DEF_FUNC(gettext, 1); API_DEF_FUNC(ngettext, 3); + API_DEF_FUNC(strlen_screen, 1); API_DEF_FUNC(string_match, 3); API_DEF_FUNC(string_has_highlight, 2); API_DEF_FUNC(string_has_highlight_regex, 2); diff --git a/src/plugins/tcl/weechat-tcl-api.c b/src/plugins/tcl/weechat-tcl-api.c index 451d9d5e9..24a8ce4a3 100644 --- a/src/plugins/tcl/weechat-tcl-api.c +++ b/src/plugins/tcl/weechat-tcl-api.c @@ -407,6 +407,25 @@ weechat_tcl_api_ngettext (ClientData clientData, Tcl_Interp *interp, API_RETURN_STRING(result); } +static int +weechat_tcl_api_strlen_screen (ClientData clientData, Tcl_Interp *interp, + int objc, Tcl_Obj *CONST objv[]) +{ + Tcl_Obj *objp; + char *string; + int result, i; + + API_FUNC(1, "strlen_screen", API_RETURN_INT(0)); + if (objc < 2) + API_WRONG_ARGS(API_RETURN_INT(0)); + + string = Tcl_GetStringFromObj (objv[1], &i); + + result = weechat_strlen_screen (string); + + API_RETURN_INT(result); +} + static int weechat_tcl_api_string_match (ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) @@ -5664,6 +5683,7 @@ void weechat_tcl_api_init (Tcl_Interp *interp) API_DEF_FUNC(iconv_from_internal); API_DEF_FUNC(gettext); API_DEF_FUNC(ngettext); + API_DEF_FUNC(strlen_screen); API_DEF_FUNC(string_match); API_DEF_FUNC(string_has_highlight); API_DEF_FUNC(string_has_highlight_regex); diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h index fb78fb40a..82873d171 100644 --- a/src/plugins/weechat-plugin.h +++ b/src/plugins/weechat-plugin.h @@ -52,7 +52,7 @@ struct timeval; * please change the date with current one; for a second change at same * date, increment the 01, otherwise please keep 01. */ -#define WEECHAT_PLUGIN_API_VERSION "20130421-01" +#define WEECHAT_PLUGIN_API_VERSION "20130727-01" /* macros for defining plugin infos */ #define WEECHAT_PLUGIN_NAME(__name) \ @@ -225,6 +225,7 @@ struct t_weechat_plugin int (*strcmp_ignore_chars) (const char *string1, const char *string2, const char *chars_ignored, int case_sensitive); char *(*strcasestr) (const char *string, const char *search); + int (*strlen_screen) (const char *string); int (*string_match) (const char *string, const char *mask, int case_sensitive); char *(*string_replace) (const char *string, const char *search, @@ -969,6 +970,8 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin); __case_sensitive) #define weechat_strcasestr(__string, __search) \ weechat_plugin->strcasestr(__string, __search) +#define weechat_strlen_screen(__string) \ + weechat_plugin->strlen_screen(__string) #define weechat_string_match(__string, __mask, __case_sensitive) \ weechat_plugin->string_match(__string, __mask, __case_sensitive) #define weechat_string_replace(__string, __search, __replace) \