Home | History | Annotate | Download | only in base

Lines Matching refs:splitter

39  * <p>Here is the most basic example of {@code Splitter} usage: <pre>   {@code
41 * Splitter.on(',').split("foo,bar")}</pre>
46 * <p>By default {@code Splitter}'s behavior is very simplistic: <pre> {@code
48 * Splitter.on(',').split("foo,,bar, quux")}</pre>
51 * Notice that the splitter does not assume that you want empty strings removed,
55 * private static final Splitter MY_SPLITTER = Splitter.on(',')
66 * <p><b>Warning: splitter instances are always immutable</b>; a configuration
68 * is invoked on! You must store and use the new splitter instance returned by
73 * Splitter splitter = Splitter.on('/');
74 * splitter.trimResults(); // does nothing!
75 * return splitter.split("wrong / wrong / wrong");}</pre>
77 * The separator recognized by the splitter does not have to be a single
93 public final class Splitter {
98 private Splitter(Strategy strategy) {
102 private Splitter(Strategy strategy, boolean omitEmptyStrings,
110 * Returns a splitter that uses the given single-character separator. For
111 * example, {@code Splitter.on(',').split("foo,,bar")} returns an iterable
115 * @return a splitter, with default settings, that recognizes that separator
117 public static Splitter on(char separator) {
122 * Returns a splitter that considers any single character matched by the
124 * Splitter.on(CharMatcher.anyOf(";,")).split("foo,;bar,quux")} returns an
129 * @return a splitter, with default settings, that uses this matcher
131 public static Splitter on(final CharMatcher separatorMatcher) {
134 return new Splitter(new Strategy() {
136 Splitter splitter, final CharSequence toSplit) {
137 return new SplittingIterator(splitter, toSplit) {
151 * Returns a splitter that uses the given fixed string as a separator. For
152 * example, {@code Splitter.on(", ").split("foo, bar, baz,qux")} returns an
156 * @return a splitter, with default settings, that recognizes that separator
158 public static Splitter on(final String separator) {
162 return new Splitter(new Strategy() {
164 Splitter splitter, CharSequence toSplit) {
165 return new SplittingIterator(splitter, toSplit) {
191 * Returns a splitter that considers any subsequence matching {@code
193 * Splitter.on(Pattern.compile("\r?\n")).split(entireFile)} splits a string
198 * @return a splitter, with default settings, that uses this pattern
202 public static Splitter on(final Pattern separatorPattern) {
207 return new Splitter(new Strategy() {
209 final Splitter splitter, CharSequence toSplit) {
211 return new SplittingIterator(splitter, toSplit) {
225 * Returns a splitter that considers any subsequence matching a given
227 * Splitter.onPattern("\r?\n").split(entireFile)} splits a string into lines
229 * equivalent to {@code Splitter.on(Pattern.compile(pattern))}.
233 * @return a splitter, with default settings, that uses this pattern
239 public static Splitter onPattern(String separatorPattern) {
244 * Returns a splitter that divides strings into pieces of the given length.
245 * For example, {@code Splitter.atEach(2).split("abcde")} returns an
250 * @return a splitter, with default settings, that can split into fixed sized
253 public static Splitter fixedLength(final int length) {
256 return new Splitter(new Strategy() {
258 final Splitter splitter, CharSequence toSplit) {
259 return new SplittingIterator(splitter, toSplit) {
274 * Returns a splitter that behaves equivalently to {@code this} splitter, but
276 * Splitter.on(',').omitEmptyStrings().split(",a,,,b,c,,")} returns an
280 * splitter, that splitter always trims results first before checking for
282 * Splitter.on(':').omitEmptyStrings().trimResults().split(": : : ")} returns
289 * @return a splitter with the desired configuration
291 public Splitter omitEmptyStrings() {
292 return new Splitter(strategy, true, trimmer);
296 * Returns a splitter that behaves equivalently to {@code this} splitter, but
300 * Splitter.on(',').trimResults().split(" a, b ,c ")} returns an iterable
303 * @return a splitter with the desired configuration
305 public Splitter trimResults() {
310 * Returns a splitter that behaves equivalently to {@code this} splitter, but
313 * Splitter.on(',').trimResults(CharMatcher.is('_')).split("_a ,_b_ ,c__")}
318 * @return a splitter with the desired configuration
320 public Splitter trimResults(CharMatcher trimmer) {
322 return new Splitter(strategy, omitEmptyStrings, trimmer);
336 return strategy.iterator(Splitter.this, sequence);
342 Iterator<String> iterator(Splitter splitter, CharSequence toSplit);
366 protected SplittingIterator(Splitter splitter, CharSequence toSplit) {
367 this.trimmer = splitter.trimmer;
368 this.omitEmptyStrings = splitter.omitEmptyStrings;