1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - STD - include
3 File: string.h
4
5 Copyright 2005-2008 Nintendo. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Date:: 2008-09-26#$
14 $Rev: 8696 $
15 $Author: yasuda_kei $
16 *---------------------------------------------------------------------------*/
17
18 #ifndef NITRO_STD_STRING_H_
19 #define NITRO_STD_STRING_H_
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25 #include <nitro/misc.h>
26 #include <nitro/types.h>
27 #include <nitro/mi/memory.h>
28
29 //---- aliases
30 #define STD_StrCpy STD_CopyString
31 #define STD_StrLCpy STD_CopyLString
32 #define STD_StrChr STD_SearchChar
33 #define STD_StrRChr STD_SearchCharReverse
34 #define STD_StrStr STD_SearchString
35 #define STD_StrLen STD_GetStringLength
36 #define STD_StrNLen STD_GetStringNLength
37 #define STD_StrCat STD_ConcatenateString
38 #define STD_StrLCat STD_ConcatenateLString
39 #define STD_StrCmp STD_CompareString
40 #define STD_StrNCmp STD_CompareNString
41 #define STD_StrLCmp STD_CompareLString
42
43 #define STD_MemCpy STD_CopyMemory
44 #define STD_MemMove STD_MoveMemory
45 #define STD_MemSet STD_FillMemory
46
47 /*---------------------------------------------------------------------------*
48 Name: STD_CopyString
49
50 Description: same to strcpy
51
52 Arguments: destp: destination pointer
53 srcp: src pointer
54
55 Returns: pointer to destination
56 *---------------------------------------------------------------------------*/
57 extern char *STD_CopyString(char *destp, const char *srcp);
58
59 /*---------------------------------------------------------------------------*
60 Name: STD_CopyLStringZeroFill
61
62 Description: do not correspond with strlcpy
63
64 Arguments: destp: destination pointer
65 srcp: src pointer
66 n: copy size + 1
67
68 Returns: size of src
69 *---------------------------------------------------------------------------*/
70 extern int STD_CopyLStringZeroFill(char *destp, const char *srcp, int n);
71
72 /*---------------------------------------------------------------------------*
73 Name: STD_CopyLString
74
75 Description: same to strlcpy
76
77 Arguments: destp: destination pointer
78 srcp: src pointer
79 siz: copy size + 1
80
81 Returns: size of src
82 *---------------------------------------------------------------------------*/
83 extern int STD_CopyLString(char *destp, const char *srcp, int siz);
84
85 /*---------------------------------------------------------------------------*
86 Name: STD_SearchChar
87
88 Description: This is the same as strchr.
89
90 Arguments: srcp: src string
91 c: character to search from src pointer
92
93 Returns: pointer to destination
94 *---------------------------------------------------------------------------*/
95 extern char *STD_SearchChar(const char *srcp, int c);
96
97 /*---------------------------------------------------------------------------*
98 Name: STD_SearchCharReverse
99
100 Description: This is the same as strrchr.
101
102 Arguments: srcp: src string
103 c: character to search from src pointer
104
105 Returns: pointer to destination
106 *---------------------------------------------------------------------------*/
107 extern char *STD_SearchCharReverse(const char *srcp, int c);
108
109 /*---------------------------------------------------------------------------*
110 Name: STD_SearchString
111
112 Description: same to strstr
113
114 Arguments: srcp: src string
115 str: string to search from src pointer
116
117 Returns: pointer to destination
118 *---------------------------------------------------------------------------*/
119 extern char *STD_SearchString(const char *srcp, const char *str);
120
121 /*---------------------------------------------------------------------------*
122 Name: STD_GetStringLength
123
124 Description: Get string length. Same as strlen
125
126 Arguments: str: string
127
128 Returns: string length
129 *---------------------------------------------------------------------------*/
130 extern int STD_GetStringLength(const char *str);
131
132 /*---------------------------------------------------------------------------*
133 Name: STD_GetStringNLength
134
135 Description: Gets the length of a string, up to 'len'. This is the same as strnlen.
136
137 Arguments: str: string
138 len: max length
139
140 Returns: string length
141 *---------------------------------------------------------------------------*/
142 extern int STD_GetStringNLength(const char *str, int len);
143
144 /*---------------------------------------------------------------------------*
145 Name: STD_ConcatenateString
146
147 Description: Concatenate strings. Same as strcat
148
149 Arguments: str1: original string
150 str2: string to concatenate
151
152 Returns: concatenated string
153 *---------------------------------------------------------------------------*/
154 extern char *STD_ConcatenateString(char *str1, const char *str2);
155
156 /*---------------------------------------------------------------------------*
157 Name: STD_ConcatenateLString
158
159 Description: Concatenates strings. This is the same as strlcat.
160
161 Arguments: str1: original string
162 str2: string to concatenate
163 size: buffer size of str1
164
165 Returns: length of str1 + length of str2
166 *---------------------------------------------------------------------------*/
167 extern int STD_ConcatenateLString(char *str1, const char *str2, int size);
168
169 /*---------------------------------------------------------------------------*
170 Name: STD_CompareString
171
172 Description: Compare strings. Same as strcmp
173
174 Arguments: str1, str2: strings
175
176 Returns: 0 if same
177 *---------------------------------------------------------------------------*/
178 extern int STD_CompareString(const char *str1, const char *str2);
179
180 /*---------------------------------------------------------------------------*
181 Name: STD_CompareNString
182
183 Description: same to strncmp
184
185 Arguments: str1, str2 : strings
186 len: max length
187
188 Returns: 0 if same
189 *---------------------------------------------------------------------------*/
190 extern int STD_CompareNString(const char *str1, const char *str2, int len);
191
192 /*---------------------------------------------------------------------------*
193 Name: STD_CompareLString
194
195 Description: same to strlcmp
196
197 Arguments: str1, str2 : strings
198 len: max length
199
200 Returns: 0 if same
201 *---------------------------------------------------------------------------*/
202 extern int STD_CompareLString(const char *str1, const char *str2, int len);
203
204 /*---------------------------------------------------------------------------*
205 Name: STD_CompareNString
206
207 Description: This is the same as strncasecmp.
208
209 Arguments: str1, str2 : strings
210 len: max length
211
212 Returns: 0 if same
213 *---------------------------------------------------------------------------*/
214 extern int STD_CompareNIString(const char *str1, const char *str2, int len);
215
216 /*---------------------------------------------------------------------------*
217 Name: STD_TSScanf
218
219 Description: sscanf with size reduced.
220 Supports basic format specifications "%(*?)([lh]{,2})([diouxXpn])".
221
222 Arguments: src Input string
223 fmt Format control string
224
225 Returns: Total number of substituted values.
226 Returns -1 if the function ends without a substitution or an error is detected.
227 *---------------------------------------------------------------------------*/
228 extern int STD_TSScanf(const char *src, const char *fmt, ...);
229
230 /*---------------------------------------------------------------------------*
231 Name: STD_TVSScanf
232
233 Description: This version supports va_list used with STD_TSScanf.
234 Supports basic format specification "%(*?)([lh]{,2})[diouxX]".
235
236 Arguments: src Input string
237 fmt Format control string
238 vlist Parameters
239
240 Returns: Total number of substituted values.
241 Returns -1 if the function ends without a substitution or an error is detected.
242 *---------------------------------------------------------------------------*/
243 extern int STD_TVSScanf(const char *src, const char *fmt, va_list vlist);
244
245 /*---------------------------------------------------------------------------*
246 Name: STD_TSPrintf
247
248 Description: With the exception of the format of the arguments, identical to STD_TVSNPrintf.
249
250 Arguments: dst The buffer that will store the result
251 fmt Format control string
252
253 Returns: Identical to STD_VSNPrintf.
254 *---------------------------------------------------------------------------*/
255 extern int STD_TSPrintf(char *dst, const char *fmt, ...);
256
257 /*---------------------------------------------------------------------------*
258 Name: STD_TVSPrintf
259
260 Description: With the exception of the format of the arguments, identical to STD_TVSNPrintf.
261
262 Arguments: dst The buffer that will store the result
263 fmt Format control string
264 vlist Parameters
265
266 Returns: Identical to STD_VSNPrintf.
267 *---------------------------------------------------------------------------*/
268 extern int STD_TVSPrintf(char *dst, const char *fmt, va_list vlist);
269
270 /*---------------------------------------------------------------------------*
271 Name: STD_TSNPrintf
272
273 Description: With the exception of the format of the arguments, identical to STD_TVSNPrintf.
274
275 Arguments: dst The buffer that will store the result
276 len Buffer length
277 fmt Format control string
278
279 Returns: Identical to STD_VSNPrintf.
280 *---------------------------------------------------------------------------*/
281 extern int STD_TSNPrintf(char *dst, size_t len, const char *fmt, ...);
282
283 /*---------------------------------------------------------------------------*
284 Name: STD_TVSNPrintf
285
286 Description: sprintf redone to save on size.
287 Supports basic format specifications.
288 %([-+# ]?)([0-9]*)(\.?)([0-9]*)([l|ll|h||hh]?)([diouxXpncs%])
289
290 Note: The '+' and '#' characters are disabled to match the behavior of sprintf() in CodeWarrior's MSL.
291
292 { // example
293 char buf[5];
294 sprintf(buf, "%-i\n", 45); // "45" (OK)
295 sprintf(buf, "%0i\n", 45); // "45" (OK)
296 sprintf(buf, "% i\n", 45); // " 45" (OK)
297 sprintf(buf, "%+i\n", 45); // "%+i" ("+45" expected)
298 sprintf(buf, "%#x\n", 45); // "%#x" ("0x2d" expected)
299 // but, this works correctly!
300 sprintf(buf, "% +i\n", 45); // "+45" (OK)
301 }
302
303 Arguments: dst The buffer that will store the result
304 len Buffer length
305 fmt Format control string
306 vlist Parameters
307
308 Returns: Returns the number of characters (exclusive of '\0') when the format string is output correctly.
309 When the buffer size is sufficient, all text is output and a terminator is provided.
310 When the buffer size is not enough, termination occurs at dst[len-1].
311 Nothing happens when len is 0.
312
313 *---------------------------------------------------------------------------*/
314 extern int STD_TVSNPrintf(char *dst, size_t len, const char *fmt, va_list vlist);
315
316
STD_CopyMemory(void * destp,const void * srcp,u32 size)317 static inline void* STD_CopyMemory(void *destp, const void *srcp, u32 size)
318 {
319 MI_CpuCopy(srcp, destp, size);
320 return destp;
321 }
322
STD_MoveMemory(void * destp,const void * srcp,u32 size)323 static inline void* STD_MoveMemory(void *destp, const void *srcp, u32 size)
324 {
325 MI_CpuMove(srcp, destp, size);
326 return destp;
327 }
328
STD_FillMemory(void * destp,u8 data,u32 size)329 static inline void* STD_FillMemory(void *destp, u8 data, u32 size)
330 {
331 MI_CpuFill(destp, data, size);
332 return destp;
333 }
334
335 #ifdef __cplusplus
336 } /* extern "C" */
337 #endif
338
339 /* NITRO_STD_STRING_H_ */
340 #endif
341