Rudiments
charstring.h
1 // Copyright (c) 2003 David Muse
2 // See the COPYING file for more information.
3 
4 #ifndef RUDIMENTS_CHARSTRING_H
5 #define RUDIMENTS_CHARSTRING_H
6 
7 #include <rudiments/private/charstringincludes.h>
8 
16 class RUDIMENTS_DLLSPEC charstring {
17  public:
18 
20  static size_t length(const char *string);
21 
23  static size_t length(const unsigned char *string);
24 
26  static bool isNullOrEmpty(const char *string);
27 
29  static bool isNullOrEmpty(const unsigned char *string);
30 
32  static void zero(char *str, size_t size);
33 
37  static char *append(char *dest, const char *source);
38 
42  static char *append(char *dest, const char *source,
43  size_t size);
44 
48  static char *append(char *dest, int64_t number);
49 
53  static char *append(char *dest, uint64_t number);
54 
58  static char *append(char *dest, double number);
59 
64  static char *append(char *dest, double number,
65  uint16_t scale);
66 
71  static char *append(char *dest, double number,
72  uint16_t precision,
73  uint16_t scale);
74 
78  static char *copy(char *dest, const char *source);
79 
83  static char *copy(char *dest,
84  const char *source, size_t size);
85 
90  static char *copy(char *dest, size_t location,
91  const char *source);
92 
97  static char *copy(char *dest, size_t location,
98  const char *source, size_t size);
99 
104  static char *safeCopy(char *dest, size_t destsize,
105  const char *source);
106 
111  static char *safeCopy(char *dest, size_t destsize,
112  const char *source, size_t sourcesize);
113 
116  static int32_t compare(const char *str1, const char *str2);
117 
120  static int32_t compare(const char *str1, const char *str2,
121  size_t size);
122 
125  static int32_t compareIgnoringCase(const char *str1,
126  const char *str2);
127 
131  static int32_t compareIgnoringCase(const char *str1,
132  const char *str2,
133  size_t size);
134 
139  static bool inSet(const char *str, const char * const *set);
140 
145  static bool inSetIgnoringCase(const char *str,
146  const char * const *set);
147 
150  static bool contains(const char *haystack,
151  const char *needle);
152 
155  static bool contains(const char *haystack, char needle);
156 
159  static const char *findFirst(const char *haystack,
160  const char *needle);
161 
164  static const char *findFirst(const char *haystack,
165  char needle);
166 
170  static const char *findFirstOrEnd(const char *haystack,
171  char needle);
172 
176  static const char *findFirstOrEnd(const char *haystack,
177  const char *needle);
178 
181  static const char *findLast(const char *haystack,
182  const char *needle);
183 
186  static const char *findLast(const char *haystack,
187  char needle);
188 
191  static char *findFirst(char *haystack, const char *needle);
192 
195  static char *findFirst(char *haystack, char needle);
196 
200  static char *findFirstOrEnd(char *haystack,
201  const char *needle);
202 
205  static char *findLast(char *haystack, const char *needle);
206 
209  static char *findLast(char *haystack, char needle);
210 
214  static const char *findFirstOfSet(const char *haystack,
215  const char *set);
216 
220  static char *findFirstOfSet(char *haystack,
221  const char *set);
222 
227  static const char *findFirstOfSetOrEnd(
228  const char *haystack,
229  const char *set);
230 
235  static char *findFirstOfSetOrEnd(
236  char *haystack,
237  const char *set);
238 
242  static size_t lengthContainingSet(const char *haystack,
243  const char *set);
244 
248  static size_t lengthNotContainingSet(const char *haystack,
249  const char *set);
250 
255  static char *duplicate(const char *str);
256 
262  static char *duplicate(const char *str, size_t length);
263 
265  static void upper(char *str);
266 
268  static void lower(char *str);
269 
272  static void capitalize(char *str);
273 
275  static void rightTrim(char *str);
276 
279  static void rightTrim(char *str, char character);
280 
282  static void leftTrim(char *str);
283 
286  static void leftTrim(char *str, char character);
287 
289  static void bothTrim(char *str);
290 
292  static void bothTrim(char *str, char character);
293 
297  static bool strip(char *str, char character);
298 
302  static bool strip(char *str1, const char *str2);
303 
307  static bool stripSet(char *str1, const char *set);
308 
311  static void replace(char *str,
312  char oldchar, char newchar);
313 
316  static void replace(char *str,
317  const char *oldchars, char newchar);
318 
321  static uint16_t integerLength(int16_t number);
322 
325  static uint16_t integerLength(int32_t number);
326 
329  static uint16_t integerLength(int64_t number);
330 
333  static uint16_t integerLength(uint16_t number);
334 
337  static uint16_t integerLength(uint32_t number);
338 
341  static uint16_t integerLength(uint64_t number);
342 
345  static bool isInteger(const char *val);
346 
349  static bool isInteger(const char *val, int32_t size);
350 
353  static bool isNumber(const char *val);
354 
357  static bool isNumber(const char *val, int32_t size);
358 
362  static char *parseNumber(int16_t number);
363 
367  static char *parseNumber(uint16_t number);
368 
372  static char *parseNumber(int16_t number,
373  uint16_t zeropadding);
374 
378  static char *parseNumber(uint16_t number,
379  uint16_t zeropadding);
380 
384  static char *parseNumber(int32_t number);
385 
389  static char *parseNumber(uint32_t number);
390 
394  static char *parseNumber(int32_t number,
395  uint16_t zeropadding);
396 
400  static char *parseNumber(uint32_t number,
401  uint16_t zeropadding);
402 
406  static char *parseNumber(int64_t number);
407 
411  static char *parseNumber(uint64_t number);
412 
416  static char *parseNumber(int64_t number,
417  uint16_t zeropadding);
418 
422  static char *parseNumber(uint64_t number,
423  uint16_t zeropadding);
424 
425 
429  static char *parseNumber(float number);
430 
434  static char *parseNumber(float number,
435  uint16_t scale);
436 
440  static char *parseNumber(float number,
441  uint16_t precision,
442  uint16_t scale);
443 
447  static char *parseNumber(double number);
448 
452  static char *parseNumber(double number,
453  uint16_t scale);
454 
458  static char *parseNumber(double number,
459  uint16_t precision,
460  uint16_t scale);
461 
465  static char *parseNumber(long double number);
466 
470  static char *parseNumber(long double number,
471  uint16_t scale);
472 
476  static char *parseNumber(long double number,
477  uint16_t precision,
478  uint16_t scale);
479 
481  static int64_t toInteger(const char *string);
482 
486  static int64_t toInteger(const char *string, char **endptr);
487 
489  static int64_t toInteger(const char *string, int32_t base);
490 
494  static int64_t toInteger(const char *string,
495  char **endptr, int32_t base);
496 
498  static uint64_t toUnsignedInteger(const char *string);
499 
503  static uint64_t toUnsignedInteger(const char *string,
504  char **endptr);
505 
508  static uint64_t toUnsignedInteger(const char *string,
509  int32_t base);
510 
515  static uint64_t toUnsignedInteger(const char *string,
516  char **endptr,
517  int32_t base);
518 
519 
521  static long double toFloat(const char *string);
522 
526  static long double toFloat(const char *string,
527  char **endptr);
528 
531  static int64_t convertAmount(const char *amount);
532 
535  static char *convertAmount(int64_t amount);
536 
542  static char *convertAmount(int64_t amount,
543  uint16_t padding);
544 
545 
549  static char *httpEscape(const char *input);
550 
554  static char *httpUnescape(const char *input);
555 
560  static char *escape(const char *input,
561  const char *characters);
562 
567  static char *unescape(const char *input);
568 
572  static void escape(const char *input, uint64_t inputsize,
573  char **output, uint64_t *outputsize,
574  const char *characters);
575 
579  static void unescape(const char *input, uint64_t inputsize,
580  char **output, uint64_t *outputsize);
581 
585  static char *base64Encode(const unsigned char *input);
586 
589  static char *base64Encode(const unsigned char *input,
590  uint64_t inputsize);
591 
595  static void base64Encode(const unsigned char *input,
596  uint64_t inputsize,
597  char **output,
598  uint64_t *outputsize);
599 
603  static unsigned char *base64Decode(const char *input);
604 
607  static unsigned char *base64Decode(const char *input,
608  uint64_t inputsize);
609 
613  static void base64Decode(const char *input,
614  uint64_t inputsize,
615  unsigned char **output,
616  uint64_t *outputsize);
617 
619  static void obfuscate(char *str);
620 
623  static void deobfuscate(char *str);
624 
629  static void leftJustify(char *str, int32_t length);
630 
635  static void rightJustify(char *str, int32_t length);
636 
640  static void center(char *str, int32_t length);
641 
647  static char *pad(const char *string,
648  char padchar,
649  int16_t direction,
650  uint64_t totallength);
651 
659  static void split(const char *string,
660  ssize_t stringlength,
661  const char *delimiter,
662  ssize_t delimiterlength,
663  bool collapse,
664  char ***list,
665  uint64_t *listlength);
666 
674  static void split(const char *string,
675  const char *delimiter,
676  ssize_t delimiterlength,
677  bool collapse,
678  char ***list,
679  uint64_t *listlength);
687  static void split(const char *string,
688  ssize_t stringlength,
689  const char *delimiter,
690  bool collapse,
691  char ***list,
692  uint64_t *listlength);
693 
701  static void split(const char *string,
702  const char *delimiter,
703  bool collapse,
704  char ***list,
705  uint64_t *listlength);
706 
710  static char *subString(const char *str,
711  size_t start, size_t end);
712 
716  static char *subString(const char *str, size_t start);
717 
720  static char *insertString(const char *dest,
721  const char *src,
722  uint64_t index);
723 
741  static ssize_t printf(char *buffer, size_t length,
742  const char *format, ...);
743 
764  static ssize_t printf(char *buffer, size_t length,
765  const char *format,
766  va_list *argp);
767 
768  #include <rudiments/private/charstring.h>
769 };
770 
771 #endif
Definition: charstring.h:16
Definition: character.h:11