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 
136  static bool inSetIgnoringCase(const char *str,
137  const char * const *set);
138 
141  static bool contains(const char *haystack,
142  const char *needle);
143 
146  static bool contains(const char *haystack, char needle);
147 
150  static const char *findFirst(const char *haystack,
151  const char *needle);
152 
155  static const char *findFirst(const char *haystack,
156  char needle);
157 
161  static const char *findFirstOrEnd(const char *haystack,
162  char needle);
163 
167  static const char *findFirstOrEnd(const char *haystack,
168  const char *needle);
169 
172  static const char *findLast(const char *haystack,
173  const char *needle);
174 
177  static const char *findLast(const char *haystack,
178  char needle);
179 
182  static char *findFirst(char *haystack, const char *needle);
183 
186  static char *findFirst(char *haystack, char needle);
187 
191  static char *findFirstOrEnd(char *haystack,
192  const char *needle);
193 
196  static char *findLast(char *haystack, const char *needle);
197 
200  static char *findLast(char *haystack, char needle);
201 
205  static const char *findFirstOfSet(const char *haystack,
206  const char *set);
207 
211  static char *findFirstOfSet(char *haystack,
212  const char *set);
213 
218  static const char *findFirstOfSetOrEnd(
219  const char *haystack,
220  const char *set);
221 
226  static char *findFirstOfSetOrEnd(
227  char *haystack,
228  const char *set);
229 
233  static size_t lengthContainingSet(const char *haystack,
234  const char *set);
235 
239  static size_t lengthNotContainingSet(const char *haystack,
240  const char *set);
241 
246  static char *duplicate(const char *str);
247 
253  static char *duplicate(const char *str, size_t length);
254 
256  static void upper(char *str);
257 
259  static void lower(char *str);
260 
263  static void capitalize(char *str);
264 
266  static void rightTrim(char *str);
267 
270  static void rightTrim(char *str, char character);
271 
273  static void leftTrim(char *str);
274 
277  static void leftTrim(char *str, char character);
278 
280  static void bothTrim(char *str);
281 
283  static void bothTrim(char *str, char character);
284 
288  static bool strip(char *str, char character);
289 
293  static bool strip(char *str1, const char *str2);
294 
298  static bool stripSet(char *str1, const char *set);
299 
302  static void replace(char *str,
303  char oldchar, char newchar);
304 
307  static void replace(char *str,
308  const char *oldchars, char newchar);
309 
312  static uint16_t integerLength(int16_t number);
313 
316  static uint16_t integerLength(int32_t number);
317 
320  static uint16_t integerLength(int64_t number);
321 
324  static uint16_t integerLength(uint16_t number);
325 
328  static uint16_t integerLength(uint32_t number);
329 
332  static uint16_t integerLength(uint64_t number);
333 
336  static bool isInteger(const char *val);
337 
340  static bool isInteger(const char *val, int32_t size);
341 
344  static bool isNumber(const char *val);
345 
348  static bool isNumber(const char *val, int32_t size);
349 
353  static char *parseNumber(int16_t number);
354 
358  static char *parseNumber(uint16_t number);
359 
363  static char *parseNumber(int16_t number,
364  uint16_t zeropadding);
365 
369  static char *parseNumber(uint16_t number,
370  uint16_t zeropadding);
371 
375  static char *parseNumber(int32_t number);
376 
380  static char *parseNumber(uint32_t number);
381 
385  static char *parseNumber(int32_t number,
386  uint16_t zeropadding);
387 
391  static char *parseNumber(uint32_t number,
392  uint16_t zeropadding);
393 
397  static char *parseNumber(int64_t number);
398 
402  static char *parseNumber(uint64_t number);
403 
407  static char *parseNumber(int64_t number,
408  uint16_t zeropadding);
409 
413  static char *parseNumber(uint64_t number,
414  uint16_t zeropadding);
415 
416 
420  static char *parseNumber(float number);
421 
425  static char *parseNumber(float number,
426  uint16_t scale);
427 
431  static char *parseNumber(float number,
432  uint16_t precision,
433  uint16_t scale);
434 
438  static char *parseNumber(double number);
439 
443  static char *parseNumber(double number,
444  uint16_t scale);
445 
449  static char *parseNumber(double number,
450  uint16_t precision,
451  uint16_t scale);
452 
456  static char *parseNumber(long double number);
457 
461  static char *parseNumber(long double number,
462  uint16_t scale);
463 
467  static char *parseNumber(long double number,
468  uint16_t precision,
469  uint16_t scale);
470 
472  static int64_t toInteger(const char *string);
473 
477  static int64_t toInteger(const char *string, char **endptr);
478 
480  static int64_t toInteger(const char *string, int32_t base);
481 
485  static int64_t toInteger(const char *string,
486  char **endptr, int32_t base);
487 
489  static uint64_t toUnsignedInteger(const char *string);
490 
494  static uint64_t toUnsignedInteger(const char *string,
495  char **endptr);
496 
499  static uint64_t toUnsignedInteger(const char *string,
500  int32_t base);
501 
506  static uint64_t toUnsignedInteger(const char *string,
507  char **endptr,
508  int32_t base);
509 
510 
512  static long double toFloat(const char *string);
513 
517  static long double toFloat(const char *string,
518  char **endptr);
519 
522  static int64_t convertAmount(const char *amount);
523 
526  static char *convertAmount(int64_t amount);
527 
533  static char *convertAmount(int64_t amount,
534  uint16_t padding);
535 
536 
540  static char *httpEscape(const char *input);
541 
545  static char *httpUnescape(const char *input);
546 
551  static char *escape(const char *input,
552  const char *characters);
553 
558  static char *unescape(const char *input);
559 
563  static void escape(const char *input, uint64_t inputsize,
564  char **output, uint64_t *outputsize,
565  const char *characters);
566 
570  static void unescape(const char *input, uint64_t inputsize,
571  char **output, uint64_t *outputsize);
572 
576  static char *base64Encode(const unsigned char *input);
577 
580  static char *base64Encode(const unsigned char *input,
581  uint64_t inputsize);
582 
586  static void base64Encode(const unsigned char *input,
587  uint64_t inputsize,
588  char **output,
589  uint64_t *outputsize);
590 
594  static unsigned char *base64Decode(const char *input);
595 
598  static unsigned char *base64Decode(const char *input,
599  uint64_t inputsize);
600 
604  static void base64Decode(const char *input,
605  uint64_t inputsize,
606  unsigned char **output,
607  uint64_t *outputsize);
608 
613  static void leftJustify(char *str, int32_t length);
614 
625  static void rightPad(char *str, int32_t lngth,
626  char padchar, bool fill);
627 
632  static void rightJustify(char *str, int32_t length);
633 
637  static void center(char *str, int32_t length);
638 
646  static void split(const char *string,
647  ssize_t stringlength,
648  const char *delimiter,
649  ssize_t delimiterlength,
650  bool collapse,
651  char ***list,
652  uint64_t *listlength);
653 
661  static void split(const char *string,
662  const char *delimiter,
663  ssize_t delimiterlength,
664  bool collapse,
665  char ***list,
666  uint64_t *listlength);
674  static void split(const char *string,
675  ssize_t stringlength,
676  const char *delimiter,
677  bool collapse,
678  char ***list,
679  uint64_t *listlength);
680 
688  static void split(const char *string,
689  const char *delimiter,
690  bool collapse,
691  char ***list,
692  uint64_t *listlength);
693 
697  static char *subString(const char *str,
698  size_t start, size_t end);
699 
703  static char *subString(const char *str, size_t start);
704 
707  static char *insertString(const char *dest,
708  const char *src,
709  uint64_t index);
710 
712  static void obfuscate(char *str);
713 
716  static void deobfuscate(char *str);
717 
723  static char *padString(const char *string,
724  char padchar,
725  int16_t direction,
726  uint64_t totallength);
727 
745  static ssize_t printf(char *buffer, size_t length,
746  const char *format, ...);
747 
768  static ssize_t printf(char *buffer, size_t length,
769  const char *format,
770  va_list *argp);
771 
772  #include <rudiments/private/charstring.h>
773 };
774 
775 #endif
Definition: charstring.h:13
Definition: character.h:11