stringtools.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #ifndef STRING_TOOLS_H
  2. #define STRING_TOOLS_H
  3. #include <string>
  4. #include <vector>
  5. #include "Strings.h"
  6. //typedef std::vector<std::string> Strings;
  7. // simple string manipulations
  8. std::string delSpaces(const std::string& s);
  9. std::string trim(const std::string& s);
  10. // reduce each occurence of char to one char
  11. // if a char is used as delimiter and may be doubled
  12. // this function
  13. void reduceToOne(std::string& s, char c);
  14. // replace each occurence of c1 with character c2
  15. void substitute(std::string& s, char c1, char c2);
  16. // split in parts
  17. // uses del as delimiter to split a string in parts
  18. // if expectedParts is given and not zero a wrong
  19. // number of parts causes an exception
  20. int split(const std::string& s, Strings& parts,
  21. char del, int expectedParts = 0);
  22. // functions for parsing of string
  23. // parsing starts at position i and sets i to the
  24. // position after end of read part
  25. // white space after read part is skipped
  26. // skip white spaces
  27. void skipWS(const std::string& s, unsigned int& i);
  28. // read int value
  29. int getInt(const std::string& s, unsigned int& i);
  30. // read long int value
  31. long int getLongInt(const std::string& s, unsigned int& i);
  32. // read long int value
  33. double getDouble(const std::string& s, unsigned int& i);
  34. // read word (series of letters)
  35. std::string getWord(const std::string& s, unsigned int& i);
  36. // pick all digits from a string and convert to long int
  37. // quick and dirty solution to read formatted ints like "1,000,000"
  38. double getNumber(const std::string& l);
  39. // compares first characters of s with the string start
  40. bool startsWith(const std::string& s, const std::string& start);
  41. // string to time
  42. // converts a given string to a time period (in seconds)
  43. time_t stot(const std::string& s);
  44. // time_t to string
  45. // converts a given time period (time_t in seconds) to a string
  46. std::string timeString(time_t t);
  47. // replaces in string template the placeholder string with the
  48. // string given as content
  49. // "my name is %name","%name","Wolfgang" -> "my name is Wolfgang"
  50. void replacePlaceHolder(std::string& templ,
  51. const std::string& placeholder,
  52. const std::string& content);
  53. #endif