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 #ifndef UCX_STRING_H
37 #define UCX_STRING_H
38
39 #include "common.h"
40 #include "allocator.h"
41
42
43
44
45 extern unsigned const cx_strstr_sbo_size;
46
47
48
49
50 struct cx_mutstr_s {
51
52
53
54
55
56 char *ptr;
57
58 size_t length;
59 };
60
61
62
63
64 typedef struct cx_mutstr_s cxmutstr;
65
66
67
68
69 struct cx_string_s {
70
71
72
73
74
75 char const *ptr;
76
77 size_t length;
78 };
79
80
81
82
83 typedef struct cx_string_s cxstring;
84
85
86
87
88 struct cx_strtok_ctx_s {
89
90
91
92 cxstring str;
93
94
95
96 cxstring delim;
97
98
99
100 cxstring
const *delim_more;
101
102
103
104 size_t delim_more_count;
105
106
107
108 size_t pos;
109
110
111
112
113
114
115
116 size_t delim_pos;
117
118
119
120 size_t next_pos;
121
122
123
124 size_t found;
125
126
127
128 size_t limit;
129 };
130
131
132
133
134 typedef struct cx_strtok_ctx_s CxStrtokCtx;
135
136 #ifdef __cplusplus
137 extern "C" {
138
139
140
141
142
143
144 #define CX_STR(literal) cxstring{literal,
sizeof(literal) -
1}
145
146 #else
147
148
149
150
151
152
153
154
155 #define CX_STR(literal) (cxstring){literal,
sizeof(literal) -
1}
156
157 #endif
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175 __attribute__((__warn_unused_result__, __nonnull__))
176 cxmutstr cx_mutstr(
char *cstring);
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194 __attribute__((__warn_unused_result__))
195 cxmutstr cx_mutstrn(
196 char *cstring,
197 size_t length
198 );
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215 __attribute__((__warn_unused_result__, __nonnull__))
216 cxstring cx_str(
char const *cstring);
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235 __attribute__((__warn_unused_result__))
236 cxstring cx_strn(
237 char const *cstring,
238 size_t length
239 );
240
241
242
243
244
245
246
247
248
249
250
251 __attribute__((__warn_unused_result__))
252 cxstring cx_strcast(cxmutstr str);
253
254
255
256
257
258
259
260
261
262
263
264
265 __attribute__((__nonnull__))
266 void cx_strfree(cxmutstr *str);
267
268
269
270
271
272
273
274
275
276
277
278
279
280 __attribute__((__nonnull__))
281 void cx_strfree_a(
282 CxAllocator
const *alloc,
283 cxmutstr *str
284 );
285
286
287
288
289
290
291
292
293
294
295
296 __attribute__((__warn_unused_result__))
297 size_t cx_strlen(
298 size_t count,
299 ...
300 );
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320 __attribute__((__warn_unused_result__, __nonnull__))
321 cxmutstr cx_strcat_ma(
322 CxAllocator
const *alloc,
323 cxmutstr str,
324 size_t count,
325 ...
326 );
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342 #define cx_strcat_a(alloc, count, ...) \
343 cx_strcat_ma(alloc, cx_mutstrn(
NULL,
0), count,
__VA_ARGS__)
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358 #define cx_strcat(count, ...) \
359 cx_strcat_ma(cxDefaultAllocator, cx_mutstrn(
NULL,
0), count,
__VA_ARGS__)
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378 #define cx_strcat_m(str, count, ...) \
379 cx_strcat_ma(cxDefaultAllocator, str, count,
__VA_ARGS__)
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396 __attribute__((__warn_unused_result__))
397 cxstring cx_strsubs(
398 cxstring string,
399 size_t start
400 );
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421 __attribute__((__warn_unused_result__))
422 cxstring cx_strsubsl(
423 cxstring string,
424 size_t start,
425 size_t length
426 );
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443 __attribute__((__warn_unused_result__))
444 cxmutstr cx_strsubs_m(
445 cxmutstr string,
446 size_t start
447 );
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468 __attribute__((__warn_unused_result__))
469 cxmutstr cx_strsubsl_m(
470 cxmutstr string,
471 size_t start,
472 size_t length
473 );
474
475
476
477
478
479
480
481
482
483
484
485
486
487 __attribute__((__warn_unused_result__))
488 cxstring cx_strchr(
489 cxstring string,
490 int chr
491 );
492
493
494
495
496
497
498
499
500
501
502
503
504
505 __attribute__((__warn_unused_result__))
506 cxmutstr cx_strchr_m(
507 cxmutstr string,
508 int chr
509 );
510
511
512
513
514
515
516
517
518
519
520
521
522
523 __attribute__((__warn_unused_result__))
524 cxstring cx_strrchr(
525 cxstring string,
526 int chr
527 );
528
529
530
531
532
533
534
535
536
537
538
539
540
541 __attribute__((__warn_unused_result__))
542 cxmutstr cx_strrchr_m(
543 cxmutstr string,
544 int chr
545 );
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563 __attribute__((__warn_unused_result__))
564 cxstring cx_strstr(
565 cxstring haystack,
566 cxstring needle
567 );
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585 __attribute__((__warn_unused_result__))
586 cxmutstr cx_strstr_m(
587 cxmutstr haystack,
588 cxstring needle
589 );
590
591
592
593
594
595
596
597
598
599
600
601
602
603 __attribute__((__warn_unused_result__, __nonnull__))
604 size_t cx_strsplit(
605 cxstring string,
606 cxstring delim,
607 size_t limit,
608 cxstring *output
609 );
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630 __attribute__((__warn_unused_result__, __nonnull__))
631 size_t cx_strsplit_a(
632 CxAllocator
const *allocator,
633 cxstring string,
634 cxstring delim,
635 size_t limit,
636 cxstring **output
637 );
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652 __attribute__((__warn_unused_result__, __nonnull__))
653 size_t cx_strsplit_m(
654 cxmutstr string,
655 cxstring delim,
656 size_t limit,
657 cxmutstr *output
658 );
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679 __attribute__((__warn_unused_result__, __nonnull__))
680 size_t cx_strsplit_ma(
681 CxAllocator
const *allocator,
682 cxmutstr string,
683 cxstring delim,
684 size_t limit,
685 cxmutstr **output
686 );
687
688
689
690
691
692
693
694
695
696 __attribute__((__warn_unused_result__))
697 int cx_strcmp(
698 cxstring s1,
699 cxstring s2
700 );
701
702
703
704
705
706
707
708
709
710 __attribute__((__warn_unused_result__))
711 int cx_strcasecmp(
712 cxstring s1,
713 cxstring s2
714 );
715
716
717
718
719
720
721
722
723
724
725
726 __attribute__((__warn_unused_result__, __nonnull__))
727 int cx_strcmp_p(
728 void const *s1,
729 void const *s2
730 );
731
732
733
734
735
736
737
738
739
740
741
742 __attribute__((__warn_unused_result__, __nonnull__))
743 int cx_strcasecmp_p(
744 void const *s1,
745 void const *s2
746 );
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761 __attribute__((__warn_unused_result__, __nonnull__))
762 cxmutstr cx_strdup_a(
763 CxAllocator
const *allocator,
764 cxstring string
765 );
766
767
768
769
770
771
772
773
774
775
776
777
778
779 #define cx_strdup(string) cx_strdup_a(cxDefaultAllocator, string)
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794 #define cx_strdup_ma(allocator, string) cx_strdup_a(allocator, cx_strcast(string))
795
796
797
798
799
800
801
802
803
804
805
806
807
808 #define cx_strdup_m(string) cx_strdup_a(cxDefaultAllocator, cx_strcast(string))
809
810
811
812
813
814
815
816
817
818
819 __attribute__((__warn_unused_result__))
820 cxstring cx_strtrim(cxstring string);
821
822
823
824
825
826
827
828
829
830
831 __attribute__((__warn_unused_result__))
832 cxmutstr cx_strtrim_m(cxmutstr string);
833
834
835
836
837
838
839
840
841
842 __attribute__((__warn_unused_result__))
843 bool cx_strprefix(
844 cxstring string,
845 cxstring prefix
846 );
847
848
849
850
851
852
853
854
855
856 __attribute__((__warn_unused_result__))
857 bool cx_strsuffix(
858 cxstring string,
859 cxstring suffix
860 );
861
862
863
864
865
866
867
868
869
870 __attribute__((__warn_unused_result__))
871 bool cx_strcaseprefix(
872 cxstring string,
873 cxstring prefix
874 );
875
876
877
878
879
880
881
882
883
884 __attribute__((__warn_unused_result__))
885 bool cx_strcasesuffix(
886 cxstring string,
887 cxstring suffix
888 );
889
890
891
892
893
894
895
896
897
898 void cx_strlower(cxmutstr string);
899
900
901
902
903
904
905
906
907
908 void cx_strupper(cxmutstr string);
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929 __attribute__((__warn_unused_result__, __nonnull__))
930 cxmutstr cx_strreplacen_a(
931 CxAllocator
const *allocator,
932 cxstring str,
933 cxstring pattern,
934 cxstring replacement,
935 size_t replmax
936 );
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956 #define cx_strreplacen(str, pattern, replacement, replmax) \
957 cx_strreplacen_a(cxDefaultAllocator, str, pattern, replacement, replmax)
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976 #define cx_strreplace_a(allocator, str, pattern, replacement) \
977 cx_strreplacen_a(allocator, str, pattern, replacement,
SIZE_MAX)
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996 #define cx_strreplace(str, pattern, replacement) \
997 cx_strreplacen_a(cxDefaultAllocator, str, pattern, replacement,
SIZE_MAX)
998
999
1000
1001
1002
1003
1004
1005
1006
1007 __attribute__((__warn_unused_result__))
1008 CxStrtokCtx cx_strtok(
1009 cxstring str,
1010 cxstring delim,
1011 size_t limit
1012 );
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022 __attribute__((__warn_unused_result__))
1023 CxStrtokCtx cx_strtok_m(
1024 cxmutstr str,
1025 cxstring delim,
1026 size_t limit
1027 );
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039 __attribute__((__warn_unused_result__, __nonnull__))
1040 bool cx_strtok_next(
1041 CxStrtokCtx *ctx,
1042 cxstring *token
1043 );
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057 __attribute__((__warn_unused_result__, __nonnull__))
1058 bool cx_strtok_next_m(
1059 CxStrtokCtx *ctx,
1060 cxmutstr *token
1061 );
1062
1063
1064
1065
1066
1067
1068
1069
1070 __attribute__((__nonnull__))
1071 void cx_strtok_delim(
1072 CxStrtokCtx *ctx,
1073 cxstring
const *delim,
1074 size_t count
1075 );
1076
1077
1078 #ifdef __cplusplus
1079 }
1080 #endif
1081
1082 #endif
1083