MCPcopy Create free account
hub / github.com/NativeScript/android / parse_ipv6

Method parse_ipv6

test-app/runtime/src/main/cpp/ada/ada.cpp:12110–12338  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12108}
12109
12110bool url::parse_ipv6(std::string_view input) {
12111 ada_log("parse_ipv6 ", input, " [", input.size(), " bytes]");
12112
12113 if (input.empty()) {
12114 return is_valid = false;
12115 }
12116 // Let address be a new IPv6 address whose IPv6 pieces are all 0.
12117 std::array<uint16_t, 8> address{};
12118
12119 // Let pieceIndex be 0.
12120 int piece_index = 0;
12121
12122 // Let compress be null.
12123 std::optional<int> compress{};
12124
12125 // Let pointer be a pointer for input.
12126 std::string_view::iterator pointer = input.begin();
12127
12128 // If c is U+003A (:), then:
12129 if (input[0] == ':') {
12130 // If remaining does not start with U+003A (:), validation error, return
12131 // failure.
12132 if (input.size() == 1 || input[1] != ':') {
12133 ada_log("parse_ipv6 starts with : but the rest does not start with :");
12134 return is_valid = false;
12135 }
12136
12137 // Increase pointer by 2.
12138 pointer += 2;
12139
12140 // Increase pieceIndex by 1 and then set compress to pieceIndex.
12141 compress = ++piece_index;
12142 }
12143
12144 // While c is not the EOF code point:
12145 while (pointer != input.end()) {
12146 // If pieceIndex is 8, validation error, return failure.
12147 if (piece_index == 8) {
12148 ada_log("parse_ipv6 piece_index == 8");
12149 return is_valid = false;
12150 }
12151
12152 // If c is U+003A (:), then:
12153 if (*pointer == ':') {
12154 // If compress is non-null, validation error, return failure.
12155 if (compress.has_value()) {
12156 ada_log("parse_ipv6 compress is non-null");
12157 return is_valid = false;
12158 }
12159
12160 // Increase pointer and pieceIndex by 1, set compress to pieceIndex, and
12161 // then continue.
12162 pointer++;
12163 compress = ++piece_index;
12164 continue;
12165 }
12166
12167 // Let value and length be 0.

Callers

nothing calls this directly

Calls 11

is_ascii_hex_digitFunction · 0.85
convert_hex_to_binaryFunction · 0.85
is_digitFunction · 0.85
ipv6Function · 0.85
overlapsFunction · 0.85
swapFunction · 0.70
sizeMethod · 0.45
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
has_valueMethod · 0.45

Tested by

no test coverage detected