modified: makefile
[GalaxyCodeBases.git] / BGI / soap_src / soap_builder / inistrlib.c
blobe6ca1bf1bfab2240d65e8ab79cef3ef2be3a53b6
2 /*-------------------------------------------------------------------------*/
3 /**
4 @file strlib.c
5 @author N. Devillard
6 @date Jan 2001
7 @version $Revision: 1.8 $
8 @brief Various string handling routines to complement the C lib.
10 This modules adds a few complementary string routines usually missing
11 in the standard C library.
13 /*--------------------------------------------------------------------------*/
16 $Id: strlib.c,v 1.8 2002/12/12 10:29:16 ndevilla Exp $
17 $Author: ndevilla $
18 $Date: 2002/12/12 10:29:16 $
19 $Revision: 1.8 $
22 /*---------------------------------------------------------------------------
23 Includes
24 ---------------------------------------------------------------------------*/
26 #include <string.h>
27 #include <ctype.h>
28 #include <stdlib.h>
30 #include "inistrlib.h"
32 /*---------------------------------------------------------------------------
33 Defines
34 ---------------------------------------------------------------------------*/
35 #define ASCIILINESZ 1024
37 /*---------------------------------------------------------------------------
38 Function codes
39 ---------------------------------------------------------------------------*/
42 /*-------------------------------------------------------------------------*/
43 /**
44 @brief Convert a string to lowercase.
45 @param s String to convert.
46 @return ptr to statically allocated string.
48 This function returns a pointer to a statically allocated string
49 containing a lowercased version of the input string. Do not free
50 or modify the returned string! Since the returned string is statically
51 allocated, it will be modified at each function call (not re-entrant).
53 /*--------------------------------------------------------------------------*/
55 char * inistrlwc(char * s)
57 static char l[ASCIILINESZ+1];
58 int i ;
60 if (s==NULL) return NULL ;
61 memset(l, 0, ASCIILINESZ+1);
62 i=0 ;
63 while (s[i] && i<ASCIILINESZ) {
64 l[i] = (char)tolower((int)s[i]);
65 i++ ;
67 l[ASCIILINESZ]=(char)0;
68 return l ;
73 /*-------------------------------------------------------------------------*/
74 /**
75 @brief Convert a string to uppercase.
76 @param s String to convert.
77 @return ptr to statically allocated string.
79 This function returns a pointer to a statically allocated string
80 containing an uppercased version of the input string. Do not free
81 or modify the returned string! Since the returned string is statically
82 allocated, it will be modified at each function call (not re-entrant).
84 /*--------------------------------------------------------------------------*/
86 char * inistrupc(char * s)
88 static char l[ASCIILINESZ+1];
89 int i ;
91 if (s==NULL) return NULL ;
92 memset(l, 0, ASCIILINESZ+1);
93 i=0 ;
94 while (s[i] && i<ASCIILINESZ) {
95 l[i] = (char)toupper((int)s[i]);
96 i++ ;
98 l[ASCIILINESZ]=(char)0;
99 return l ;
104 /*-------------------------------------------------------------------------*/
106 @brief Skip blanks until the first non-blank character.
107 @param s String to parse.
108 @return Pointer to char inside given string.
110 This function returns a pointer to the first non-blank character in the
111 given string.
113 /*--------------------------------------------------------------------------*/
115 char * inistrskp(char * s)
117 char * skip = s;
118 if (s==NULL) return NULL ;
119 while (isspace((int)*skip) && *skip) skip++;
120 return skip ;
125 /*-------------------------------------------------------------------------*/
127 @brief Remove blanks at the end of a string.
128 @param s String to parse.
129 @return ptr to statically allocated string.
131 This function returns a pointer to a statically allocated string,
132 which is identical to the input string, except that all blank
133 characters at the end of the string have been removed.
134 Do not free or modify the returned string! Since the returned string
135 is statically allocated, it will be modified at each function call
136 (not re-entrant).
138 /*--------------------------------------------------------------------------*/
140 char * inistrcrop(char * s)
142 static char l[ASCIILINESZ+1];
143 char * last ;
145 if (s==NULL) return NULL ;
146 memset(l, 0, ASCIILINESZ+1);
147 strcpy(l, s);
148 last = l + strlen(l);
149 while (last > l) {
150 if (!isspace((int)*(last-1)))
151 break ;
152 last -- ;
154 *last = (char)0;
155 return l ;
160 /*-------------------------------------------------------------------------*/
162 @brief Remove blanks at the beginning and the end of a string.
163 @param s String to parse.
164 @return ptr to statically allocated string.
166 This function returns a pointer to a statically allocated string,
167 which is identical to the input string, except that all blank
168 characters at the end and the beg. of the string have been removed.
169 Do not free or modify the returned string! Since the returned string
170 is statically allocated, it will be modified at each function call
171 (not re-entrant).
173 /*--------------------------------------------------------------------------*/
174 char * inistrstrip(char * s)
176 static char l[ASCIILINESZ+1];
177 char * last ;
179 if (s==NULL) return NULL ;
181 while (isspace((int)*s) && *s) s++;
183 memset(l, 0, ASCIILINESZ+1);
184 strcpy(l, s);
185 last = l + strlen(l);
186 while (last > l) {
187 if (!isspace((int)*(last-1)))
188 break ;
189 last -- ;
191 *last = (char)0;
193 return (char*)l ;
196 /*-------------------------------------------------------------------------*/
198 @brief Duplicate a string by allocating memory and copy the contents.
199 @param s String to duplicate.
200 @return ptr to dynamically allocated string.
202 This function returns a pointer to a dynamically allocated string,
203 which is identical to the input string.
204 Free the returned string when it is no longer used.
206 /*--------------------------------------------------------------------------*/
207 char *inistrdup(const char *s) {
209 int l;
210 char *dup;
212 l = (int)strlen(s) + 1;
214 dup = malloc(l);
215 if (dup == NULL) {
216 return NULL;
219 memcpy(dup, s, l);
221 return dup;