StringUtils.cpp 964 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * StringUtils.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include <vstd/StringUtils.h>
  12. VCMI_LIB_NAMESPACE_BEGIN
  13. namespace vstd
  14. {
  15. DLL_LINKAGE std::vector<std::string> split(std::string s, const std::string& separators)
  16. {
  17. std::vector<std::string> result;
  18. boost::split(result, s, boost::is_any_of(separators));
  19. return result;
  20. }
  21. DLL_LINKAGE std::pair<std::string, std::string> splitStringToPair(const std::string& input, char separator)
  22. {
  23. std::pair<std::string, std::string> ret;
  24. size_t splitPos = input.find(separator);
  25. if (splitPos == std::string::npos)
  26. {
  27. ret.first.clear();
  28. ret.second = input;
  29. }
  30. else
  31. {
  32. ret.first = input.substr(0, splitPos);
  33. ret.second = input.substr(splitPos + 1);
  34. }
  35. return ret;
  36. }
  37. }
  38. VCMI_LIB_NAMESPACE_END