stringutils.h 656 B

1234567891011121314151617181920212223242526272829
  1. #ifndef STRINGUTILS_HPP
  2. #define STRINGUTILS_HPP
  3. #include <vector>
  4. #include <string>
  5. #include <sstream>
  6. #include <stdexcept>
  7. using namespace std;
  8. void Tokenize(const string& str,
  9. vector<string>& tokens,
  10. const string& delimiters);
  11. // http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.1
  12. class BadConversion : public std::runtime_error {
  13. public:
  14. BadConversion(const std::string& s)
  15. : std::runtime_error(s)
  16. { }
  17. };
  18. inline std::string stringify(int x)
  19. {
  20. std::ostringstream o;
  21. if (!(o << x))
  22. throw BadConversion("stringify(int)");
  23. return o.str();
  24. }
  25. #endif // STRINGUTILS_HPP