| 83 | // assert_found_terminating_null is passed as false). |
| 84 | template <class InputIt> |
| 85 | inline std::string MakeString(InputIt first, InputIt last, |
| 86 | bool assert_found_terminating_null = true) { |
| 87 | std::string result; |
| 88 | constexpr size_t kCharsPerWord = sizeof(*first); |
| 89 | static_assert(kCharsPerWord == 4, "expect 4-byte word"); |
| 90 | |
| 91 | for (InputIt pos = first; pos != last; ++pos) { |
| 92 | uint32_t word = *pos; |
| 93 | for (size_t byte_index = 0; byte_index < kCharsPerWord; byte_index++) { |
| 94 | uint32_t extracted_word = (word >> (8 * byte_index)) & 0xFF; |
| 95 | char c = static_cast<char>(extracted_word); |
| 96 | if (c == 0) { |
| 97 | return result; |
| 98 | } |
| 99 | result += c; |
| 100 | } |
| 101 | } |
| 102 | assert(!assert_found_terminating_null && |
| 103 | "Did not find terminating null for the string."); |
| 104 | (void)assert_found_terminating_null; /* No unused parameters in release |
| 105 | builds. */ |
| 106 | return result; |
| 107 | } |
| 108 | |
| 109 | // Decode a string from a sequence of words in a vector, using the SPIR-V |
| 110 | // encoding. |