/** * Returns an iterator over the lines in the string. If the string ends in a newline, a final * empty string is not included, to match the behavior of BufferedReader/LineReader.readLine(). */ private Iterator<String> linesIterator() { return new AbstractIterator<String>() { Iterator<String> lines = LINE_SPLITTER.split(seq).iterator(); @Override protected String computeNext() { if (lines.hasNext()) { String next = lines.next(); // skip last line if it's empty if (lines.hasNext() || !next.isEmpty()) { return next; } } return endOfData(); } }; }
@NullableDecl private static byte[] textToNumericFormatV4(String ipString) { byte[] bytes = new byte[IPV4_PART_COUNT]; int i = 0; try { for (String octet : IPV4_SPLITTER.split(ipString)) { bytes[i++] = parseOctet(octet); } } catch (NumberFormatException ex) { return null; } return i == IPV4_PART_COUNT ? bytes : null; }
/** * Splits {@code sequence} into substrings, splits each substring into an entry, and returns an * unmodifiable map with each of the entries. For example, {@code * Splitter.on(';').trimResults().withKeyValueSeparator("=>").split("a=>b ; c=>b")} will return * a mapping from {@code "a"} to {@code "b"} and {@code "c"} to {@code "b"}. * * <p>The returned map preserves the order of the entries from {@code sequence}. * * @throws IllegalArgumentException if the specified sequence does not split into valid map * entries, or if there are duplicate keys */ public Map<String, String> split(CharSequence sequence) { Map<String, String> map = new LinkedHashMap<>(); for (String entry : outerSplitter.split(sequence)) { Iterator<String> entryFields = entrySplitter.splittingIterator(entry); checkArgument(entryFields.hasNext(), INVALID_ENTRY_MESSAGE, entry); String key = entryFields.next(); checkArgument(!map.containsKey(key), "Duplicate key [%s] found.", key); checkArgument(entryFields.hasNext(), INVALID_ENTRY_MESSAGE, entry); String value = entryFields.next(); map.put(key, value); checkArgument(!entryFields.hasNext(), INVALID_ENTRY_MESSAGE, entry); } return Collections.unmodifiableMap(map); } }
/** * Returns the URLs in the class path specified by the {@code java.class.path} {@linkplain * System#getProperty system property}. */ @VisibleForTesting // TODO(b/65488446): Make this a public API. static ImmutableList<URL> parseJavaClassPath() { ImmutableList.Builder<URL> urls = ImmutableList.builder(); for (String entry : Splitter.on(PATH_SEPARATOR.value()).split(JAVA_CLASS_PATH.value())) { try { try { urls.add(new File(entry).toURI().toURL()); } catch (SecurityException e) { // File.toURI checks to see if the file is a directory urls.add(new URL("file", null, new File(entry).getAbsolutePath())); } } catch (MalformedURLException e) { logger.log(WARNING, "malformed classpath entry: " + entry, e); } } return urls.build(); }
/** * Creates a CacheBuilderSpec from a string. * * @param cacheBuilderSpecification the string form */ public static CacheBuilderSpec parse(String cacheBuilderSpecification) { CacheBuilderSpec spec = new CacheBuilderSpec(cacheBuilderSpecification); if (!cacheBuilderSpecification.isEmpty()) { for (String keyValuePair : KEYS_SPLITTER.split(cacheBuilderSpecification)) { List<String> keyAndValue = ImmutableList.copyOf(KEY_VALUE_SPLITTER.split(keyValuePair)); checkArgument(!keyAndValue.isEmpty(), "blank key-value pair"); checkArgument( keyAndValue.size() <= 2, "key-value pair %s with more than one equals sign", keyValuePair); // Find the ValueParser for the current key. String key = keyAndValue.get(0); ValueParser valueParser = VALUE_PARSERS.get(key); checkArgument(valueParser != null, "unknown key %s", key); String value = keyAndValue.size() == 1 ? null : keyAndValue.get(1); valueParser.parse(spec, key, value); } } return spec; }
Iterable<String> components = Splitter.on('/').omitEmptyStrings().split(pathname); List<String> path = new ArrayList<>();
/** * Converts a field mask from a Proto3 JSON string, that is splitting the paths along commas and * converting from camel case to snake case. */ public static FieldMask fromJsonString(String value) { Iterable<String> paths = Splitter.on(FIELD_PATH_SEPARATOR).split(value); FieldMask.Builder builder = FieldMask.newBuilder(); for (String path : paths) { if (path.isEmpty()) { continue; } builder.addPaths(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, path)); } return builder.build(); }
manifest.getMainAttributes().getValue(Attributes.Name.CLASS_PATH.toString()); if (classpathAttribute != null) { for (String path : CLASS_PATH_ATTRIBUTE_SEPARATOR.split(classpathAttribute)) { URL url; try {
/** Constructor used to implement {@link #from(String)}, and from subclasses. */ InternetDomainName(String name) { // Normalize: // * ASCII characters to lowercase // * All dot-like characters to '.' // * Strip trailing '.' name = Ascii.toLowerCase(DOTS_MATCHER.replaceFrom(name, '.')); if (name.endsWith(".")) { name = name.substring(0, name.length() - 1); } checkArgument(name.length() <= MAX_LENGTH, "Domain name too long: '%s':", name); this.name = name; this.parts = ImmutableList.copyOf(DOT_SPLITTER.split(name)); checkArgument(parts.size() <= MAX_PARTS, "Domain has too many parts: '%s'", name); checkArgument(validateSyntax(parts), "Not a valid domain name: '%s'", name); this.publicSuffixIndex = findSuffixOfType(Optional.<PublicSuffixType>absent()); this.registrySuffixIndex = findSuffixOfType(Optional.of(PublicSuffixType.REGISTRY)); }
ACCEPT_ENCODING_SPLITTER.split(new String(messageAcceptEncoding, GrpcUtil.US_ASCII)), compressor.getMessageEncoding())) {