Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

Commit b915330f authored by rswindell's avatar rswindell

New functions: utf8_str_total_width() and utf8_str_count_width().

parent d3989071
......@@ -191,6 +191,40 @@ bool utf8_str_is_valid(const char* str)
return true;
}
// Return the total printed-width of UTF-8 string (str) accounting for zero/half/full-width codepoints
size_t utf8_str_total_width(const char* str)
{
size_t count = 0;
const char* end = str + strlen(str);
while (str < end) {
enum unicode_codepoint codepoint = 0;
int len = utf8_getc(str, end - str, &codepoint);
if (len < 1)
break;
count += unicode_width(codepoint);
str += len;
}
return count;
}
// Return the count of chars within the specified width range in UTF-8 string (str)
size_t utf8_str_count_width(const char* str, size_t min_width, size_t max_width)
{
size_t count = 0;
const char* end = str + strlen(str);
while (str < end) {
enum unicode_codepoint codepoint = 0;
int len = utf8_getc(str, end - str, &codepoint);
if (len < 1)
break;
size_t width = unicode_width(codepoint);
if(width >= min_width && width <= max_width)
count++;
str += len;
}
return count;
}
int cp437_to_utf8_str(const char* str, char* dest, size_t maxlen, unsigned char minval)
{
int retval = 0;
......
......@@ -49,6 +49,12 @@ extern "C" {
// Returns true if the string is valid UTF-8
bool utf8_str_is_valid(const char*);
// Returns the fixed printed-width of the UTF-8 string
size_t utf8_str_total_width(const char*);
// Return the count of chars within the specified width range in UTF-8 string (str)
size_t utf8_str_count_width(const char*, size_t min_width, size_t max_width);
// Normalizes (to ASCII) chars in UTF-8 string 'str', in-place, resulting in string <= original in length
char* utf8_normalize_str(char* str);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment