Menu

[b84aab]: / src / common / str.h  Maximize  Restore  History

Download this file

467 lines (421 with data), 11.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
// This file is part of SmallBASIC
//
// strings
//
// This program is distributed under the terms of the GPL v2.0 or later
// Download the GNU Public License (GPL) from www.gnu.org
//
// Copyright(C) 2000 Nicholas Christopoulos
/**
* @defgroup str Strings
*/
#if !defined(_sb_str_h)
#define _sb_str_h
#include "common/sys.h"
#if defined(__cplusplus)
extern "C" {
#endif
// SJIS
//Begin: Modified by Araiguma
#define IsJIS1Font(x) (((x) >= 0x81 && (x) <= 0x9f) || ((x) >= 0xe0 && (x) <= 0xef))
/**< SJIS charset, true if the first character is belongs to sjis encode @ingroup str */
#define IsJIS2Font(x) ((x) >= 0x40 && (x) <= 0xfc)
/**< SJIS charset, true if the second character is belongs to sjis encode @ingroup str */
#define IsJISFont(x) (IsJIS1Font((x >> 8) & 0xff) && IsJIS2Font(x & 0xff))
/**< SJIS charset, true if the character is belongs to sjis encode @ingroup str */
// End : Modified by Araiguma
// Big5
#define IsBig51Font(x) ((x) >= 0x81 && (x) <= 0xfe)
/**< BIG5 charset, true if the first character is belongs to big5 encode @ingroup str */
#define IsBig52Font(x) (((x) >= 0x40 && (x) <= 0x7e) || ((x) >= 0xa1 && (x) <= 0xfe))
/**< BIG5 charset, true if the second character is belongs to big5 encode @ingroup str */
#define IsBig5Font(x) (IsBig51Font((x >> 8) & 0xff) && IsBig52Font(x & 0xff))
/**< BIG5 charset, true if the character is belongs to big5 encode @ingroup str */
// generic multibyte
#define IsGMB1Font(x) ((x) >= 0x81 && (x) <= 0xfe)
/**< generic-multibyte charset, true if the character is belongs to gmb encode @ingroup str */
#define IsGMB2Font(x) ((x) >= 0x21 && (x) <= 0xff)
/**< generic-multibyte charset, true if the second character is belongs to gmb encode @ingroup str */
#define IsGMBFont(x) (IsGMB1Font((x >> 8) & 0xff) && IsGMB2Font(x & 0xff))
/**< generic-multibyte charset, true if the character is belongs to gmb encode @ingroup str */
#include "languages/chars.en.h"
/**
* @ingroup str
*
* returns true if the character is an alphabet symbol
*
* @param ch the character
* @return non-zero if the character is an alphabet symbol
*/
int is_alpha(int ch) SEC(BCSCAN);
/**
* @ingroup str
*
* returns true if the character is an alphabet symbol or a digit
*
* @param ch the character
* @return non-zero if the character is an alphanumeric symbol
*/
int is_alnum(int ch) SEC(BCSCAN);
/**
* @ingroup str
*
* returns true if the character is a 'space'
*
* @param ch the character
* @return non-zero if the character is a 'space'
*/
int is_space(int ch) SEC(BCSCAN);
/**
* @ingroup str
*
* returns true if the character is a white-space character
*
* @param ch the character
* @return non-zero if the character is a white-space character
*/
int is_wspace(int c) SEC(BCSCAN);
/**
* @ingroup str
*
* returns true if all the characters of the string are digits
*
* @param text the text
* @return true if all the characters of the string are digits
*/
int is_all_digits(const char *text) SEC(BCSCAN);
/**
* @ingroup str
*
* returns true if the string 'name' can be a keyword
*
* @param name the string
* @return true if the string 'name' can be a keyword
*/
int is_keyword(const char *name) SEC(BCSCAN);
/**
* @ingroup str
*
* returns true if the string is a number
*
* @param name the string
* @return true if the string is a number
*/
int is_number(const char *str) SEC(BCSCAN);
/**
* @ingroup str
*
* converts a string to upper-case
*
* @param str the string
* @return the str
*/
char *strupper(char *str) SEC(BIO3);
/**
* @ingroup str
*
* converts a string to lower-case
*
* @param str the string
* @return the str
*/
char *strlower(char *str) SEC(BIO3);
/**
* @ingroup str
*
* stores the next keyword of text in dest and returns a pointer to the next position
*
* @param text the source string
* @param dest the buffer to store the keyword
* @return a pointer in 'text' that points to the next position
*/
char *get_keyword(char *text, char *dest) SEC(BCSCAN);
/**
* @ingroup str
*
* Returns the number of a complex constant numeric expression
*
* type <=0 = error
* 1 = int32
* 2 = double
*
* Warning: octals are different from C (QB compatibility: 009 = 9)
*
* @param text the source text, the text does not need to contains only the expression
* @param dest buffer to return the string of the expression
* @param type the type (1=integer-number, 2=real-number, otherwise error)
* @param lv the integer value
* @param dv the real value
* @return a pointer in 'text' that points to the next position
*/
char *get_numexpr(char *text, char *dest, int *type, var_int_t *lv, var_num_t *dv) SEC(BCSCAN);
/**
* @ingroup str
*
* removes all the leading/trailing white-spaces
*
* <b>Example</b>
* @code
* before " Hello World " -> after "Hello World"
* @endcode
*
* @param str the string
*/
void str_alltrim(char *str) SEC(BIO3);
/**
* @ingroup str
*
* returns the value of a string that contains an integer number in binary form
*
* @param str the string
* @return the number
*/
long bintol(const char *str) SEC(BIO3);
/**
* @ingroup str
*
* returns the value of a string that contains an integer number in octal form
*
* @param str the string
* @return the number
*/
long octtol(const char *str) SEC(BIO3);
/**
* @ingroup str
*
* returns the value of a string that contains an integer number in hexadecimal form
*
* @param str the string
* @return the number
*/
long hextol(const char *str) SEC(BIO3);
/**
* @ingroup str
*
* returns the value of a string that contains a real number in decimal form
*
* @param str the string
* @return the number
*/
var_num_t sb_strtof(const char *str) SEC(BIO3);
#define xsb_strtof(s) sb_strtof((s))
/**
* @ingroup str
*
* returns the value of a string that contains an integer number in decimal form
*
* @param str the string
* @return the number
*/
long xstrtol(const char *str) SEC(BIO3);
/**
* @ingroup str
*
* converts a real number to string
*
* @param num the number
* @param dest is the buffer to store the string
* @return a pointer to dest
*/
char *ftostr(var_num_t num, char *dest) SEC(BIO3);
/**
* @ingroup str
*
* converts an integer number to string
*
* @param num the number
* @param dest is the buffer to store the string
* @return a pointer to dest
*/
char *ltostr(var_int_t num, char *dest) SEC(BIO3);
int strcaseless(const char *s1, const char *s2) SEC(BIO3);
int strcaselessn(const char *s1, const char *s2, int len) SEC(BIO3);
/**
* @ingroup str
*
* locate the substring 's2' into 's1' and return a pointer of the
* first occurence (in 's1') or NULL if not found.
*
* the difference with strstr() is that the stristr do the search ignoring the case
*
* @param s1 the text
* @param s2 the substring
* @return on success a pointer to 's1' in the place which the 's2' is starting; otherwise NULL
*/
char *stristr(const char *s1, const char *s2) SEC(BIO3);
/**
* @ingroup str
*
* locate the substring 's2' into 's1' and return a pointer of the
* first occurence (in 's1') or NULL if not found.
*
* the difference with strstr() is that the q_strstr do the search ignoring everything
* that included in the specified pairs.
*
* example
* @code
* q_strstr("Hello (world of) of", "of", "()");
* @endcode
*
* @param s1 the text
* @param s2 the substring
* @param pairs ignore the string that is included in any of that pairs
* @return on success a pointer to 's1' in the place which the 's2' is starting; otherwise NULL
*/
char *q_strstr(const char *s1, const char *s2, const char *pairs) SEC(BIO3);
#if defined(_PalmOS)
/**
* @ingroup str
*
* searches for the last occurence of the character 'ch' in the string 'source'
*
* @param source the string
* @param ch the character
* @return on success a pointer in 'source' of the last occurence of 'ch'; otherwise returns NULL
*/
char *strrchr(const char *source, int ch) SEC(BIO3);
#endif
/**
* @ingroup str
*
* returns the real-number of a complex-constant numeric expression
*
* @param source is the text
* @returns the real-number
*/
var_num_t numexpr_sb_strtof(char *source) SEC(BIO3);
/**
* @ingroup str
*
* returns the integer-number of a complex-constant numeric expression
*
* @param source is the text
* @returns the real-number
*/
var_int_t numexpr_strtol(char *source) SEC(BIO3);
/**
* @ingroup str
*
* returns the string 'source' enclosed by pairs
*
* @param source the source-string
* @param pairs the pair
* @return a newly allocated string of the enclosed result
*/
char *encldup(const char *source, const char *pairs) SEC(BIO3);
/**
* @ingroup str
*
* returns the string 'source' that is located inside the of some pair of 'pairs'
*
* @param source the source-string
* @param pairs the pairs
* @param ignpairs ignore the string that is included in any of that pairs
* @return a newly allocated string of the disclosed result
*/
char *discldup(const char *source, const char *pairs, const char *ignpairs) SEC(BIO3);
/**
* @ingroup str
*
* The squeeze function removes all duplicated white-spaces from the string, include all the leading/trailing white-spaces.
*
* <b>Example</b>
* @code
* source=" Hello World " -> result="Hello World"
* @endcode
*
* @param source is the source string
* @return a newly created string
*/
char *sqzdup(const char *source) SEC(BIO3);
/**
* @ingroup str
*
* translates the 'what' with the 'with'
*
* @param src is the source string
* @param what is what to search
* @param with is what to replace with
* @return a newly created string
*/
char *transdup(const char *src, const char *what, const char *with) SEC(BIO3);
/**
* @ingroup str
*
* removes all the leading/trailing white-spaces
*
* <b>Example</b>
* @code
* source=" Hello World " -> result="Hello World"
* @endcode
*
* @param source is the source string
* @return a newly created string
*/
char *trimdup(const char *str) SEC(BIO3);
/**
* @ingroup str
*
* with few words, the filename's playground.
*
* @param dest is the buffer to store the result
* @param source is the filename
* @param newdir if not NULL, the directory to replace the old-one (note the newdir must ends with directory-separator character)
* @param prefix if not NULL, the prefix to be used on the basename
* @param new_ext if not NULL, the new extension of the file
* @param suffix if not NULL, the suffix to be used on the basename (before the extension)
* @return a pointer to dest
*/
char *chgfilename(char *dest, char *source, char *newdir, char *prefix, char *new_ext, char *suffix)
SEC(BIO3);
/**
* @ingroup str
*
* returns the basename of source. basename means the name without the directory.
* on error the dest will be empty.
*
* @param dest is the buffer to store the name
* @param source is the filename
* @return a pointer to dest
*/
char *xbasename(char *dest, const char *source) SEC(BIO3);
/**
* @ingroup str
*
* Converts a string which contains c-style special characters
* to normal text.
*
* @param source the string
* @return a newly created string
*/
char *cstrdup(const char *source) SEC(BIO3);
/**
* @ingroup str
*
* Converts a string to c-style string
*
* @param source the string
* @return a newly created string
*/
char *bstrdup(const char *source) SEC(BIO3);
/**
* @ingroup str
*
* returns a pointer of 'source' on the base-name
*
* @param source the string
* @param delim the delimiter
* @return pointer to base
*/
const char *baseof(const char *source, int delim) SEC(BIO3);
/*
*/
char char_table_replace(const char *what_table, int ch, const char *replace_table) SEC(BIO3);
#if defined(_WinBCB)
#define strncasecmp(a,b,n) strnicmp(a,b,n)
#define strcasecmp(a,b) stricmp(a,b)
#endif
#if defined(__cplusplus)
}
#endif
#endif
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.