[string] add StringParseUint8() helper function (#9026)

This commit adds a helper function to parse a decimal number from a
given string as `uint8_t` and skip over the parsed characters. This
is used to simplify the methods parsing IPv6/IPv4 address or prefix
from a string.
This commit is contained in:
Abtin Keshavarzian
2023-05-09 12:54:39 -07:00
committed by GitHub
parent 5081882bb9
commit a259d23e7f
6 changed files with 144 additions and 61 deletions
+1
View File
@@ -295,6 +295,7 @@ void TestIp4CidrFromString(void)
// valid address, invalid suffix
{"1.2.3.4/33", {0}, 0, ot::kErrorParse}, // Prefix length too large
{"1.2.3.4/12345678", {0}, 0, ot::kErrorParse}, // Prefix length too large?
{"1.2.3.4/12a", {0}, 0, ot::kErrorParse}, // Extra char after prefix length.
{"1.2.3.4/-1", {0}, 0, ot::kErrorParse}, // Not even a non-negative integer.
{"1.2.3.4/3.14", {0}, 0, ot::kErrorParse}, // Not even a integer.
{"1.2.3.4/abcd", {0}, 0, ot::kErrorParse}, // Not even a number.