1 #include <linux/ucs2_string.h>
2 #include <linux/module.h>
4 /* Return the number of unicode characters in data */
6 ucs2_strnlen(const ucs2_char_t
*s
, size_t maxlength
)
8 unsigned long length
= 0;
10 while (*s
++ != 0 && length
< maxlength
)
14 EXPORT_SYMBOL(ucs2_strnlen
);
17 ucs2_strlen(const ucs2_char_t
*s
)
19 return ucs2_strnlen(s
, ~0UL);
21 EXPORT_SYMBOL(ucs2_strlen
);
24 * Return the number of bytes is the length of this string
25 * Note: this is NOT the same as the number of unicode characters
28 ucs2_strsize(const ucs2_char_t
*data
, unsigned long maxlength
)
30 return ucs2_strnlen(data
, maxlength
/sizeof(ucs2_char_t
)) * sizeof(ucs2_char_t
);
32 EXPORT_SYMBOL(ucs2_strsize
);
35 ucs2_strncmp(const ucs2_char_t
*a
, const ucs2_char_t
*b
, size_t len
)
44 if (*a
== 0) /* implies *b == 0 */
51 EXPORT_SYMBOL(ucs2_strncmp
);
54 ucs2_utf8size(const ucs2_char_t
*src
)
59 for (i
= 0; src
[i
]; i
++) {
72 EXPORT_SYMBOL(ucs2_utf8size
);
75 * copy at most maxlength bytes of whole utf8 characters to dest from the
78 * The return value is the number of characters copied, not including the
79 * final NUL character.
82 ucs2_as_utf8(u8
*dest
, const ucs2_char_t
*src
, unsigned long maxlength
)
86 unsigned long limit
= ucs2_strnlen(src
, maxlength
);
88 for (i
= 0; maxlength
&& i
< limit
; i
++) {
95 dest
[j
++] = 0xe0 | (c
& 0xf000) >> 12;
96 dest
[j
++] = 0x80 | (c
& 0x0fc0) >> 6;
97 dest
[j
++] = 0x80 | (c
& 0x003f);
98 } else if (c
>= 0x80) {
102 dest
[j
++] = 0xc0 | (c
& 0x7c0) >> 6;
103 dest
[j
++] = 0x80 | (c
& 0x03f);
106 dest
[j
++] = c
& 0x7f;
113 EXPORT_SYMBOL(ucs2_as_utf8
);