@Test public void testSplit() { BracketDotKeySplitter splitter = new BracketDotKeySplitter(); assertIterator(splitter.split("a..bar:.c"), "a", "bar:", "c"); assertIterator(splitter.split(". "), " "); assertIterator(splitter.split("."), "."); assertIterator(splitter.split("foo"), "foo"); assertIterator(splitter.split("foo[\"bar\"]"), "foo", "bar"); assertIterator(splitter.split("foo[\"a.b.c\"]"), "foo", "a.b.c"); assertIterator(splitter.split("foo[\"bar\"].baz"), "foo", "bar", "baz"); assertIterator(splitter.split("a[\"b\"].c.d[\"e\"][\"f\"]"), "a", "b", "c", "d", "e", "f"); assertIterator(splitter.split("foo['bar']"), "foo", "bar"); assertIterator(splitter.split("foo['bar dot'][\"qux\"].me"), "foo", "bar dot", "qux", "me"); }
@Override public Iterator<String> split(String key) { if (key.equals(Strings.DOT) || key.equals(Strings.THIS)) { return Iterables.singletonIterator(key); } boolean stringLiteral = false; boolean separator = false; List<String> parts = new ArrayList<>(); StringBuilder buffer = new StringBuilder(); for (int i = 0; i < key.length(); i++) { if (isSeparator(key.charAt(i))) { if (!separator) { if (!stringLiteral) { if (buffer.length() > 0) { parts.add(buffer.toString()); buffer = new StringBuilder(); } separator = true; } else { buffer.append(key.charAt(i)); } } } else { if (Strings.isStringLiteralSeparator(key.charAt(i))) { stringLiteral = !stringLiteral; } else { buffer.append(key.charAt(i)); } separator = false; } } if (buffer.length() > 0) { parts.add(buffer.toString()); } return parts.iterator(); }
BracketDotKeySplitter extends AbstractConfigurationAware implements KeySplitter { @Override public Iterator<String> split(String key) { if (key.equals(Strings.DOT) || key.equals(Strings.THIS)) { return Iterables.singletonIterator(key); } boolean stringLiteral = false; boolean separator = false; List<String> parts = new ArrayList<>(); StringBuilder buffer = new StringBuilder(); for (int i = 0; i < key.length(); i++) { if (isSeparator(key.charAt(i))) { if (!separator) { if (!stringLiteral) { if (buffer.length() > 0) { parts.add(buffer.toString()); buffer = new StringBuilder(); } separator = true; } else { buffer.append(key.charAt(i)); } } } else { if (Strings.isStringLiteralSeparator(key.charAt(i))) { stringLiteral = !stringLiteral; } else { buffer.append(key.charAt(i)); } separator = false; } } if (buffer.length() > 0) { parts.add(buffer.toString()); } return parts.iterator(); } }
BracketDotKeySplitter extends AbstractConfigurationAware implements KeySplitter { @Override public Iterator<String> split(String key) { if (key.equals(Strings.DOT) || key.equals(Strings.THIS)) { return Iterables.singletonIterator(key); } boolean stringLiteral = false; boolean separator = false; List<String> parts = new ArrayList<>(); StringBuilder buffer = new StringBuilder(); for (int i = 0; i < key.length(); i++) { if (isSeparator(key.charAt(i))) { if (!separator) { if (!stringLiteral) { if (buffer.length() > 0) { parts.add(buffer.toString()); buffer = new StringBuilder(); } separator = true; } else { buffer.append(key.charAt(i)); } } } else { if (Strings.isStringLiteralSeparator(key.charAt(i))) { stringLiteral = !stringLiteral; } else { buffer.append(key.charAt(i)); } separator = false; } } if (buffer.length() > 0) { parts.add(buffer.toString()); } return parts.iterator(); }  }
BracketDotKeySplitter extends AbstractConfigurationAware implements KeySplitter { @Override public Iterator<String> split(String key) { if (key.equals(Strings.DOT) || key.equals(Strings.THIS)) { return Iterables.singletonIterator(key); } boolean stringLiteral = false; boolean separator = false; List<String> parts = new ArrayList<>(); StringBuilder buffer = new StringBuilder(); for (int i = 0; i < key.length(); i++) { if (isSeparator(key.charAt(i))) { if (!separator) { if (!stringLiteral) { if (buffer.length() > 0) { parts.add(buffer.toString()); buffer = new StringBuilder(); } separator = true; } else { buffer.append(key.charAt(i)); } } } else { if (Strings.isStringLiteralSeparator(key.charAt(i))) { stringLiteral = !stringLiteral; } else { buffer.append(key.charAt(i)); } separator = false; } } if (buffer.length() > 0) { parts.add(buffer.toString()); } return parts.iterator(); }  @Override Iterator<String> split(String key); }
BracketDotKeySplitter extends AbstractConfigurationAware implements KeySplitter { @Override public Iterator<String> split(String key) { if (key.equals(Strings.DOT) || key.equals(Strings.THIS)) { return Iterables.singletonIterator(key); } boolean stringLiteral = false; boolean separator = false; List<String> parts = new ArrayList<>(); StringBuilder buffer = new StringBuilder(); for (int i = 0; i < key.length(); i++) { if (isSeparator(key.charAt(i))) { if (!separator) { if (!stringLiteral) { if (buffer.length() > 0) { parts.add(buffer.toString()); buffer = new StringBuilder(); } separator = true; } else { buffer.append(key.charAt(i)); } } } else { if (Strings.isStringLiteralSeparator(key.charAt(i))) { stringLiteral = !stringLiteral; } else { buffer.append(key.charAt(i)); } separator = false; } } if (buffer.length() > 0) { parts.add(buffer.toString()); } return parts.iterator(); }  @Override Iterator<String> split(String key);  }