List of usage examples for com.google.common.base CharMatcher countIn
public int countIn(CharSequence sequence)
From source file:io.v.impl.google.naming.EndpointImpl.java
private static String escapeString(String s) { CharMatcher matcher = CharMatcher.anyOf("%@"); int count = matcher.countIn(s); if (count == 0) { return s; }//from w w w . j a va 2 s .com char[] escaped = new char[s.length() + 2 * count]; for (int i = 0; i < s.length();) { char x = s.charAt(i); if (x == '%') { escaped[i++] = '%'; escaped[i++] = '2'; escaped[i++] = '5'; } else if (x == '@') { escaped[i++] = '%'; escaped[i++] = '4'; escaped[i++] = '0'; } else { escaped[i++] = x; } } return new String(escaped); }
From source file:org.zanata.webtrans.shared.validation.action.TabValidation.java
@Override public List<String> doValidate(String source, String target) { ArrayList<String> errors = new ArrayList<>(); CharMatcher tabs = CharMatcher.is('\t'); int sourceTabs = tabs.countIn(source); int targetTabs = tabs.countIn(target); if (sourceTabs > targetTabs) { errors.add(getMessages().targetHasFewerTabs(sourceTabs, targetTabs)); } else if (targetTabs > sourceTabs) { errors.add(getMessages().targetHasMoreTabs(sourceTabs, targetTabs)); }/*from ww w .j av a 2s . co m*/ return errors; }
From source file:org.locationtech.geogig.storage.memory.HeapConfigDatabase.java
private Map<String, String> getAllSection(ConcurrentMap<String, String> config, String section) { checkNotNull(section);/*from w w w . ja va 2 s . c om*/ CharMatcher matcher = CharMatcher.is('.'); final int numSections = 1 + matcher.countIn(section); final String prefix = section + "."; Map<String, String> res = new HashMap<>(); config.forEach((k, v) -> { if (k.startsWith(prefix) && numSections == matcher.countIn(k)) { res.put(k.substring(prefix.length()), v); } }); return res; }
From source file:org.locationtech.geogig.storage.memory.HeapConfigDatabase.java
private List<String> getAllSubSection(ConcurrentMap<String, String> config, String section) { checkNotNull(section);/*from w w w.ja v a2s . c o m*/ CharMatcher matcher = CharMatcher.is('.'); final int numSections = 2 + matcher.countIn(section); // one separator for subsection and // one for the leaf key final String prefix = section + "."; Set<String> subsections = new TreeSet<>(); config.forEach((k, v) -> { if (k.startsWith(prefix) && matcher.countIn(k) >= numSections) { int keyIndex = k.lastIndexOf('.'); String subsection = k.substring(prefix.length(), keyIndex); subsections.add(subsection); } }); return new ArrayList<>(subsections); }