summaryrefslogtreecommitdiff
path: root/support/dktools/dk4strx.cpt
blob: cf8b9c8ea9654b43ff6fc36408536849e185b27b (plain)
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
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
%%	options

copyright owner	=	Dirk Krause
copyright year	=	2015-xxxx
license		=	bsd

%%	header

/**	@file	dk4strx.h	String functions for wxChar.
*/

#ifndef DK4CONF_H_INCLUDED
#include "dk4conf.h"
#endif

#ifndef DK4TYPES_H_INCLUDED
#include "dk4types.h"
#endif

#ifndef DK4CONST_H_INCLUDED
#include "dk4const.h"
#endif

#ifndef DK4ERROR_H_INCLUDED
#include "dk4error.h"
#endif

#ifndef DK4WXCS_H_INCLUDED
#include "dk4wxcs.h"
#endif


#ifndef	WX_WXPREC_H_INCLUDED
#include <wx/wxprec.h>
#define	WX_WXPREC_H_INCLUDED 1
#endif
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#if	DK4_HAVE_WX_CHARTYPE_H
#ifndef	WX_CHARTYPE_H_INCLUDED
#include <wx/chartype.h>
#define	WX_CHARTYPE_H_INCLUDED 1
#endif
#else
#if	DK4_HAVE_WX_WXCHAR_H
#ifndef	WX_WXCHAR_H_INCLUDED
#include <wx/wxchar.h>
#define	WX_WXCHAR_H_INCLUDED 1
#endif
#else
#ifndef	WX_WX_H_INCLUDED
#include <wx/wx.h>
#define	WX_WX_H_INCLUDED
#endif
#endif
#endif
#endif

#ifdef __cplusplus
extern "C" {
#endif

/**	Copy string, check destination buffer size.
	@param	dst	Destination buffer address.
	@param	sz	Destination buffer size.
	@param	src	Source string.
	@param	erp	Error report, may be NULL.
	@return	1 on success, 0 on error.
	
	Error codes:
	- DK4_E_INVALID_ARGUMENTS<br>
	  if dst or src is NULL or sz is 0,
	- DK4_E_BUFFER_TOO_SMALL<br>
	  if the dst buffer is too small.
*/
int
dk4strx_cpy_s(wxChar *dst, size_t sz, const wxChar *src, dk4_er_t *erp);

/**	Concatenate strings, check destination buffer size.
	@param	dst	Destination buffer address.
	@param	sz	Destination buffer size.
	@param	src	Source string.
	@param	erp	Error report, may be NULL.
	@return	1 on success, 0 on error.
	
	Error codes:
	- DK4_E_INVALID_ARGUMENTS<br>
	  if dst or src is NULL or sz is 0,
	- DK4_E_MATH_OVERFLOW<br>
	  if a mathematical overflow occured in size calculation,
	- DK4_E_BUFFER_TOO_SMALL<br>
	  if the concatenated string doest not fit into the buffer.
*/
int
dk4strx_cat_s(wxChar *dst, size_t sz, const wxChar *src, dk4_er_t *erp);

/**	Copy characters within a string from right to left.
	This copy operation is intended for moving characters within
	one string from right to left, making the string shorter
	as is. This function does not check buffer size or report
	any error.
	For normal string copy operations, use the dk4strx_cpy_s()
	function instead.
	@param	dst	Destination buffer address.
	@param	src	Source string.
*/
void
dk4strx_cpy_to_left(wxChar *dst, const wxChar *src);

/**	Find string length.
	@param	src	Source string.
	@return	String length.
*/
size_t
dk4strx_len(const wxChar *src);

/**	Compare two strings.
	@param	s1	Left string, may be NULL.
	@param	s2	Right string, may be NULL.
	@return	1 if s1>s2, 0 if s1==s2, -1 if s1<s2.
*/
int
dk4strx_cmp(const wxChar *s1, const wxChar *s2);

/**	Compare two strings, case-insensitive comparison.
	@param	s1	Left string, may be NULL.
	@param	s2	Right string, may be NULL.
	@return	1 if s1>s2, 0 if s1==s2, -1 if s1<s2.
*/
int
dk4strx_casecmp(const wxChar *s1, const wxChar *s2);

/**	Compare two file path names.
	@param	s1	Left string, may be NULL.
	@param	s2	Right string, may be NULL.
	@return	1 if s1>s2, 0 if s1==s2, -1 if s1<s2.
*/
int
dk4strx_pathcmp(const wxChar *s1, const wxChar *s2);

/**	Find first occurance of character c in string s.
	@param	s	String to search for c.
	@param	c	Character to find.
	@return	Pointer to first occurance if found, NULL otherwise.
*/
wxChar *
dk4strx_chr(const wxChar *s, wxChar c);

/**	Find last occurance of character c in string s.
	@param	s	String to search for c.
	@param	c	Character to find.
	@return	Pointer to last occurance if found, NULL otherwise.
*/
wxChar *
dk4strx_rchr(const wxChar *s, wxChar c);

/**	Retrieve first token from *stringp.
	@param	stringp	Adress of string pointer.
	@param	delim	String containing the delimiter set,
			my be NULL to use the default delimiter
			set (space, tabulator, carriage return and newline).
	@return	Pointer to first token on success, NULL if no (further)
	token found.
*/
wxChar *
dk4strx_sep(wxChar **stringp, const wxChar *delim);

/**	Find first token in string.
	@param	src	String to search for tokens.
	@param	delim	String containing the delimiter characters,
			may be NULL to use the default delimiter set.
	@return	Pointer to first token if found, NULL otherwise.
*/
wxChar *
dk4strx_start(const wxChar *src, const wxChar *delim);

/**	Cut string after first token, find start of second token in string.
	@param	src	String to search for tokens,
			normally the result of dk4strx_start() or a
			previous dk4strx_next() call.
	@param	delim	String containing the delimiter characters,
			may be NULL to use the default delimiter set.
	@return	Pointer to second token if found, NULL otherwise.
*/
wxChar *
dk4strx_next(wxChar *src, const wxChar *delim);

/**	Split a string into tokens.
	@param	dpp	Pointer to string pointer array.
	@param	szdpp	Size of destination string pointer array.
	@param	src	Source string to process.
	@param	delim	String containing delimiter characters,
			may be NULL to use the default delimiter set.
	@param	erp	Error report, may be NULL.
	@return	Number of tokens found on success, 0 if no token
	found or on error.
	
	Error codes:
	- DK4_E_INVALID_ARGUMENTS<br>
	  for invalid function arguments,
	- DK4_E_BUFFER_TOO_SMALL<br>
	  with dt.mem.nelem set to the number of tokens in string if the dpp
	  array is too short.
*/
size_t
dk4strx_tokenize(
  wxChar **dpp, size_t szdpp, wxChar *src, const wxChar *delim, dk4_er_t *erp
);

/**	Normalize a string (remove leading and trailing delimiters,
	replace delimiter sequences by just one delimiter).
	@param	src	Buffer containing the string to normalize.
	@param	delim	String containing delimiter characters,
			may be NULL to use the default delimiter set.
*/
void
dk4strx_normalize(wxChar *src, const wxChar *delim);

/**	Find index of a string in an array of strings.
	@param	arr	Array of strings.
	@param	str	String to find in array.
	@param	cs	Flag: Case-sensitive search (0=no, other=yes).
	@return	Non-negative index value on success, -1 on error.
*/
int
dk4strx_array_index(const wxChar * const *arr, const wxChar *str, int cs);

/**	Find index of a string in an array of strings.
	@param	arr	Array of strings allowing abbreviation.
	@param	spec	Special character indicating start of optional text.
	@param	str	String to find in array.
	@param	cs	Flag: Case-sensitive search (0=no, other=yes).
	@return	Non-negative index value on success, -1 on error.
*/
int
dk4strx_abbr_index(
  const wxChar * const	*arr,
  wxChar		 spec,
  const wxChar		*str,
  int cs
);

/**	Check whether a text matches a pattern, the text may be abbreviated.
 	@param	str	Text to check.
 	@param	pattern	Pattern for comparison.
 	@param	spec	Special character marking the abbreviation in the
	pattern.
 	@param	cs	Flag: Case sensitive (1) or not (0).
 	@return	1 for a match, 0 otherwise.
*/
int
dk4strx_is_abbr(const wxChar *str, const wxChar *pattern, wxChar spec, int cs);

/**	Check whether a string represents a boolean value.
	@param	str	String to check.
	@return	1 if str represents a boolean value, 0 otherwise.
*/
int
dk4strx_is_bool(const wxChar *str);

/**	Check whether a string represents the boolean value TRUE.
	@param	str	String to check.
	@return	1 if str represents the boolean value TRUE, 0 otherwise.
*/
int
dk4strx_is_on(const wxChar *str);

#if (defined(_WIN32) && DK4_USE_WINDOWS_LOCAL_ALLOC) \
    || (DK4_HAVE_MALLOC && DK4_HAVE_FREE)

/**	Duplicate string in dynamically allocated memory.
	@param	src	String to duplicate.
	@param	erp	Error report, may be NULL.
	@return	Pointer to string in new memory on succes, NULL on error.
	Use dk4mem_free() to release the memory after usage.
	
	Error codes:
	- DK4_E_INVALID_ARGUMENTS<br>
	  if src is a NULL pointer,
	- DK4_E_MATH_OVERFLOW<br>
	  on mathematical overflow in size calculation,
	- DK4_E_MEMORY<br>
	  if no memory is available.
*/
wxChar *
dk4strx_dup(const wxChar *src, dk4_er_t *erp);

#endif
/* if (defined(_WIN32) ... */

/**	Remove trailing white spaces.
	@param	str	String to remove white spaces from.
	@param	whsp	White spaces set.
*/
void
dk4strx_rtwh(wxChar *str, const wxChar *whsp);

/**	Remove trailing newline from line.
	@param	lptr	Line pointer.
*/
void
dk4strx_delnl(wxChar *lptr);

#ifdef __cplusplus
}
#endif



%%	module

#include "dk4strx.h"


#if DK4_SIZEOF_WXCHAR > 1
#include "dk4strw.h"
#else
#include "dk4str8.h"
#endif



$!trace-include



int
dk4strx_cpy_s(wxChar *dst, size_t sz, const wxChar *src, dk4_er_t *erp)
{
#if DK4_SIZEOF_WXCHAR > 1
  return (dk4strw_cpy_s(dst, sz, src, erp));
#else
  return (dk4str8_cpy_s(dst, sz, src, erp));
#endif
}



int
dk4strx_cat_s(wxChar *dst, size_t sz, const wxChar *src, dk4_er_t *erp)
{
#if DK4_SIZEOF_WXCHAR > 1
  return (dk4strw_cat_s(dst, sz, src, erp));
#else
  return (dk4str8_cat_s(dst, sz, src, erp));
#endif
}



void
dk4strx_cpy_to_left(wxChar *dst, const wxChar *src)
{
#if DK4_SIZEOF_WXCHAR > 1
  dk4strw_cpy_to_left(dst, src);
#else
  dk4str8_cpy_to_left(dst, src);
#endif
}



size_t
dk4strx_len(const wxChar *src)
{
#if DK4_SIZEOF_WXCHAR > 1
  return (dk4strw_len(src));
#else
  return (dk4str8_len(src));
#endif
}



int
dk4strx_cmp(const wxChar *s1, const wxChar *s2)
{
#if DK4_SIZEOF_WXCHAR > 1
  return (dk4strw_cmp(s1, s2));
#else
  return (dk4str8_cmp(s1, s2));
#endif
}



int
dk4strx_casecmp(const wxChar *s1, const wxChar *s2)
{
#if DK4_SIZEOF_WXCHAR > 1
  return (dk4strw_casecmp(s1, s2));
#else
  return (dk4str8_casecmp(s1, s2));
#endif
}



int
dk4strx_pathcmp(const wxChar *s1, const wxChar *s2)
{
#if DK4_SIZEOF_WXCHAR > 1
  return (dk4strw_pathcmp(s1, s2));
#else
  return (dk4str8_pathcmp(s1, s2));
#endif
}



wxChar *
dk4strx_chr(const wxChar *s, wxChar c)
{
#if DK4_SIZEOF_WXCHAR > 1
  return (dk4strw_chr(s, c));
#else
  return (dk4str8_chr(s, c));
#endif
}



wxChar *
dk4strx_rchr(const wxChar *s, wxChar c)
{
#if DK4_SIZEOF_WXCHAR > 1
  return (dk4strw_rchr(s, c));
#else
  return (dk4str8_rchr(s, c));
#endif
}



wxChar *
dk4strx_sep(wxChar **stringp, const wxChar *delim)
{
#if DK4_SIZEOF_WXCHAR > 1
  return (dk4strw_sep(stringp, delim));
#else
  return (dk4str8_sep(stringp, delim));
#endif
}



wxChar *
dk4strx_start(const wxChar *src, const wxChar *delim)
{
#if DK4_SIZEOF_WXCHAR > 1
  return (dk4strw_start(src, delim));
#else
  return (dk4str8_start(src, delim));
#endif
}



wxChar *
dk4strx_next(wxChar *src, const wxChar *delim)
{
#if DK4_SIZEOF_WXCHAR > 1
  return (dk4strw_next(src, delim));
#else
  return (dk4str8_next(src, delim));
#endif
}



size_t
dk4strx_tokenize(
  wxChar **dpp, size_t szdpp, wxChar *src, const wxChar *delim, dk4_er_t *erp
)
{
#if DK4_SIZEOF_WXCHAR > 1
  return (dk4strw_tokenize(dpp, szdpp, src, delim, erp));
#else
  return (dk4str8_tokenize(dpp, szdpp, src, delim, erp));
#endif
}



void
dk4strx_normalize(wxChar *src, const wxChar *delim)
{
#if DK4_SIZEOF_WXCHAR > 1
  dk4strw_normalize(src, delim);
#else
  dk4str8_normalize(src, delim);
#endif
}



int
dk4strx_array_index(const wxChar * const *arr, const wxChar *str, int cs)
{
#if DK4_SIZEOF_WXCHAR > 1
  return (dk4strw_array_index(arr, str, cs));
#else
  return (dk4str8_array_index(arr, str, cs));
#endif
}



int
dk4strx_abbr_index(
  const wxChar * const	*arr,
  wxChar		 spec,
  const wxChar		*str,
  int cs
)
{
#if DK4_SIZEOF_WXCHAR > 1
  return (dk4strw_abbr_index(arr, spec, str, cs));
#else
  return (dk4str8_abbr_index(arr, spec, str, cs));
#endif
}



int
dk4strx_is_abbr(const wxChar *str, const wxChar *pattern, wxChar spec, int cs)
{
#if DK4_SIZEOF_WXCHAR > 1
  return (dk4strw_is_abbr(str, pattern, spec, cs));
#else
  return (dk4str8_is_abbr(str, pattern, spec, cs));
#endif
}



int
dk4strx_is_bool(const wxChar *str)
{
#if DK4_SIZEOF_WXCHAR > 1
  return (dk4strw_is_bool(str));
#else
  return (dk4str8_is_bool(str));
#endif
}



int
dk4strx_is_on(const wxChar *str)
{
#if DK4_SIZEOF_WXCHAR > 1
  return (dk4strw_is_on(str));
#else
  return (dk4str8_is_on(str));
#endif
}



#if (defined(_WIN32) && DK4_USE_WINDOWS_LOCAL_ALLOC) \
    || (DK4_HAVE_MALLOC && DK4_HAVE_FREE)

wxChar *
dk4strx_dup(const wxChar *src, dk4_er_t *erp)
{
#if DK4_SIZEOF_WXCHAR > 1
  return (dk4strw_dup(src, erp));
#else
  return (dk4str8_dup(src, erp));
#endif
}

#endif
/* if (defined(_WIN32) ... */

void
dk4strx_rtwh(wxChar *str, const wxChar *whsp)
{
#if DK4_SIZEOF_WXCHAR > 1
  dk4strw_rtwh(str, whsp);
#else
  dk4str8_rtwh(str, whsp);
#endif
}



void
dk4strx_delnl(wxChar *lptr)
{
#if DK4_SIZEOF_WXCHAR > 1
  dk4strw_delnl(lptr);
#else
  dk4str8_delnl(lptr);
#endif
}