source: trunk/libs/string.h @ 420

Last change on this file since 420 was 412, checked in by alain, 7 years ago

Introduce user libraries

File size: 7.6 KB
Line 
1/*
2 * string.h - Caracter string handling API definition.
3 *
4 * Author     Alain Greiner (2016,2017)
5 *
6 * Copyright (c) UPMC Sorbonne Universites
7 *
8 * This file is part of ALMOS-MKH.
9 *
10 * ALMOS-MKH is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2.0 of the License.
13 *
14 * ALMOS-MKH is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#ifndef _STRING_H_
25#define _STRING_H_
26
27/********************************************************************************************
28 * This function returns the length of a character string.
29 ********************************************************************************************
30 * @ s     : pointer on the string.
31 * @ return the number of characters preceding the NUL character.
32 *******************************************************************************************/
33unsigned int strlen( const char * s );
34
35/********************************************************************************************
36 * This function attempts to compute the length of a string, but never scans beyond
37 * <maxlen> characters.
38 ********************************************************************************************
39 * @ s     : pointer on the string.
40 * returns min( maxlen , number of characters preceding the NUL character).
41 *******************************************************************************************/
42unsigned int strnlen( const char * str, 
43                  unsigned int     maxlen );
44
45/********************************************************************************************
46 * This function compares lexicographically the strings s1 and s2.
47 * Characters are considered unsigned.
48 * It does not compare characters after the first NUL character.
49 ********************************************************************************************
50 * @ s1   : pointer on string.
51 * @ s2   : pointer on string.
52 * @ return 0 if s1 == s2 / return 1 if s1 > s2 / return -1 if s1 < s2
53 *******************************************************************************************/
54int strcmp ( const char * s1, 
55             const char * s2 );
56
57/********************************************************************************************
58 * This function compares lexicographically the strings s1 and s2.
59 * It does not compare more than <n> characters and stops after the first NUL character.
60 ********************************************************************************************
61 * @ s1   : pointer on string.
62 * @ s2   : pointer on string.
63 * @ n    : max number of compared characters.
64 * @ return 0 if s1 == s2 / return 1 if s1 > s2 / return -1 if s1 < s2
65 *******************************************************************************************/
66int strncmp ( const char * s1,
67              const char * s2,
68              unsigned int     n );
69
70/********************************************************************************************
71 * This function compares lexicographically the strings s1 and s2, ignoring case.
72 ********************************************************************************************
73 * @ s1   : pointer on string.
74 * @ s2   : pointer on string.
75 * @ return 0 if s1 == s2 / return 1 if s1 > s2 / return -1 if s1 < s2
76 *******************************************************************************************/
77int strcasecmp ( const char * s1,
78                 const char * s2 );
79
80/********************************************************************************************
81 * this function copies the <src> buffer to the <dst> buffer, including the terminating NUL.
82 ********************************************************************************************
83 * @ dst   : pointer on destination buffer.
84 * @ src   : pointer on source buffer.
85 *******************************************************************************************/
86char * strcpy ( char * dst, 
87                char * src );
88
89/********************************************************************************************
90 * This function copies <n> characters from the <sr> buffer to the <dst> buffer.
91 ********************************************************************************************
92 * @ dst   : pointer on destination buffer.
93 * @ src   : pointer on source buffer.
94 * @ n     : number of characters to be copied.
95 *******************************************************************************************/
96char * strncpy ( char         * dst,
97                 char         * src,
98                 unsigned int   n );
99
100/********************************************************************************************
101 * This function locates the first occurence of the <find> string in the <s> string.
102 ********************************************************************************************
103 * @ s     : string to be analysed.
104 * @ find  : searched string
105 * @ return pointer on the found string / return NULL if not found.
106 *******************************************************************************************/
107char * strstr( char       * s,
108               const char * find);
109
110/********************************************************************************************
111 * This function locates the first occurence of the <c> character in the <s> string.
112 ********************************************************************************************
113 * @ s     : string to be analysed.
114 * @ c     : searched character value (casted to a char)
115 * @ return pointer on the found character / return NULL if not found.
116 *******************************************************************************************/
117char * strchr ( const char * s,
118                int          c );
119
120/********************************************************************************************
121 * This function locates the last occurence of the <c> character in the <s> string.
122 ********************************************************************************************
123 * @ s     : string to be analysed.
124 * @ c     : searched character value (casted to a char)
125 * @ return pointer on the found character / return NULL if not found.
126 *******************************************************************************************/
127char * strrchr ( const char * t,
128                 int          c );
129
130/********************************************************************************************
131 * This function returns a lower case ASCII code if input is in [A...Z] range.
132 ********************************************************************************************
133 * @ c     : the 8 LSB bits define the character to be forced to lower case.
134 * @ return lower case ASCII code.
135 *******************************************************************************************/
136inline int tolower( int  c );
137
138/********************************************************************************************
139 * This function returns an upper case ASCII code if input is in [a...z] range.
140 ********************************************************************************************
141 * @ c     : the 8 LSB bits define the character to be forced to upper case.
142 * @ return upper case ASCII code.
143 *******************************************************************************************/
144inline int toupper( int  c );
145
146#endif  /* _STRING_H_ */
147
Note: See TracBrowser for help on using the repository browser.