private static Segment removeEndingWhitespace(Segment segment){
  int toTrim=0;
  char currentChar=segment.setIndex(segment.getEndIndex() - 1);
  while ((currentChar == ' ' || currentChar == '\t') && currentChar != Segment.DONE) {
    toTrim++;
    currentChar=segment.previous();
  }
  String stringVal=segment.toString();
  String newStringVal=stringVal.substring(0,stringVal.length() - toTrim);
  return new Segment(newStringVal.toCharArray(),0,newStringVal.length());
}

private static Segment removeEndingWhitespace ( Segment segment ) { int toTrim = 0 ; char currentChar = segment . setIndex ( segment . getEndIndex ( ) - 1 ) ; while ( ( currentChar == ' ' || currentChar == '\t' ) && currentChar != Segment . DONE ) { toTrim ++ ; currentChar = segment . previous ( ) ; } String stringVal = segment . toString ( ) ; String newStringVal = stringVal . substring ( 0 , stringVal . length ( ) - toTrim ) ; return new Segment ( newStringVal . toCharArray ( ) , 0 , newStringVal . length ( ) ) ; }
removes any spaces or tabs from the end of the segment .
