You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
2.7 KiB

  1. /*
  2. Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
  3. Permission to use, copy, modify, and/or distribute this software for any
  4. purpose with or without fee is hereby granted, provided that the above
  5. copyright notice and this permission notice appear in all copies.
  6. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  7. WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  8. MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  9. ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  10. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  11. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  12. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  13. */
  14. #pragma once
  15. #include <set>
  16. #include <string>
  17. #include <vector>
  18. namespace str
  19. {
  20. void
  21. split(const char *str,
  22. const char delimiter,
  23. std::vector<std::string> *result);
  24. void
  25. split(const std::string &str,
  26. const char delimiter,
  27. std::vector<std::string> *result);
  28. void
  29. split(const char *str,
  30. const char delimiter,
  31. std::set<std::string> *result);
  32. void
  33. split(const std::string &str,
  34. const char delimiter,
  35. std::set<std::string> *result);
  36. void
  37. rsplit1(const std::string &str,
  38. const char delimiter,
  39. std::vector<std::string> *result);
  40. void
  41. splitkv(const std::string &str,
  42. const char delimiter,
  43. std::string *key,
  44. std::string *value);
  45. std::string
  46. join(const std::vector<std::string> &vec,
  47. const size_t substridx,
  48. const char sep);
  49. std::string
  50. join(const std::vector<std::string> &vec,
  51. const char sep);
  52. std::string
  53. join(const std::set<std::string> &s,
  54. const char sep);
  55. size_t
  56. longest_common_prefix_index(const std::vector<std::string> &vec);
  57. std::string
  58. longest_common_prefix(const std::vector<std::string> &vec);
  59. std::string
  60. remove_common_prefix_and_join(const std::vector<std::string> &vec,
  61. const char sep);
  62. void
  63. erase_fnmatches(const std::vector<std::string> &pattern,
  64. std::vector<std::string> &strs);
  65. bool
  66. isprefix(const std::string &s0,
  67. const std::string &s1);
  68. bool
  69. startswith(const std::string &str_,
  70. const std::string &prefix_);
  71. bool
  72. endswith(const std::string &str_,
  73. const std::string &suffix_);
  74. std::string
  75. trim(const std::string &str);
  76. }