1
0
mirror of https://github.com/irssi/irssi.git synced 2025-02-02 15:08:01 -05:00

Leverage string_policy().

This commit is contained in:
Xavier G 2016-05-13 02:27:19 +02:00
parent 2c8648a9c8
commit 21c07c0060
4 changed files with 9 additions and 8 deletions

View File

@ -28,9 +28,9 @@
/* Provide is_utf8(): */ /* Provide is_utf8(): */
#include "recode.h" #include "recode.h"
int string_advance(char const **str, gboolean utf8) int string_advance(char const **str, int policy)
{ {
if (utf8) { if (policy == TREAT_STRING_AS_UTF8) {
gunichar c; gunichar c;
c = g_utf8_get_char(*str); c = g_utf8_get_char(*str);
@ -38,6 +38,7 @@ int string_advance(char const **str, gboolean utf8)
return unichar_isprint(c) ? mk_wcwidth(c) : 1; return unichar_isprint(c) ? mk_wcwidth(c) : 1;
} else { } else {
/* Assume TREAT_STRING_AS_BYTES: */
*str += 1; *str += 1;
return 1; return 1;

View File

@ -17,7 +17,7 @@ int mk_wcwidth(unichar c);
/* Advance the str pointer one character further; return the number of columns /* Advance the str pointer one character further; return the number of columns
* occupied by the skipped character. * occupied by the skipped character.
*/ */
int string_advance(char const **str, gboolean utf8); int string_advance(char const **str, int policy);
/* TREAT_STRING_AS_BYTES means strings are to be treated using strncpy, /* TREAT_STRING_AS_BYTES means strings are to be treated using strncpy,
* strnlen, etc. * strnlen, etc.

View File

@ -425,12 +425,12 @@ int format_get_length(const char *str)
{ {
GString *tmp; GString *tmp;
int len; int len;
gboolean utf8; int utf8;
int adv = 0; int adv = 0;
g_return_val_if_fail(str != NULL, 0); g_return_val_if_fail(str != NULL, 0);
utf8 = is_utf8() && g_utf8_validate(str, -1, NULL); utf8 = string_policy(str);
tmp = g_string_new(NULL); tmp = g_string_new(NULL);
len = 0; len = 0;
@ -464,12 +464,12 @@ int format_real_length(const char *str, int len)
GString *tmp; GString *tmp;
const char *start; const char *start;
const char *oldstr; const char *oldstr;
gboolean utf8; int utf8;
int adv = 0; int adv = 0;
g_return_val_if_fail(str != NULL, 0); g_return_val_if_fail(str != NULL, 0);
g_return_val_if_fail(len >= 0, 0); g_return_val_if_fail(len >= 0, 0);
utf8 = is_utf8() && g_utf8_validate(str, -1, NULL); utf8 = string_policy(str);
start = str; start = str;
tmp = g_string_new(NULL); tmp = g_string_new(NULL);

View File

@ -367,7 +367,7 @@ static int scrlen_str(const char *str)
g_return_val_if_fail(str != NULL, 0); g_return_val_if_fail(str != NULL, 0);
str = stripped = strip_codes(str); str = stripped = strip_codes(str);
if (is_utf8() && g_utf8_validate(str, -1, NULL)) { if (string_policy(str) == TREAT_STRING_AS_UTF8) {
while (*str != '\0') { while (*str != '\0') {
gunichar c; gunichar c;