public boolean removeToPreviousSeparator ( int offset , int length , IXtextDocument document , String separator ) throws BadLocationException { // Skip spaces before the identifier until the separator int index = offset - 1 ; char c = document . getChar ( index ) ; while ( Character . isWhitespace ( c ) ) { index -- ; c = document . getChar ( index ) ; } // Test if it previous non-space character is the separator final boolean foundSeparator = document . getChar ( index ) == separator . charAt ( 0 ) ; if ( foundSeparator ) { index -- ; c = document . getChar ( index ) ; // Skip the previous spaces while ( Character . isWhitespace ( c ) ) { index -- ; c = document . getChar ( index ) ; } final int delta = offset - index - 1 ; document . replace ( index + 1 , length + delta , "" ) ; //$NON-NLS-1$ } return foundSeparator ; }
Remove the portion of text and the whitespaces before the text until the given separator .