string_utils.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright (c) 2017 Google Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #ifndef SOURCE_UTIL_STRING_UTILS_H_
  15. #define SOURCE_UTIL_STRING_UTILS_H_
  16. #include <sstream>
  17. #include <string>
  18. #include "source/util/string_utils.h"
  19. namespace spvtools {
  20. namespace utils {
  21. // Converts arithmetic value |val| to its default string representation.
  22. template <class T>
  23. std::string ToString(T val) {
  24. static_assert(
  25. std::is_arithmetic<T>::value,
  26. "spvtools::utils::ToString is restricted to only arithmetic values");
  27. std::stringstream os;
  28. os << val;
  29. return os.str();
  30. }
  31. // Converts cardinal number to ordinal number string.
  32. std::string CardinalToOrdinal(size_t cardinal);
  33. // Splits the string |flag|, of the form '--pass_name[=pass_args]' into two
  34. // strings "pass_name" and "pass_args". If |flag| has no arguments, the second
  35. // string will be empty.
  36. std::pair<std::string, std::string> SplitFlagArgs(const std::string& flag);
  37. } // namespace utils
  38. } // namespace spvtools
  39. #endif // SOURCE_UTIL_STRING_UTILS_H_