MCPcopy Create free account
hub / github.com/Pagghiu/SaneCppLibraries / parseUnsignedByte

Function parseUnsignedByte

Libraries/Plugin/Internal/PluginString.h:268–288  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

tryFindCompilerMethod · 0.85

Calls 3

StringEncodingGetSizeFunction · 0.85
isEmptyMethod · 0.45
sizeInBytesMethod · 0.45

Tested by

no test coverage detected