comparison src/aci2/mfw/mfw_str.c @ 3:93999a60b835

src/aci2, src/condat2: import of g23m/condat source pieces from TCS211
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 26 Sep 2016 00:29:36 +0000
parents
children
comparison
equal deleted inserted replaced
2:c41a534f33c6 3:93999a60b835
1 /*
2 +--------------------------------------------------------------------+
3 | PROJECT: MMI-Framework (8417) $Workfile:: mfw_str.c $|
4 | $Author:: Es $ CONDAT GmbH $Revision:: 1 $|
5 | CREATED: 03.08.00 $Modtime:: 03.08.00 18:57 $|
6 | STATE : code |
7 +--------------------------------------------------------------------+
8
9 MODULE : MFW_STR
10
11 PURPOSE : string handling functions
12
13 EXPORT :
14
15 TO DO :
16
17 $History:: mfw_str.c $
18 */
19
20 #define ENTITY_MFW
21
22 #if defined (NEW_FRAME)
23
24 #include "typedefs.h"
25 #include "vsi.h"
26 #include "custom.h"
27 #include "gsm.h"
28
29 #else
30
31 #include "STDDEFS.H"
32 #include "custom.h"
33 #include "gsm.h"
34 #include "vsi.h"
35
36 #endif
37
38 #include "mfw_mfw.h"
39 #include "mfw_sys.h"
40 #include "mfw_str.h"
41
42
43
44 /*
45 +--------------------------------------------------------------------+
46 | PROJECT : MMI-Framework (8417) MODULE : MFW_STR |
47 | STATE : code ROUTINE : mfwStrChr |
48 +--------------------------------------------------------------------+
49
50 PURPOSE : find first occurence of char in string
51
52 */
53
54 MfwChar* mfwStrChr (MfwChar* p, int c)
55 {
56 while (*p && *p != c)
57 p++;
58
59 return (*p) ? p : 0;
60 }
61
62
63 /*
64 +--------------------------------------------------------------------+
65 | PROJECT : MMI-Framework (8417) MODULE : MFW_STR |
66 | STATE : code ROUTINE : mfwStrLen |
67 +--------------------------------------------------------------------+
68
69 PURPOSE : compute length of string
70
71 */
72
73 int mfwStrLen (MfwChar *s)
74 {
75 int i = 0;
76
77 while (*s++)
78 i++;
79
80 return i;
81 }
82
83
84 /*
85 +--------------------------------------------------------------------+
86 | PROJECT : MMI-Framework (8417) MODULE : MFW_STR |
87 | STATE : code ROUTINE : mfwStrSiz |
88 +--------------------------------------------------------------------+
89
90 PURPOSE : get length of counted string
91
92 */
93
94 int mfwStrSiz (MfwStr *s)
95 {
96 #ifdef MFW_COUNTED_STRINGS
97 return s->len;
98 #else
99 return mfwStrLen(s);
100 #endif
101 }
102
103
104 /*
105 +--------------------------------------------------------------------+
106 | PROJECT : MMI-Framework (8417) MODULE : MFW_STR |
107 | STATE : code ROUTINE : mfwStrAt |
108 +--------------------------------------------------------------------+
109
110 PURPOSE : get substring of counted string
111
112 */
113
114 MfwChar* mfwStrAt (MfwStr *s, int off)
115 {
116 #ifdef MFW_COUNTED_STRINGS
117 return s->s+off;
118 #else
119 return s+off;
120 #endif
121 }
122
123
124 /*
125 +--------------------------------------------------------------------+
126 | PROJECT : MMI-Framework (8417) MODULE : MFW_STR |
127 | STATE : code ROUTINE : mfwStrCut |
128 +--------------------------------------------------------------------+
129
130 PURPOSE : cut off (shorten) counted string
131
132 */
133
134 MfwChar* mfwStrCut (MfwStr* s, int n)
135 {
136 #ifdef MFW_COUNTED_STRINGS
137 s->len-=n;
138 s->s[s->len]=0;
139 return s->s;
140 #else
141 s[mfwStrLen(s)-n] = 0;
142 return s;
143 #endif
144 }
145
146
147 /*
148 +--------------------------------------------------------------------+
149 | PROJECT : MMI-Framework (8417) MODULE : MFW_STR |
150 | STATE : code ROUTINE : mfwStrMov |
151 +--------------------------------------------------------------------+
152
153 PURPOSE : move (copy) a string into a counted string (override)
154
155 */
156
157 MfwChar* mfwStrMov (MfwStr* d, int o, MfwChar* s)
158 {
159 #ifdef MFW_COUNTED_STRINGS
160 int i = mfwStrLen(s);
161 memcpy(d->s+o,s,i*sizeof(MfwChar));
162 d->len = i + o;
163 d->s[o+i] = 0;
164 return d->s;
165 #else
166 int i = mfwStrLen(s);
167 memcpy(d+o,s,i*sizeof(MfwChar));
168 d[o+i] = 0;
169 return d;
170 #endif
171 }
172
173
174 /*
175 +--------------------------------------------------------------------+
176 | PROJECT : MMI-Framework (8417) MODULE : MFW_STR |
177 | STATE : code ROUTINE : mfwStrIns |
178 +--------------------------------------------------------------------+
179
180 PURPOSE : insert (copy) a string into a counted string (expand)
181
182 */
183
184 MfwChar* mfwStrIns (MfwStr* d, int o, MfwChar* s)
185 {
186 #ifdef MFW_COUNTED_STRINGS
187 int i = mfwStrLen(s);
188 memmove(d->s+o+i,d->s+o,(mfwStrSiz(d)-o)*sizeof(MfwChar));
189 memmove(d->s+o,s,i*sizeof(MfwChar));
190 d->len += i;
191 return d->s;
192 #else
193 int i = mfwStrLen(s);
194 memmove(d+o+i,d+o,(mfwStrSiz(d)-o)*sizeof(MfwChar));
195 memmove(d+o,s,i*sizeof(MfwChar));
196 return d;
197 #endif
198 }
199
200
201 /*
202 +--------------------------------------------------------------------+
203 | PROJECT : MMI-Framework (8417) MODULE : MFW_STR |
204 | STATE : code ROUTINE : mfwStrApp |
205 +--------------------------------------------------------------------+
206
207 PURPOSE : append string to counted string
208
209 */
210
211 MfwChar* mfwStrApp (MfwStr* s, MfwChar* c)
212 {
213 return mfwStrMov(s,mfwStrSiz(s),c);
214 }
215
216
217 /*
218 +--------------------------------------------------------------------+
219 | PROJECT : MMI-Framework (8417) MODULE : MFW_STR |
220 | STATE : code ROUTINE : mfwStrRChr |
221 +--------------------------------------------------------------------+
222
223 PURPOSE : find last occurence of char in string
224
225 */
226
227 MfwChar* mfwStrRChr (MfwChar* p, int c)
228 {
229 int i = mfwStrLen(p);
230
231 while (i && p[i-1] != c)
232 i--;
233
234 return (i) ? p + i - 1 : 0;
235 }