/** * Trim the body of the script. * In this case, trim all elements, removing any that are empty text. */ public void trimWhitespace() { List list = getScriptList(); for ( int i = list.size() - 1; i >= 0; i-- ) { Script script = (Script) list.get(i); if ( script instanceof TextScript ) { TextScript textScript = (TextScript) script; String text = textScript.getText(); text = text.trim(); if ( text.length() == 0 ) { list.remove(i); } } } } }
/** * Trim the body of the script. * In this case, trim all elements, removing any that are empty text. */ public void trimWhitespace() { List list = getScriptList(); for ( int i = list.size() - 1; i >= 0; i-- ) { Script script = (Script) list.get(i); if ( script instanceof TextScript ) { TextScript textScript = (TextScript) script; String text = textScript.getText(); text = text.trim(); if ( text.length() == 0 ) { list.remove(i); } } } } }
/** * Trim the body of the script. * In this case, trim all elements, removing any that are empty text. */ public void trimWhitespace() { List list = getScriptList(); for ( int i = list.size() - 1; i >= 0; i-- ) { Script script = (Script) list.get(i); if ( script instanceof TextScript ) { TextScript textScript = (TextScript) script; String text = textScript.getText(); text = text.trim(); if ( text.length() == 0 ) { list.remove(i); } } } } }
/** * Trim the body of the script. * In this case, trim all elements, removing any that are empty text. */ public void trimWhitespace() { List list = getScriptList(); for ( int i = list.size() - 1; i >= 0; i-- ) { Script script = (Script) list.get(i); if ( script instanceof TextScript ) { TextScript textScript = (TextScript) script; String text = textScript.getText(); text = text.trim(); if ( text.length() == 0 ) { list.remove(i); } else { textScript.setText(text); } } } } }
public void testTrimEnd() throws Exception { TextScript script = new TextScript( " foo " ); script.trimEndWhitespace(); assertEquals( " foo", script.getText() ); script = new TextScript( " foo " ); script.trimEndWhitespace(); assertEquals( " foo", script.getText() ); script = new TextScript( "foo" ); script.trimEndWhitespace(); assertEquals( "foo", script.getText() ); } }
public void testTrimStart() throws Exception { TextScript script = new TextScript( " foo " ); script.trimStartWhitespace(); assertEquals( "foo ", script.getText() ); script = new TextScript( " foo " ); script.trimStartWhitespace(); assertEquals( "foo ", script.getText() ); script = new TextScript( "foo" ); script.trimStartWhitespace(); assertEquals( "foo", script.getText() ); }
public void testTrim() throws Exception { TextScript script = new TextScript( " foo " ); script.trimWhitespace(); assertEquals( "foo", script.getText() ); script = new TextScript( " foo " ); script.trimWhitespace(); assertEquals( "foo", script.getText() ); script = new TextScript( "foo" ); script.trimWhitespace(); assertEquals( "foo", script.getText() ); }
public void testTrimEndWhitespace() throws Exception { TextScript textScript = new TextScript(" "); textScript.trimEndWhitespace(); assertEquals("", textScript.getText()); textScript = new TextScript(""); textScript.trimEndWhitespace(); assertEquals("", textScript.getText()); textScript = new TextScript(" foo "); textScript.trimEndWhitespace(); assertEquals(" foo", textScript.getText()); textScript = new TextScript("foo"); textScript.trimEndWhitespace(); assertEquals("foo", textScript.getText()); }
public void testTrimStartWhitespace() throws Exception { TextScript textScript = new TextScript(" "); textScript.trimStartWhitespace(); assertEquals("", textScript.getText()); textScript = new TextScript(""); textScript.trimStartWhitespace(); assertEquals("", textScript.getText()); textScript = new TextScript(" foo "); textScript.trimStartWhitespace(); assertEquals("foo ", textScript.getText()); textScript = new TextScript("foo"); textScript.trimStartWhitespace(); assertEquals("foo", textScript.getText()); } }