]> git.sur5r.net Git - openldap/blob - contrib/tweb/strng.c
* configure.in: add tcl8.2 to list of tcl libs to search for, also added new MOD_TCL_LIB
[openldap] / contrib / tweb / strng.c
1 /*_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
2 *                                                                          *
3 * strng.c....                                                              *
4 *                                                                          *
5 * Function:..String Handling Functions                                     *
6 *                                                                          *
7 *                                                                          *
8 *                                                                          *
9 * Authors:...Dr. Kurt Spanier & Bernhard Winkler,                          *
10 *            Zentrum fuer Datenverarbeitung, Bereich Entwicklung           *
11 *            neuer Dienste, Universitaet Tuebingen, GERMANY                *
12 *                                                                          *
13 *                                       ZZZZZ  DDD    V   V                *
14 *            Creation date:                Z   D  D   V   V                *
15 *            February 13 1996             Z    D   D   V V                 *
16 *            Last modification:          Z     D  D    V V                 *
17 *            November 3 1998            ZZZZ   DDD      V                  *
18 *                                                                          *
19 _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_*/
20
21 /*
22  * $Id: strng.c,v 1.6 1999/09/10 15:01:19 zrnsk01 Exp $
23  *
24  */
25
26 #include "strng_exp.h"
27 #include "tgeneral.h"
28
29 /*
30  *  Convert string to integer by means of a dispatcherlist
31  *  if string is not in the dispatcher -> return default
32  */
33
34 PUBLIC int cnvt_str2int (stringVal, dispatcher, defaultVal)
35 STRDISP_P  dispatcher;
36 int        defaultVal;
37 char      *stringVal;
38 {
39         int        retVal = defaultVal;
40         STRDISP_P  disp;
41         
42         for (disp = dispatcher; disp->stringVal; disp++) {
43         
44                 if (!strncmp (stringVal, disp->stringVal, disp->abbr)) {
45                 
46                         retVal = disp->intVal;
47                         break;
48                         
49                 }
50         }
51         
52         return (retVal);
53         
54 } /* cnvt_str2int */
55
56
57 /*
58  *  Truncate characters at the beginning of a string
59  */
60
61 PUBLIC char * trimleft (s, what)
62 char   *s, *what;
63 {
64
65         return (s + strspn (s, what));
66
67 } /* trimleft */
68
69
70 /*
71  *  Truncate characters at the end of a string
72  */
73
74 PUBLIC char * trimright (s, what)
75 char   *s, *what;
76 {
77         char  *tmp = s + strlen (s) - 1;
78
79         while ((tmp >= s) && strchr (what, *tmp)) *tmp-- = '\0';
80
81         return (s);
82
83 } /* trimright */
84
85
86 /*
87  *  Truncate characters at the beginning and end of a string
88  */
89
90 PUBLIC char * trim (s, what)
91 char   *s, *what;
92 {
93         (void) trimright (s, what);
94         return (trimleft (s, what));
95
96 } /* trim */
97
98
99 /*
100  *  Convert a string to lower-case "in place"
101  *  uses tolower()
102  */
103
104 PUBLIC char *str_tolower (source)
105 char  *source;
106 {
107         char  *target = source;
108
109         for (; *target; target++) *target = tolower (*target);
110         return (source);
111
112 } /* str_tolower */
113
114
115 /*
116  *  Convert a string to upper-case "in place"
117  *  uses toupper()
118  */
119
120 PUBLIC char *str_toupper (source)
121 char  *source;
122 {
123         char  *target = source;
124
125         for (; *target; target++){
126             *target = toupper (*target);
127
128             /* Patch fuer Umlaute */
129             if(*target == 'ä') *target = 'Ä';
130             else if(*target == 'ö') *target = 'Ö';
131             else if(*target == 'ü') *target = 'Ü';
132         }
133         return (source);
134
135 } /* str_toupper */
136
137
138 /*
139  *  Substitute a character in a string by another
140  */
141
142 PUBLIC char *tr1 (source, from, to)
143 char  *source;
144 char   from, to;
145 {
146         char *target = source - 1;
147
148         while ( ( target = strchr( ++target, from )) ) *target = to;
149
150         return (source);
151
152 } /* tr1 */
153
154
155 PUBLIC int chrcnt(string, c)
156 char *string;
157 char *c;
158 {
159         int count=0;
160
161         string--;
162         while( ( string = strpbrk(string+1, c)) )
163                 count++;
164         return(count);
165 }
166 /* end of function: chrcnt */
167
168
169 PUBLIC int
170 qSortByString( a, b )
171 char **a, **b;
172 {
173         return strcmp( *a, *b );
174 }
175 /*  end of function: qSortByString  */
176
177