StringUtils.cpp 735 B

123456789101112131415161718192021222324252627282930313233343536
  1. #include "StdInc.h"
  2. #include <vstd/StringUtils.h>
  3. VCMI_LIB_NAMESPACE_BEGIN
  4. namespace vstd
  5. {
  6. DLL_LINKAGE std::vector<std::string> split(std::string s, const std::string& separators)
  7. {
  8. std::vector<std::string> result;
  9. boost::split(result, s, boost::is_any_of(separators));
  10. return result;
  11. }
  12. DLL_LINKAGE std::pair<std::string, std::string> splitStringToPair(const std::string& input, char separator)
  13. {
  14. std::pair<std::string, std::string> ret;
  15. size_t splitPos = input.find(separator);
  16. if (splitPos == std::string::npos)
  17. {
  18. ret.first.clear();
  19. ret.second = input;
  20. }
  21. else
  22. {
  23. ret.first = input.substr(0, splitPos);
  24. ret.second = input.substr(splitPos + 1);
  25. }
  26. return ret;
  27. }
  28. }
  29. VCMI_LIB_NAMESPACE_END