| 266 | }; |
| 267 | |
| 268 | [[nodiscard]] constexpr bool parseUnsignedByte(StringSpan text, unsigned char& value) |
| 269 | { |
| 270 | if (text.isEmpty()) |
| 271 | return false; |
| 272 | unsigned int result = 0; |
| 273 | const size_t unitSize = StringEncodingGetSize(text.getEncoding()); |
| 274 | for (size_t offset = 0; offset < text.sizeInBytes(); offset += unitSize) |
| 275 | { |
| 276 | const char* current = text.bytesWithoutTerminator() + offset; |
| 277 | if (unitSize == 2 and current[1] != 0) |
| 278 | return false; |
| 279 | const char character = current[0]; |
| 280 | if (character < '0' or character > '9') |
| 281 | return false; |
| 282 | result = result * 10 + static_cast<unsigned int>(character - '0'); |
| 283 | if (result > 255) |
| 284 | return false; |
| 285 | } |
| 286 | value = static_cast<unsigned char>(result); |
| 287 | return true; |
| 288 | } |
| 289 | } // namespace PluginString |
| 290 | } // namespace SC |
no test coverage detected