MCPcopy Create free account
hub / github.com/antlr/codebuff / ipStringToBytes

Method ipStringToBytes

output/java_guava/1.4.19/InetAddresses.java:169–200  ·  view source on GitHub ↗
(String ipString)

Source from the content-addressed store, hash-verified

167 }
168
169 private static byte[] ipStringToBytes(String ipString) {
170 // Make a first pass to categorize the characters in this string.
171 boolean hasColon = false;
172 boolean hasDot = false;
173 for (int i = 0; i < ipString.length(); i++) {
174 char c = ipString.charAt(i);
175 if (c == '.') {
176 hasDot = true;
177 } else if (c == ':') {
178 if (hasDot) {
179 return null; // Colons must not appear after dots.
180 }
181 hasColon = true;
182 } else if (Character.digit(c, 16) == -1) {
183 return null; // Everything else must be a decimal or hex digit.
184 }
185 }
186
187 // Now decide which address family to parse.
188 if (hasColon) {
189 if (hasDot) {
190 ipString = convertDottedQuadToHex(ipString);
191 if (ipString == null) {
192 return null;
193 }
194 }
195 return textToNumericFormatV6(ipString);
196 } else if (hasDot) {
197 return textToNumericFormatV4(ipString);
198 }
199 return null;
200 }
201
202 private static byte[] textToNumericFormatV4(String ipString) {
203 byte[] bytes = new byte[IPV4_PART_COUNT];

Callers 4

forStringMethod · 0.95
isInetAddressMethod · 0.95
forUriStringNoThrowMethod · 0.95
isMappedIPv4AddressMethod · 0.95

Calls 5

textToNumericFormatV6Method · 0.95
textToNumericFormatV4Method · 0.95
lengthMethod · 0.45
digitMethod · 0.45

Tested by

no test coverage detected