Skip to content

Commit

Permalink
Update configuration and tutorial doc
Browse files Browse the repository at this point in the history
  • Loading branch information
VladimirShaleev committed May 27, 2024
1 parent 215ec5a commit 13a8764
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
4 changes: 4 additions & 0 deletions doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion include/ipaddress/base-v6.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion include/ipaddress/errors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
12 changes: 6 additions & 6 deletions include/ipaddress/uint128.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 13a8764

Please sign in to comment.