diff --git a/doc/tutorial.md b/doc/tutorial.md index d794413..3221bc3 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -113,6 +113,8 @@ int main() { } ``` +@remark The library also supports working with Unicode C++ strings such as **UTF-8**, **UTF-16**, **UTF-32** and **wide-char** (`char8_t`, `char16_t`, `char32_t` and `wchar_t`). For strings with a base type of `char`, it is assumed that the input string consists of an **ASCII** character sequence and is not encoded with any encoding. If your application uses the Unicode encoding **UTF-8** for incoming strings with a base type of `char`, you can define the macro `IPADDRESS_CHAR_IS_UTF8`. In this case, all incoming strings with a base type of `char` will be interpreted as **UTF-8** encoding. Despite the support for Unicode, it's important to note that for successful parsing of IP addresses, the incoming string must contain valid symbols for IP addresses. + ### From uint/To uint Below is code demonstrating how to create IP addresses from unsigned integers and convert them back to unsigned integers. @@ -550,6 +552,8 @@ int main() { } ``` +@remark By default, the use of whitespace characters in the scope id is not permitted. If a whitespace character is found in the incoming string within the scope id (for example, `fe80::1ff:fe23:4567:890a%et h2`), an error with the code `error_code::invalid_scope_id` will be generated. However, if for some reason you need to parse and save spaces in the scope id, you can define the macro `IPADDRESS_SCOPE_ID_SUPPORT_SPACES`. + ## Std overrides @note If, for some reason, you don't want the library to overload standard functions, you can define `IPADDRESS_NO_OVERLOAD_STD` during compilation. diff --git a/include/ipaddress/base-v6.hpp b/include/ipaddress/base-v6.hpp index 65181a7..1bab4bf 100644 --- a/include/ipaddress/base-v6.hpp +++ b/include/ipaddress/base-v6.hpp @@ -20,7 +20,11 @@ namespace IPADDRESS_NAMESPACE { namespace internal { IPADDRESS_NODISCARD IPADDRESS_CONSTEXPR IPADDRESS_FORCE_INLINE bool is_invalid_scope_id_symbol(char c) IPADDRESS_NOEXCEPT { - return c == '%' || c == '/' || c == ' ' || (c >= '\t' && c <= '\r'); + return c == '%' || c == '/' +#ifndef IPADDRESS_SCOPE_ID_SUPPORT_SPACES + || c == ' ' || (c >= '\t' && c <= '\r') +#endif // IPADDRESS_SCOPE_ID_SUPPORT_SPACES + ; } } // namespace IPADDRESS_NAMESPACE::internal diff --git a/include/ipaddress/errors.hpp b/include/ipaddress/errors.hpp index e8e8b25..2104a76 100644 --- a/include/ipaddress/errors.hpp +++ b/include/ipaddress/errors.hpp @@ -78,7 +78,7 @@ enum class error_code { expected_at_most_7_other_parts_with_double_colon, /**< With a double colon present, at most seven other parts are expected. */ exactly_8_parts_expected_without_double_colon, /**< Without a double colon, exactly eight parts are expected. */ scope_id_is_too_long, /**< The scope ID in the IPv6 address exceeds the maximum length. */ - invalid_scope_id, /**< The scope ID in the IPv6 address is invalid. */ + invalid_scope_id, /**< The scope ID in the IPv6 address is invalid. If for some reason you need to add whitespace support to the scope id, add the following definition IPADDRESS_SCOPE_ID_SUPPORT_SPACES */ // logic errors invalid_version, /**< The IP address version does not match the expected version. */ diff --git a/include/ipaddress/uint128.hpp b/include/ipaddress/uint128.hpp index 524a892..b580ecb 100644 --- a/include/ipaddress/uint128.hpp +++ b/include/ipaddress/uint128.hpp @@ -1593,8 +1593,8 @@ class uint128_t final { // NOLINT(cppcoreguidelines-special-member-functions) uint128_t result = 0; const T* it = begin; while (it < end) { - auto c = internal::next_char_or_error(it, end, code, error_symbol); - if (code != error_code::no_error) { + const auto c = internal::next_char_or_error(it, end, code, error_symbol); + if (code != error_code::no_error) { // NOLINT(bugprone-branch-clone) return nullptr; } else if (c == '\0') { break; @@ -1613,8 +1613,8 @@ class uint128_t final { // NOLINT(cppcoreguidelines-special-member-functions) uint128_t result = 0; const T* it = begin; while (it < end) { - auto c = internal::next_char_or_error(it, end, code, error_symbol); - if (code != error_code::no_error) { + const auto c = internal::next_char_or_error(it, end, code, error_symbol); + if (code != error_code::no_error) { // NOLINT(bugprone-branch-clone) return nullptr; } else if (c == '\0') { break; @@ -1634,8 +1634,8 @@ class uint128_t final { // NOLINT(cppcoreguidelines-special-member-functions) int digit = 0; const T* it = begin; while (it < end) { - auto c = internal::next_char_or_error(it, end, code, error_symbol); - if (code != error_code::no_error) { + const auto c = internal::next_char_or_error(it, end, code, error_symbol); + if (code != error_code::no_error) { // NOLINT(bugprone-branch-clone) return nullptr; } else if (c == '\0') { break;