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 
13 class RUDIMENTS_DLLSPEC charstring {
14  public:
15 
17  static size_t length(const char *string);
18 
20  static size_t length(const unsigned char *string);
21 
23  static void zero(char *str, size_t size);
24 
28  static char *append(char *dest, const char *source);
29 
33  static char *append(char *dest, const char *source,
34  size_t size);
35 
39  static char *append(char *dest, int64_t number);
40 
44  static char *append(char *dest, uint64_t number);
45 
49  static char *append(char *dest, double number);
50 
55  static char *append(char *dest, double number,
56  uint16_t scale);
57 
62  static char *append(char *dest, double number,
63  uint16_t precision,
64  uint16_t scale);
65 
69  static char *copy(char *dest, const char *source);
70 
74  static char *copy(char *dest,
75  const char *source, size_t size);
76 
81  static char *copy(char *dest, size_t location,
82  const char *source);
83 
88  static char *copy(char *dest, size_t location,
89  const char *source, size_t size);
90 
95  static char *safeCopy(char *dest, size_t destsize,
96  const char *source);
97 
102  static char *safeCopy(char *dest, size_t destsize,
103  const char *source, size_t sourcesize);
104 
107  static int32_t compare(const char *str1, const char *str2);
108 
111  static int32_t compare(const char *str1, const char *str2,
112  size_t size);
113 
116  static int32_t compareIgnoringCase(const char *str1,
117  const char *str2);
118 
122  static int32_t compareIgnoringCase(const char *str1,
123  const char *str2,
124  size_t size);
125 
130  static bool inSet(const char *str, const char * const *set);
131 
134  static bool contains(const char *haystack,
135  const char *needle);
136 
139  static bool contains(const char *haystack, char needle);
140 
143  static const char *findFirst(const char *haystack,
144  const char *needle);
145 
148  static const char *findFirst(const char *haystack,
149  char needle);
150 
154  static const char *findFirstOrEnd(const char *haystack,
155  char needle);
156 
160  static const char *findFirstOrEnd(const char *haystack,
161  const char *needle);
162 
165  static const char *findLast(const char *haystack,
166  const char *needle);
167 
170  static const char *findLast(const char *haystack,
171  char needle);
172 
175  static char *findFirst(char *haystack, const char *needle);
176 
179  static char *findFirst(char *haystack, char needle);
180 
184  static char *findFirstOrEnd(char *haystack,
185  const char *needle);
186 
189  static char *findLast(char *haystack, const char *needle);
190 
193  static char *findLast(char *haystack, char needle);
194 
198  static const char *findFirstOfSet(const char *haystack,
199  const char *set);
200 
204  static char *findFirstOfSet(char *haystack,
205  const char *set);
206 
211  static const char *findFirstOfSetOrEnd(
212  const char *haystack,
213  const char *set);
214 
219  static char *findFirstOfSetOrEnd(
220  char *haystack,
221  const char *set);
222 
226  static size_t lengthContainingSet(const char *haystack,
227  const char *set);
228 
232  static size_t lengthNotContainingSet(const char *haystack,
233  const char *set);
234 
239  static char *duplicate(const char *str);
240 
246  static char *duplicate(const char *str, size_t length);
247 
249  static void upper(char *str);
250 
252  static void lower(char *str);
253 
256  static void capitalize(char *str);
257 
259  static void rightTrim(char *str);
260 
263  static void rightTrim(char *str, char character);
264 
266  static void leftTrim(char *str);
267 
270  static void leftTrim(char *str, char character);
271 
273  static void bothTrim(char *str);
274 
276  static void bothTrim(char *str, char character);
277 
281  static bool strip(char *str, char character);
282 
286  static bool strip(char *str1, const char *str2);
287 
291  static bool stripSet(char *str1, const char *set);
292 
295  static void replace(char *str,
296  char oldchar, char newchar);
297 
300  static void replace(char *str,
301  const char *oldchars, char newchar);
302 
305  static uint16_t integerLength(int16_t number);
306 
309  static uint16_t integerLength(int32_t number);
310 
313  static uint16_t integerLength(int64_t number);
314 
317  static uint16_t integerLength(uint16_t number);
318 
321  static uint16_t integerLength(uint32_t number);
322 
325  static uint16_t integerLength(uint64_t number);
326 
329  static bool isInteger(const char *val);
330 
333  static bool isInteger(const char *val, int32_t size);
334 
337  static bool isNumber(const char *val);
338 
341  static bool isNumber(const char *val, int32_t size);
342 
346  static char *parseNumber(int16_t number);
347 
351  static char *parseNumber(uint16_t number);
352 
356  static char *parseNumber(int16_t number,
357  uint16_t zeropadding);
358 
362  static char *parseNumber(uint16_t number,
363  uint16_t zeropadding);
364 
368  static char *parseNumber(int32_t number);
369 
373  static char *parseNumber(uint32_t number);
374 
378  static char *parseNumber(int32_t number,
379  uint16_t zeropadding);
380 
384  static char *parseNumber(uint32_t number,
385  uint16_t zeropadding);
386 
390  static char *parseNumber(int64_t number);
391 
395  static char *parseNumber(uint64_t number);
396 
400  static char *parseNumber(int64_t number,
401  uint16_t zeropadding);
402 
406  static char *parseNumber(uint64_t number,
407  uint16_t zeropadding);
408 
409 
413  static char *parseNumber(float number);
414 
418  static char *parseNumber(float number,
419  uint16_t scale);
420 
424  static char *parseNumber(float number,
425  uint16_t precision,
426  uint16_t scale);
427 
431  static char *parseNumber(double number);
432 
436  static char *parseNumber(double number,
437  uint16_t scale);
438 
442  static char *parseNumber(double number,
443  uint16_t precision,
444  uint16_t scale);
445 
449  static char *parseNumber(long double number);
450 
454  static char *parseNumber(long double number,
455  uint16_t scale);
456 
460  static char *parseNumber(long double number,
461  uint16_t precision,
462  uint16_t scale);
463 
465  static int64_t toInteger(const char *string);
466 
470  static int64_t toInteger(const char *string, char **endptr);
471 
473  static int64_t toInteger(const char *string, int32_t base);
474 
478  static int64_t toInteger(const char *string,
479  char **endptr, int32_t base);
480 
482  static uint64_t toUnsignedInteger(const char *string);
483 
487  static uint64_t toUnsignedInteger(const char *string,
488  char **endptr);
489 
492  static uint64_t toUnsignedInteger(const char *string,
493  int32_t base);
494 
499  static uint64_t toUnsignedInteger(const char *string,
500  char **endptr,
501  int32_t base);
502 
503 
505  static long double toFloat(const char *string);
506 
510  static long double toFloat(const char *string,
511  char **endptr);
512 
515  static int64_t convertAmount(const char *amount);
516 
519  static char *convertAmount(int64_t amount);
520 
526  static char *convertAmount(int64_t amount,
527  uint16_t padding);
528 
529 
533  static char *httpEscape(const char *input);
534 
538  static char *httpUnescape(const char *input);
539 
544  static char *escape(const char *input,
545  const char *characters);
546 
551  static char *unescape(const char *input);
552 
556  static void escape(const char *input, uint64_t inputsize,
557  char **output, uint64_t *outputsize,
558  const char *characters);
559 
563  static void unescape(const char *input, uint64_t inputsize,
564  char **output, uint64_t *outputsize);
565 
569  static char *base64Encode(const unsigned char *input);
570 
573  static char *base64Encode(const unsigned char *input,
574  uint64_t inputsize);
575 
579  static void base64Encode(const unsigned char *input,
580  uint64_t inputsize,
581  char **output,
582  uint64_t *outputsize);
583 
587  static unsigned char *base64Decode(const char *input);
588 
591  static unsigned char *base64Decode(const char *input,
592  uint64_t inputsize);
593 
597  static void base64Decode(const char *input,
598  uint64_t inputsize,
599  unsigned char **output,
600  uint64_t *outputsize);
601 
606  static void leftJustify(char *str, int32_t length);
607 
618  static void rightPad(char *str, int32_t lngth,
619  char padchar, bool fill);
620 
625  static void rightJustify(char *str, int32_t length);
626 
630  static void center(char *str, int32_t length);
631 
639  static void split(const char *string,
640  ssize_t stringlength,
641  const char *delimiter,
642  ssize_t delimiterlength,
643  bool collapse,
644  char ***list,
645  uint64_t *listlength);
646 
654  static void split(const char *string,
655  const char *delimiter,
656  ssize_t delimiterlength,
657  bool collapse,
658  char ***list,
659  uint64_t *listlength);
667  static void split(const char *string,
668  ssize_t stringlength,
669  const char *delimiter,
670  bool collapse,
671  char ***list,
672  uint64_t *listlength);
673 
681  static void split(const char *string,
682  const char *delimiter,
683  bool collapse,
684  char ***list,
685  uint64_t *listlength);
686 
690  static char *subString(const char *str,
691  size_t start, size_t end);
692 
696  static char *subString(const char *str, size_t start);
697 
700  static char *insertString(const char *dest,
701  const char *src,
702  uint64_t index);
703 
705  static void obfuscate(char *str);
706 
709  static void deobfuscate(char *str);
710 
716  static char *padString(const char *string,
717  char padchar,
718  int16_t direction,
719  uint64_t totallength);
720 
738  static ssize_t printf(char *buffer, size_t length,
739  const char *format, ...);
740 
761  static ssize_t printf(char *buffer, size_t length,
762  const char *format,
763  va_list *argp);
764 
765  #include <rudiments/private/charstring.h>
766 };
767 
768 #endif