@Test public void testTrim() { String string1 = " 12 34 "; Span span1 = new Span(0, string1.length()); Assert.assertEquals("12 34", span1.trim(string1).getCoveredText(string1)); }
public Span trim(CharSequence text) { int newStartOffset = getStart(); for (int i = getStart(); i < getEnd() && StringUtil.isWhitespace(text.charAt(i)); i++) { newStartOffset++; } int newEndOffset = getEnd(); for (int i = getEnd(); i > getStart() && StringUtil.isWhitespace(text.charAt(i - 1)); i--) { newEndOffset--; } if (newStartOffset == getStart() && newEndOffset == getEnd()) { return this; } else if (newStartOffset > newEndOffset) { return new Span(getStart(), getStart(), getType()); } else { return new Span(newStartOffset, newEndOffset, getType()); } }
Span implements Comparable<Span>, Serializable { public Span trim(CharSequence text) { int newStartOffset = getStart(); for (int i = getStart(); i < getEnd() && StringUtil.isWhitespace(text.charAt(i)); i++) { newStartOffset++; } int newEndOffset = getEnd(); for (int i = getEnd(); i > getStart() && StringUtil.isWhitespace(text.charAt(i - 1)); i--) { newEndOffset--; } if (newStartOffset == getStart() && newEndOffset == getEnd()) { return this; } else if (newStartOffset > newEndOffset) { return new Span(getStart(), getStart(), getType()); } else { return new Span(newStartOffset, newEndOffset, getType()); } } }
Span implements Comparable<Span>, Serializable { public Span trim(CharSequence text) { int newStartOffset = getStart(); for (int i = getStart(); i < getEnd() && StringUtil.isWhitespace(text.charAt(i)); i++) { newStartOffset++; } int newEndOffset = getEnd(); for (int i = getEnd(); i > getStart() && StringUtil.isWhitespace(text.charAt(i - 1)); i--) { newEndOffset--; } if (newStartOffset == getStart() && newEndOffset == getEnd()) { return this; } else if (newStartOffset > newEndOffset) { return new Span(getStart(), getStart(), getType()); } else { return new Span(newStartOffset, newEndOffset, getType()); } } Span(int s, int e, String type);  Span(int s, int e, String type, double prob);  Span(int s, int e);  Span(int s, int e, double prob);  Span(Span span, int offset);  Span(Span span, double prob); }
Span implements Comparable<Span>, Serializable { public Span trim(CharSequence text) { int newStartOffset = getStart(); for (int i = getStart(); i < getEnd() && StringUtil.isWhitespace(text.charAt(i)); i++) { newStartOffset++; } int newEndOffset = getEnd(); for (int i = getEnd(); i > getStart() && StringUtil.isWhitespace(text.charAt(i - 1)); i--) { newEndOffset--; } if (newStartOffset == getStart() && newEndOffset == getEnd()) { return this; } else if (newStartOffset > newEndOffset) { return new Span(getStart(), getStart(), getType()); } else { return new Span(newStartOffset, newEndOffset, getType()); } } Span(int s, int e, String type);  Span(int s, int e, String type, double prob);  Span(int s, int e);  Span(int s, int e, double prob);  Span(Span span, int offset);  Span(Span span, double prob); int getStart(); int getEnd(); String getType(); int length(); boolean contains(Span s); boolean contains(int index); boolean startsWith(Span s); boolean intersects(Span s); boolean crosses(Span s); CharSequence getCoveredText(CharSequence text); Span trim(CharSequence text); int compareTo(Span s); @Override int hashCode(); @Override boolean equals(Object o); @Override String toString(); static String[] spansToStrings(Span[] spans, CharSequence s); static String[] spansToStrings(Span[] spans, String[] tokens); double getProb(); }
Span implements Comparable<Span>, Serializable { public Span trim(CharSequence text) { int newStartOffset = getStart(); for (int i = getStart(); i < getEnd() && StringUtil.isWhitespace(text.charAt(i)); i++) { newStartOffset++; } int newEndOffset = getEnd(); for (int i = getEnd(); i > getStart() && StringUtil.isWhitespace(text.charAt(i - 1)); i--) { newEndOffset--; } if (newStartOffset == getStart() && newEndOffset == getEnd()) { return this; } else if (newStartOffset > newEndOffset) { return new Span(getStart(), getStart(), getType()); } else { return new Span(newStartOffset, newEndOffset, getType()); } } Span(int s, int e, String type);  Span(int s, int e, String type, double prob);  Span(int s, int e);  Span(int s, int e, double prob);  Span(Span span, int offset);  Span(Span span, double prob); int getStart(); int getEnd(); String getType(); int length(); boolean contains(Span s); boolean contains(int index); boolean startsWith(Span s); boolean intersects(Span s); boolean crosses(Span s); CharSequence getCoveredText(CharSequence text); Span trim(CharSequence text); int compareTo(Span s); @Override int hashCode(); @Override boolean equals(Object o); @Override String toString(); static String[] spansToStrings(Span[] spans, CharSequence s); static String[] spansToStrings(Span[] spans, String[] tokens); double getProb();  }