2 * Copyright (c) 2016 Joshua Rubin <joshua@rubixconsulting.com>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
13 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
14 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #include <sys/types.h>
24 utf8proc_wcwidth(wchar_t wc
)
28 cat
= utf8proc_category(wc
);
29 if (cat
== UTF8PROC_CATEGORY_CO
) {
31 * The private use category is where powerline and similar
32 * codepoints are stored, they have "ambiguous" width - use 1.
36 return (utf8proc_charwidth(wc
));
40 utf8proc_mbtowc(wchar_t *pwc
, const char *s
, size_t n
)
42 utf8proc_ssize_t slen
;
48 * *pwc == -1 indicates invalid codepoint
49 * slen < 0 indicates an error
51 slen
= utf8proc_iterate(s
, n
, pwc
);
52 if (*pwc
== (wchar_t)-1 || slen
< 0)
58 utf8proc_wctomb(char *s
, wchar_t wc
)
63 if (!utf8proc_codepoint_valid(wc
))
65 return (utf8proc_encode_char(wc
, s
));