/** * Trim the body of the script. * In this case, trim the whitespace from the start of the first element * and from the end of the last element. */ public void trimWhitespace() { List list = getScriptList(); int size = list.size(); if ( size > 0 ) { Script script = (Script) list.get(0); if ( script instanceof TextScript ) { TextScript textScript = (TextScript) script; textScript.trimStartWhitespace(); } if ( size > 1 ) { script = (Script) list.get(size - 1); if ( script instanceof TextScript ) { TextScript textScript = (TextScript) script; textScript.trimEndWhitespace(); } } } }
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 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()); } }