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 15 #ifndef SOURCE_UTIL_STRING_UTILS_H_ 16 #define SOURCE_UTIL_STRING_UTILS_H_ 17 18 #include <sstream> 19 #include <string> 20 21 #include "source/util/string_utils.h" 22 23 namespace spvtools { 24 namespace utils { 25 26 // Converts arithmetic value |val| to its default string representation. 27 template <class T> ToString(T val)28std::string ToString(T val) { 29 static_assert( 30 std::is_arithmetic<T>::value, 31 "spvtools::utils::ToString is restricted to only arithmetic values"); 32 std::stringstream os; 33 os << val; 34 return os.str(); 35 } 36 37 // Converts cardinal number to ordinal number string. 38 std::string CardinalToOrdinal(size_t cardinal); 39 40 // Splits the string |flag|, of the form '--pass_name[=pass_args]' into two 41 // strings "pass_name" and "pass_args". If |flag| has no arguments, the second 42 // string will be empty. 43 std::pair<std::string, std::string> SplitFlagArgs(const std::string& flag); 44 45 } // namespace utils 46 } // namespace spvtools 47 48 #endif // SOURCE_UTIL_STRING_UTILS_H_ 49