X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2FMacAddress.cpp;h=c806d9b7feb21ca820e892886ce12caaa7be3d56;hb=1badabb2b6715e70e47040711607e620c5952adf;hp=8db2e6d3c70b85b1514b061bc4f8b610bf1ca586;hpb=d4aacd244f21e76dce685365acc281a9015897c1;p=folly.git diff --git a/folly/MacAddress.cpp b/folly/MacAddress.cpp index 8db2e6d3..c806d9b7 100644 --- a/folly/MacAddress.cpp +++ b/folly/MacAddress.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -72,32 +73,30 @@ string MacAddress::toString() const { void MacAddress::parse(StringPiece str) { // Helper function to convert a single hex char into an integer - auto isSeparatorChar = [](char c) { - return c == ':' || c == '-'; - }; + auto isSeparatorChar = [](char c) { return c == ':' || c == '-'; }; uint8_t parsed[SIZE]; auto p = str.begin(); for (unsigned int byteIndex = 0; byteIndex < SIZE; ++byteIndex) { if (p == str.end()) { - throw invalid_argument(to("invalid MAC address \"", str, - "\": not enough digits")); + throw invalid_argument( + sformat("invalid MAC address '{}': not enough digits", str)); } // Skip over ':' or '-' separators between bytes if (byteIndex != 0 && isSeparatorChar(*p)) { ++p; if (p == str.end()) { - throw invalid_argument(to("invalid MAC address \"", str, - "\": not enough digits")); + throw invalid_argument( + sformat("invalid MAC address '{}': not enough digits", str)); } } // Parse the upper nibble uint8_t upper = detail::hexTable[static_cast(*p)]; if (upper & 0x10) { - throw invalid_argument(to("invalid MAC address \"", str, - "\": contains non-hex digit")); + throw invalid_argument( + sformat("invalid MAC address '{}': contains non-hex digit", str)); } ++p; @@ -115,8 +114,8 @@ void MacAddress::parse(StringPiece str) { lower = upper; upper = 0; } else { - throw invalid_argument(to("invalid MAC address \"", str, - "\": contains non-hex digit")); + throw invalid_argument( + sformat("invalid MAC address '{}': contains non-hex digit", str)); } } ++p; @@ -128,8 +127,8 @@ void MacAddress::parse(StringPiece str) { if (p != str.end()) { // String is too long to be a MAC address - throw invalid_argument(to("invalid MAC address \"", str, - "\": found trailing characters")); + throw invalid_argument( + sformat("invalid MAC address '{}': found trailing characters", str)); } // Only update now that we have successfully parsed the entire @@ -139,8 +138,8 @@ void MacAddress::parse(StringPiece str) { void MacAddress::setFromBinary(ByteRange value) { if (value.size() != SIZE) { - throw invalid_argument(to("MAC address must be 6 bytes " - "long, got ", value.size())); + throw invalid_argument( + sformat("MAC address must be 6 bytes long, got ", value.size())); } memcpy(bytes_ + 2, value.begin(), SIZE); }