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

Method ipStringToBytes

output/java_guava/1.4.16/InetAddresses.java:168–199  ·  view source on GitHub ↗
(String ipString)

Source from the content-addressed store, hash-verified

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