1 | /* |
---|
2 | * string.h - string related helper functions definition. |
---|
3 | * |
---|
4 | * Authors Ghassan Almaless (2007,2009,2010,2011,2012) |
---|
5 | * Alain Greiner (2017) |
---|
6 | * |
---|
7 | * Copyright (c) UPMC Sorbonne Universites |
---|
8 | * |
---|
9 | * This file is part of ALMOS-MKH. |
---|
10 | * |
---|
11 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
---|
12 | * under the terms of the GNU General Public License as published by |
---|
13 | * the Free Software Foundation; version 2.0 of the License. |
---|
14 | * |
---|
15 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
---|
16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
18 | * General Public License for more details. |
---|
19 | * |
---|
20 | * You should have received a copy of the GNU General Public License |
---|
21 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
---|
22 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
23 | */ |
---|
24 | |
---|
25 | #ifndef _STRING_H_ |
---|
26 | #define _STRING_H_ |
---|
27 | |
---|
28 | #include <hal_types.h> |
---|
29 | |
---|
30 | |
---|
31 | /******************************************************************************************** |
---|
32 | * This function returns the length of a character string. |
---|
33 | ******************************************************************************************** |
---|
34 | * @ s : pointer on the string. |
---|
35 | * @ return the number of characters preceding the NUL character. |
---|
36 | *******************************************************************************************/ |
---|
37 | uint32_t strlen( const char * s ); |
---|
38 | |
---|
39 | /******************************************************************************************** |
---|
40 | * This function attempts to compute the length of a string, but never scans beyond |
---|
41 | * <maxlen> characters. |
---|
42 | ******************************************************************************************** |
---|
43 | * @ s : pointer on the string. |
---|
44 | * returns min( maxlen , number of characters preceding the NUL character). |
---|
45 | *******************************************************************************************/ |
---|
46 | uint32_t strnlen( const char * str, |
---|
47 | uint32_t maxlen ); |
---|
48 | |
---|
49 | /******************************************************************************************** |
---|
50 | * This function compares lexicographically the strind s1 and s2. |
---|
51 | * characters are considered unsigned. |
---|
52 | * I does not compare characters after the first NUL character. |
---|
53 | ******************************************************************************************** |
---|
54 | * @ s1 : pointer on string. |
---|
55 | * @ s2 : pointer on string. |
---|
56 | * @ return 0 if s1 == s2 / return 1 if s1 > s2 / return -1 if s1 < s2 |
---|
57 | *******************************************************************************************/ |
---|
58 | int strcmp ( const char * s1, |
---|
59 | const char * s2 ); |
---|
60 | |
---|
61 | /******************************************************************************************** |
---|
62 | * This function compares lexicographically the strind s1 and s2. |
---|
63 | * I does not compare than <n> characters and stops after the first NUL character. |
---|
64 | ******************************************************************************************** |
---|
65 | * @ s1 : pointer on string. |
---|
66 | * @ s2 : pointer on string. |
---|
67 | * @ n : max number of compared characters. |
---|
68 | * @ return 0 if s1 == s2 / return 1 if s1 > s2 / return -1 if s1 < s2 |
---|
69 | *******************************************************************************************/ |
---|
70 | int strncmp ( const char * s1, |
---|
71 | const char * s2, |
---|
72 | uint32_t n ); |
---|
73 | |
---|
74 | /******************************************************************************************** |
---|
75 | * This function compares lexicographically the strind s1 and s2, ignoring case. |
---|
76 | ******************************************************************************************** |
---|
77 | * @ s1 : pointer on string. |
---|
78 | * @ s2 : pointer on string. |
---|
79 | * @ return 0 if s1 == s2 / return 1 if s1 > s2 / return -1 if s1 < s2 |
---|
80 | *******************************************************************************************/ |
---|
81 | int strcasecmp ( const char * s1, |
---|
82 | const char * s2 ); |
---|
83 | |
---|
84 | /******************************************************************************************** |
---|
85 | * this function copies the <src> buffer to the <dst> buffer, including the terminating NUL. |
---|
86 | ******************************************************************************************** |
---|
87 | * @ dst : pointer on destination buffer. |
---|
88 | * @ src : pointer on source buffer. |
---|
89 | *******************************************************************************************/ |
---|
90 | char * strcpy ( char * dst, |
---|
91 | char * src ); |
---|
92 | |
---|
93 | /******************************************************************************************** |
---|
94 | * This function copies <n> characters from the <sr> buffer to the <dst> buffer. |
---|
95 | ******************************************************************************************** |
---|
96 | * @ dst : pointer on destination buffer. |
---|
97 | * @ src : pointer on source buffer. |
---|
98 | * @ n : number of characters to be copied. |
---|
99 | *******************************************************************************************/ |
---|
100 | char * strncpy ( char * dst, |
---|
101 | char * src, |
---|
102 | uint32_t n ); |
---|
103 | |
---|
104 | /******************************************************************************************** |
---|
105 | * This function locates the first occurence of the <c> character in the <s> string. |
---|
106 | ******************************************************************************************** |
---|
107 | * @ s : string to be analysed. |
---|
108 | * @ c : searched character value (casted to a char) |
---|
109 | * @ return pointer on the found character / return NULL if not found. |
---|
110 | *******************************************************************************************/ |
---|
111 | char * strchr ( const char * s, |
---|
112 | int c ); |
---|
113 | |
---|
114 | /******************************************************************************************** |
---|
115 | * This function locates the last occurence of the <c> character in the <s> string. |
---|
116 | ******************************************************************************************** |
---|
117 | * @ s : string to be analysed. |
---|
118 | * @ c : searched character value (casted to a char) |
---|
119 | * @ return pointer on the found character / return NULL if not found. |
---|
120 | *******************************************************************************************/ |
---|
121 | char * strrchr ( const char * t, |
---|
122 | int c ); |
---|
123 | |
---|
124 | #endif /* _STRING_H_ */ |
---|