estring.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2009-2021 Intel Corporation
  2. // SPDX-License-Identifier: Apache-2.0
  3. #include "estring.h"
  4. #include <algorithm>
  5. #include <ctype.h>
  6. namespace embree
  7. {
  8. char to_lower(char c) { return char(tolower(int(c))); }
  9. char to_upper(char c) { return char(toupper(int(c))); }
  10. std::string toLowerCase(const std::string& s) { std::string dst(s); std::transform(dst.begin(), dst.end(), dst.begin(), to_lower); return dst; }
  11. std::string toUpperCase(const std::string& s) { std::string dst(s); std::transform(dst.begin(), dst.end(), dst.begin(), to_upper); return dst; }
  12. Vec2f string_to_Vec2f ( std::string str )
  13. {
  14. size_t next = 0;
  15. const float x = std::stof(str,&next); str = str.substr(next+1);
  16. const float y = std::stof(str,&next);
  17. return Vec2f(x,y);
  18. }
  19. Vec3f string_to_Vec3f ( std::string str )
  20. {
  21. size_t next = 0;
  22. const float x = std::stof(str,&next); str = str.substr(next+1);
  23. const float y = std::stof(str,&next); str = str.substr(next+1);
  24. const float z = std::stof(str,&next);
  25. return Vec3f(x,y,z);
  26. }
  27. Vec4f string_to_Vec4f ( std::string str )
  28. {
  29. size_t next = 0;
  30. const float x = std::stof(str,&next); str = str.substr(next+1);
  31. const float y = std::stof(str,&next); str = str.substr(next+1);
  32. const float z = std::stof(str,&next); str = str.substr(next+1);
  33. const float w = std::stof(str,&next);
  34. return Vec4f(x,y,z,w);
  35. }
  36. }