1 #ifndef CSR_UNICODE_H__
2 #define CSR_UNICODE_H__
3 /*****************************************************************************
5 (c) Cambridge Silicon Radio Limited 2010
6 All rights reserved and confidential information of CSR
8 Refer to LICENSE.txt included with this source for details
11 *****************************************************************************/
13 #include "csr_types.h"
19 u16 *CsrUint32ToUtf16String(u32 number);
21 u32 CsrUtf16StringToUint32(const u16 *unicodeString);
22 u32 CsrUtf16StrLen(const u16 *unicodeString);
24 u8 *CsrUtf16String2Utf8(const u16 *source);
26 u16 *CsrUtf82Utf16String(const u8 *utf8String);
28 u16 *CsrUtf16StrCpy(u16 *target, const u16 *source);
29 u16 *CsrUtf16StringDuplicate(const u16 *source);
31 u16 CsrUtf16StrICmp(const u16 *string1, const u16 *string2);
32 u16 CsrUtf16StrNICmp(const u16 *string1, const u16 *string2, u32 count);
34 u16 *CsrUtf16MemCpy(u16 *dest, const u16 *src, u32 count);
35 u16 *CsrUtf16ConcatenateTexts(const u16 *inputText1, const u16 *inputText2,
36 const u16 *inputText3, const u16 *inputText4);
38 u16 *CsrUtf16String2XML(u16 *str);
39 u16 *CsrXML2Utf16String(u16 *str);
41 s32 CsrUtf8StrCmp(const u8 *string1, const u8 *string2);
42 s32 CsrUtf8StrNCmp(const u8 *string1, const u8 *string2, size_t count);
43 u32 CsrUtf8StringLengthInBytes(const u8 *string);
45 /*******************************************************************************
51 In-place truncate a string on a UTF-8 character boundary by writing a
52 null character somewhere in the range target[count - 3]:target[count].
54 Please note that memory passed must be at least of length count + 1, to
55 ensure space for a full length string that is terminated at
56 target[count], in the event that target[count - 1] is the final byte of
60 target - Target string to truncate.
61 count - The desired length, in bytes, of the resulting string. Depending
62 on the contents, the resulting string length will be between
68 *******************************************************************************/
69 u8 *CsrUtf8StrTruncate(u8 *target, size_t count);
71 /*******************************************************************************
77 Copies the null terminated UTF-8 string pointed at by source into the
78 memory pointed at by target, including the terminating null character.
80 To avoid overflows, the size of the memory pointed at by target shall be
81 long enough to contain the same UTF-8 string as source (including the
82 terminating null character), and should not overlap in memory with
86 target - Pointer to the target memory where the content is to be copied.
87 source - UTF-8 string to be copied.
92 *******************************************************************************/
93 u8 *CsrUtf8StrCpy(u8 *target, const u8 *source);
95 /*******************************************************************************
101 Copies the first count bytes of source to target. If the end of the
102 source UTF-8 string (which is signaled by a null-character) is found
103 before count bytes have been copied, target is padded with null
104 characters until a total of count bytes have been written to it.
106 No null-character is implicitly appended to the end of target, so target
107 will only be null-terminated if the length of the UTF-8 string in source
111 target - Pointer to the target memory where the content is to be copied.
112 source - UTF-8 string to be copied.
113 count - Maximum number of bytes to be written to target.
118 *******************************************************************************/
119 u8 *CsrUtf8StrNCpy(u8 *target, const u8 *source, size_t count);
121 /*******************************************************************************
127 Equivalent to CsrUtf8StrNCpy, but if the length of source is equal to or
128 greater than count the target string is truncated on a UTF-8 character
129 boundary by writing a null character somewhere in the range
130 target[count - 4]:target[count - 1], leaving the target string
131 unconditionally null terminated in all cases.
133 Please note that if the length of source is shorter than count, no
134 truncation will be applied, and the target string will be a one to one
138 target - Pointer to the target memory where the content is to be copied.
139 source - UTF-8 string to be copied.
140 count - Maximum number of bytes to be written to target.
145 *******************************************************************************/
146 u8 *CsrUtf8StrNCpyZero(u8 *target, const u8 *source, size_t count);
148 /*******************************************************************************
154 This function will allocate memory and copy the source string into the
155 allocated memory, which is then returned as a duplicate of the original
156 string. The memory returned must be freed by calling CsrPmemFree when
157 the duplicate is no longer needed.
160 source - UTF-8 string to be duplicated.
163 Returns a duplicate of source.
165 *******************************************************************************/
166 u8 *CsrUtf8StrDup(const u8 *source);
168 u8 *CsrUtf8StringConcatenateTexts(const u8 *inputText1, const u8 *inputText2, const u8 *inputText3, const u8 *inputText4);
175 typedef u8 CsrUcs2String;
177 size_t CsrUcs2ByteStrLen(const CsrUcs2String *ucs2String);
178 size_t CsrConverterUcs2ByteStrLen(const CsrUcs2String *str);
180 u8 *CsrUcs2ByteString2Utf8(const CsrUcs2String *ucs2String);
181 CsrUcs2String *CsrUtf82Ucs2ByteString(const u8 *utf8String);
183 u8 *CsrUtf16String2Ucs2ByteString(const u16 *source);
184 u16 *CsrUcs2ByteString2Utf16String(const u8 *source);