mirror of
https://github.com/irssi/irssi.git
synced 2024-12-04 14:46:39 -05:00
Introduce string_length() and string_width().
This commit is contained in:
parent
21c07c0060
commit
35b3ccc6a4
@ -55,3 +55,37 @@ int string_policy(const char *str)
|
|||||||
}
|
}
|
||||||
return TREAT_STRING_AS_BYTES;
|
return TREAT_STRING_AS_BYTES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int string_length(const char *str, int policy)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail(str != NULL, 0);
|
||||||
|
|
||||||
|
if (policy == -1) {
|
||||||
|
policy = string_policy(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (policy == TREAT_STRING_AS_UTF8) {
|
||||||
|
return g_utf8_strlen(str, -1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
/* Assume TREAT_STRING_AS_BYTES: */
|
||||||
|
return strlen(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int string_width(const char *str, int policy)
|
||||||
|
{
|
||||||
|
int len;
|
||||||
|
|
||||||
|
g_return_val_if_fail(str != NULL, 0);
|
||||||
|
|
||||||
|
if (policy == -1) {
|
||||||
|
policy = string_policy(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
len = 0;
|
||||||
|
while (*str != '\0') {
|
||||||
|
len += string_advance(&str, policy);
|
||||||
|
}
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
@ -33,6 +33,15 @@ int string_advance(char const **str, int policy);
|
|||||||
*/
|
*/
|
||||||
int string_policy(const char *str);
|
int string_policy(const char *str);
|
||||||
|
|
||||||
|
/* Return the length of the str string according to the given policy; if policy
|
||||||
|
* is -1, this function will call string_policy().
|
||||||
|
*/
|
||||||
|
int string_length(const char *str, int policy);
|
||||||
|
/* Return the screen width of the str string according to the given policy; if
|
||||||
|
* policy is -1, this function will call string_policy().
|
||||||
|
*/
|
||||||
|
int string_width(const char *str, int policy);
|
||||||
|
|
||||||
#define unichar_isprint(c) (((c) & ~0x80) >= 32)
|
#define unichar_isprint(c) (((c) & ~0x80) >= 32)
|
||||||
#define is_utf8_leading(c) (((c) & 0xc0) != 0x80)
|
#define is_utf8_leading(c) (((c) & 0xc0) != 0x80)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user