701aae8651ec0f80e4da1aabb678b5ba449a1799
[linux-2.6-block.git] / drivers / staging / csr / csr_unicode.h
1 #ifndef CSR_UNICODE_H__
2 #define CSR_UNICODE_H__
3 /*****************************************************************************
4
5             (c) Cambridge Silicon Radio Limited 2010
6             All rights reserved and confidential information of CSR
7
8             Refer to LICENSE.txt included with this source for details
9             on the license terms.
10
11 *****************************************************************************/
12
13 #include "csr_types.h"
14
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18
19 u16 *CsrUint32ToUtf16String(u32 number);
20
21 u32 CsrUtf16StringToUint32(const u16 *unicodeString);
22 u32 CsrUtf16StrLen(const u16 *unicodeString);
23
24 u8 *CsrUtf16String2Utf8(const u16 *source);
25
26 u16 *CsrUtf82Utf16String(const u8 *utf8String);
27
28 u16 *CsrUtf16StrCpy(u16 *target, const u16 *source);
29 u16 *CsrUtf16StringDuplicate(const u16 *source);
30
31 u16 CsrUtf16StrICmp(const u16 *string1, const u16 *string2);
32 u16 CsrUtf16StrNICmp(const u16 *string1, const u16 *string2, u32 count);
33
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);
37
38 u16 *CsrUtf16String2XML(u16 *str);
39 u16 *CsrXML2Utf16String(u16 *str);
40
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);
44
45 /*******************************************************************************
46
47     NAME
48         CsrUtf8StrTruncate
49
50     DESCRIPTION
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].
53
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
57         a UTF-8 character.
58
59     PARAMETERS
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
63                 count - 3 and count.
64
65     RETURNS
66         Returns target
67
68 *******************************************************************************/
69 u8 *CsrUtf8StrTruncate(u8 *target, size_t count);
70
71 /*******************************************************************************
72
73     NAME
74         CsrUtf8StrCpy
75
76     DESCRIPTION
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.
79
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
83         source.
84
85     PARAMETERS
86         target - Pointer to the target memory where the content is to be copied.
87         source - UTF-8 string to be copied.
88
89     RETURNS
90         Returns target
91
92 *******************************************************************************/
93 u8 *CsrUtf8StrCpy(u8 *target, const u8 *source);
94
95 /*******************************************************************************
96
97     NAME
98         CsrUtf8StrNCpy
99
100     DESCRIPTION
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.
105
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
108         is less than count.
109
110     PARAMETERS
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.
114
115     RETURNS
116         Returns target
117
118 *******************************************************************************/
119 u8 *CsrUtf8StrNCpy(u8 *target, const u8 *source, size_t count);
120
121 /*******************************************************************************
122
123     NAME
124         CsrUtf8StrNCpyZero
125
126     DESCRIPTION
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.
132
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
135         copy of source.
136
137     PARAMETERS
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.
141
142     RETURNS
143         Returns target
144
145 *******************************************************************************/
146 u8 *CsrUtf8StrNCpyZero(u8 *target, const u8 *source, size_t count);
147
148 /*******************************************************************************
149
150     NAME
151         CsrUtf8StrDup
152
153     DESCRIPTION
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.
158
159     PARAMETERS
160         source - UTF-8 string to be duplicated.
161
162     RETURNS
163         Returns a duplicate of source.
164
165 *******************************************************************************/
166 u8 *CsrUtf8StrDup(const u8 *source);
167
168 u8 *CsrUtf8StringConcatenateTexts(const u8 *inputText1, const u8 *inputText2, const u8 *inputText3, const u8 *inputText4);
169
170 /*
171  * UCS2
172  *
173  * D-13157
174  */
175 typedef u8 CsrUcs2String;
176
177 size_t CsrUcs2ByteStrLen(const CsrUcs2String *ucs2String);
178 size_t CsrConverterUcs2ByteStrLen(const CsrUcs2String *str);
179
180 u8 *CsrUcs2ByteString2Utf8(const CsrUcs2String *ucs2String);
181 CsrUcs2String *CsrUtf82Ucs2ByteString(const u8 *utf8String);
182
183 u8 *CsrUtf16String2Ucs2ByteString(const u16 *source);
184 u16 *CsrUcs2ByteString2Utf16String(const u8 *source);
185
186 #ifdef __cplusplus
187 }
188 #endif
189
190 #endif