• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* ------------------------------------------------------------------
2  * Copyright (C) 1998-2009 PacketVideo
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13  * express or implied.
14  * See the License for the specific language governing permissions
15  * and limitations under the License.
16  * -------------------------------------------------------------------
17  */
18 // -*- c++ -*-
19 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
20 
21 //                     O S C L _ S T D S T R I N G
22 
23 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
24 
25 /*! \addtogroup osclbase OSCL Base
26  *
27  * @{
28  */
29 
30 
31 /**
32  *  @file oscl_stdstring.h
33  *  @brief This file provides standard string operations such as strlen,
34  *  strncpy, etc
35  *
36  */
37 
38 
39 #ifndef OSCL_STDSTRING_H_INCLUDED
40 #define OSCL_STDSTRING_H_INCLUDED
41 
42 #ifndef OSCL_BASE_H_INCLUDED
43 #include "oscl_base.h"
44 #endif
45 
46 
47 /**
48  * Gets the length of a string
49  *
50  * @param str    NULL terminated string.
51  *
52  * @return Returns the number of characters in string, excluding the
53  *         terminal NULL.
54  */
55 OSCL_IMPORT_REF uint32 oscl_strlen(const char* str);
56 
57 /**
58  * Gets the length of a wide char string
59  *
60  * @param str    NULL terminated string.
61  *
62  * @return Returns the number of characters in string, excluding the
63  *         terminal NULL.
64  */
65 OSCL_IMPORT_REF uint32 oscl_strlen(const oscl_wchar* str);
66 
67 /**
68  * Copies the chars of one string to another.
69  *
70  * Copies the initial count characters of src to dest and
71  * returns dest. If count is less than or equal to the
72  * length of src, a null character is not appended automatically
73  * to the copied string. If count is greater than the length
74  * of src, the destination string is padded with null characters
75  * up to length count. The behavior of strncpy is undefined
76  * if the source and destination strings overlap.
77  *
78  * @param dest   Destination string
79  * @param src    NULL terminated source string
80  * @param count  Number of chars to copy
81  *
82  * @return Returns dest.
83  */
84 OSCL_IMPORT_REF char* oscl_strncpy(char* dest, const char* src, uint32 count);
85 
86 /**
87  * Copies the chars of one string to another.
88  *
89  * Copies the initial count characters of src to dest and
90  * returns dest. If count is less than or equal to the
91  * length of src, a null character is not appended automatically
92  * to the copied string. If count is greater than the length
93  * of src, the destination string is padded with null characters
94  * up to length count. The behavior of strncpy is undefined
95  * if the source and destination strings overlap.
96  *
97  * @param dest   Destination string
98  * @param src    NULL terminated source string
99  * @param count  Number of chars to copy
100  *
101  * @return Returns dest.
102  */
103 OSCL_IMPORT_REF oscl_wchar* oscl_strncpy(oscl_wchar* dest, const oscl_wchar* src, uint32 count);
104 
105 /**
106  * Lexicographically compares two NULL terminated strings,
107  * str1 and str2, and returns a value indicating the relationship
108  * between them.
109  *
110  * @param str1   String to compare
111  * @param str2   String to compare
112  *
113  * @return Negative if str1 < str2
114  *         Positive if str1 > str2
115  *         Zero if equal
116  */
117 OSCL_IMPORT_REF int32 oscl_strcmp(const char* str1, const char* str2);
118 
119 /**
120  * Lexicographically compares two NULL terminated strings,
121  * str1 and str2, and returns a value indicating the relationship
122  * between them.
123  *
124  * @param str1   String to compare
125  * @param str2   String to compare
126  *
127  * @return Negative if str1 < str2
128  *         Positive if str1 > str2
129  *         Zero if equal
130  */
131 OSCL_IMPORT_REF int32 oscl_strcmp(const oscl_wchar* str1, const oscl_wchar* str2);
132 
133 
134 /**
135  * Lexicographically compares, at most, the first count characters
136  * in str1 and str2 and returns a value indicating the relationship
137  * between the substrings.
138  *
139  * @param str1   String to compare
140  * @param str2   String to compare
141  * @param count  Number of characters to compare
142  *
143  * @return Negative if str1 < str2
144  *         Positive if str1 > str2
145  *         Zero if equal
146  */
147 OSCL_IMPORT_REF int32 oscl_strncmp(const char* str1, const char* str2, uint32 count);
148 
149 /**
150  * Lexicographically compares, at most, the first count characters
151  * in str1 and str2 and returns a value indicating the relationship
152  * between the substrings.
153  *
154  * @param str1   String to compare
155  * @param str2   String to compare
156  * @param count  Number of characters to compare
157  *
158  * @return Negative if str1 < str2
159  *         Positive if str1 > str2
160  *         Zero if equal
161  */
162 OSCL_IMPORT_REF int32 oscl_strncmp(const oscl_wchar* str1, const oscl_wchar* str2, uint32 count);
163 
164 /**
165  * Appends up to count characters from string src to string
166  * dest, and then appends a terminating null character. The
167  * initial character of src overwrites the null character at
168  * the end of dest. Subsequent characters in src are appended
169  * to dest until either the end of src is reached or count
170  * characters have been copied. If copying takes place between
171  * objects that overlap, the behavior is undefined.
172  *
173  * @param dest   null terminated destination string
174  * @param src    source string
175  * @param count  number of characters to append.
176  *
177  * @return dest
178  */
179 OSCL_IMPORT_REF char* oscl_strncat(char* dest, const char* src, uint32 count);
180 
181 /**
182  * Appends up to count characters from string src to string
183  * dest, and then appends a terminating null character. The
184  * initial character of src overwrites the null character at
185  * the end of dest. Subsequent characters in src are appended
186  * to dest until either the end of src is reached or count
187  * characters have been copied. If copying takes place between
188  * objects that overlap, the behavior is undefined.
189  *
190  * @param dest   null terminated destination string
191  * @param src    source string
192  * @param count  number of characters to append.
193  *
194  * @return dest
195  */
196 OSCL_IMPORT_REF oscl_wchar* oscl_strncat(oscl_wchar* dest, const oscl_wchar* src, uint32 count);
197 
198 /**
199  * Finds the first occurrence of c in string, or it
200  * returns NULL if c is not found. The null-terminating
201  * character is included in the search.
202  *
203  * @param str    null terminated source string
204  * @param c      character to search for
205  *
206  * @return
207  */
208 OSCL_IMPORT_REF const char* oscl_strchr(const char *str, int32 c);
209 OSCL_IMPORT_REF char* oscl_strchr(char *str, int32 c);
210 
211 /**
212  * Finds the first occurrence of c in string, or it
213  * returns NULL if c is not found. The null-terminating
214  * character is included in the search.
215  *
216  * @param str    null terminated source string
217  * @param c      character to search for
218  *
219  * @return
220  */
221 OSCL_IMPORT_REF const oscl_wchar* oscl_strchr(const oscl_wchar *str, int32 c);
222 OSCL_IMPORT_REF oscl_wchar* oscl_strchr(oscl_wchar *str, int32 c);
223 
224 /**
225  * Finds the last occurrence of c in string, or it
226  * returns NULL if c is not found. The null-terminating
227  * character is included in the search.
228  *
229  * @param str    null terminated source string
230  * @param c      character to search for
231  *
232  * @return
233  */
234 OSCL_IMPORT_REF const char* oscl_strrchr(const char *str, int32 c);
235 OSCL_IMPORT_REF char* oscl_strrchr(char *str, int32 c);
236 OSCL_IMPORT_REF const oscl_wchar* oscl_strrchr(const oscl_wchar *str, int32 c);
237 OSCL_IMPORT_REF oscl_wchar* oscl_strrchr(oscl_wchar *str, int32 c);
238 
239 /**
240  * Sets the characters of a string to a specified character
241  *
242  * @param dest   buffer to modify
243  * @param val    character to set
244  * @param count  number of chars to set
245  *
246  * @return the value of dest
247  */
248 OSCL_IMPORT_REF char* oscl_strset(char* dest, char val, uint32 count);
249 
250 /**
251  * Sets the characters of a string to a specified character
252  *
253  * @param dest   buffer to modify
254  * @param val    character to set
255  * @param count  number of chars to set
256  *
257  * @return the value of dest
258  */
259 OSCL_IMPORT_REF oscl_wchar* oscl_strset(oscl_wchar* dest, oscl_wchar val, uint32 count);
260 
261 
262 /**
263  * Case in-sensitive string comparision.
264  *
265  * @param str1  string to compare
266  * @param str2  string to compare
267  *
268  *
269  * @return Negative if str1 < str2
270  *         Positive if str1 > str2
271  *         Zero if equal
272  */
273 OSCL_IMPORT_REF int32 oscl_CIstrcmp(const char *str1, const char *str2);
274 
275 /**
276  * Case in-sensitive string comparision.
277  *
278  * @param str1  string to compare
279  * @param str2  string to compare
280  *
281  *
282  * @return Negative if str1 < str2
283  *         Positive if str1 > str2
284  *         Zero if equal
285  */
286 OSCL_IMPORT_REF int32 oscl_CIstrcmp(const oscl_wchar *str1, const oscl_wchar *str2);
287 
288 /**
289  * Lexicographically compares(case in-sensitive), at most, the first
290  * count characters in str1 and str2 and returns a value indicating
291  * the relationship between the substrings.
292  *
293  * @param str1  string to compare
294  * @param str2  string to compare
295  * @param count  Number of characters to compare
296  *
297  *
298  * @return Negative if str1 < str2
299  *         Positive if str1 > str2
300  *         Zero if equal
301  */
302 OSCL_IMPORT_REF int32 oscl_CIstrncmp(const char *str1, const char *str2, uint32 count);
303 
304 /**
305  * Lexicographically compares(case in-sensitive), at most, the first
306  * count characters in str1 and str2 and returns a value indicating
307  * the relationship between the substrings.
308  *
309  * @param str1  string to compare
310  * @param str2  string to compare
311  * @param count  Number of characters to compare
312  *
313  *
314  * @return Negative if str1 < str2
315  *         Positive if str1 > str2
316  *         Zero if equal
317  */
318 OSCL_IMPORT_REF int32 oscl_CIstrncmp(const oscl_wchar *str1, const oscl_wchar *str2, uint32 count);
319 
320 /**
321  * convert upper case ASCII character to lower case.
322  * behaviour of this function for non-ASCII characters is not defined.
323  *
324  * @param car    upper case character.
325  *
326  * @return    lower case character.
327  */
328 OSCL_IMPORT_REF char oscl_tolower(const char car);
329 
330 
331 /**
332  * convert upper case ASCII character to lower case.
333  * behaviour of this function for non-ASCII characters is not defined.
334  *
335  * @param car    upper case character.
336  *
337  * @return    lower case character.
338  */
339 OSCL_IMPORT_REF oscl_wchar oscl_tolower(const oscl_wchar car);
340 
341 
342 /**
343  * check if supplied parameter is an alphabet (ASCII only).
344  *
345  * @param car
346  *
347  * @return    1 if car is an alphabet
348  *            0 if car is not an alphabet.
349  */
350 OSCL_IMPORT_REF bool oscl_isLetter(const char car);
351 
352 
353 /**
354  * find the occurrence of sub-string in a string.
355  *
356  * @param str1   string.
357  * @param str2   sub-string
358  *
359  * @return    pointer to the begining of sub-string.
360  */
361 OSCL_IMPORT_REF const char* oscl_strstr(const char* str1, const char* str2);
362 OSCL_IMPORT_REF char* oscl_strstr(char* str1, const char* str2);
363 
364 
365 /**
366  * find the occurrence of sub-string in a string.
367  *
368  * @param str1   string.
369  * @param str2   sub-string
370  *
371  * @return    pointer to the begining of sub-string.
372  */
373 OSCL_IMPORT_REF const oscl_wchar* oscl_strstr(const oscl_wchar* str1, const oscl_wchar* str2);
374 OSCL_IMPORT_REF oscl_wchar* oscl_strstr(oscl_wchar* str1, const oscl_wchar* str2);
375 
376 
377 /**
378  * Appends string src to string dest, and then appends a
379  * terminating null character. The initial character of src
380  * overwrites the null character at the end of dest.
381  * Subsequent characters in src are appended to dest until
382  * the end of src is reached. If copying takes place between
383  * objects that overlap, the behavior is undefined.
384  *
385  * @param dest   null terminated destination string
386  * @param src    source string
387  *
388  *
389  * @return dest
390  */
391 OSCL_IMPORT_REF char* oscl_strcat(char* dest, const char* src);
392 
393 
394 /**
395  * Appends up to count characters from string src to string
396  * dest, and then appends a terminating null character. The
397  * initial character of src overwrites the null character at
398  * the end of dest. Subsequent characters in src are appended
399  * to dest until either the end of src is reached or count
400  * characters have been copied. If copying takes place between
401  * objects that overlap, the behavior is undefined.
402  *
403  * @param dest   null terminated destination string
404  * @param src    source string
405  * @param count  number of characters to append.
406  *
407  * @return dest
408  */
409 OSCL_IMPORT_REF oscl_wchar* oscl_strcat(oscl_wchar* dest, const oscl_wchar* src);
410 
411 
412 /*! @} */
413 
414 
415 #endif
416