/* XBN Java: Generically useful, non-GUI Java code. http://sourceforge.net/projects/xbnjava Copyright (C) 1997-2003, Jeff Epstein All rights reserved. Modifications: No Redistribution in binary form, with or without modifications, are permitted provided that the following conditions are met: * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * If modifications are made to source code then this license should indicate that fact in the "Modifications" section above. * Neither the author, nor the contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. [NOTE: This license contains NO advertising clause.] */ package xbn.string; /**

A StringOrBuffer that wraps around a java.lang.String. See String.

Source code:  SOBString.java.  Unit tests:  See the unit tests for StringOrBuffer.

@version 0.9b @author Jeff Epstein, http://sourceforge.net/projects/xbnjava. **/ public class SOBString extends StringOrBuffer { private String s = null; /**

Create an SOBString.

@param s_tr May not be null. **/ public SOBString(String s_tr) { throwAXIfNull(s_tr, "s_tr", sCNSTR); s = s_tr; } /**

Get the String.

@return The internally-held String. **/ public final String getString() { return s; } /** @return true **/ public final boolean isString() { return true; } /**

Get some information about this SOBString.

@return getString().toString() **/ public final String toString() { return getString().toString(); } /** @return getString().length() **/ public final int length() { return getString().length(); } /** @return getString().trim()rr **/ public final String getTrimmed() { return getString().trim(); } /**

Trim whitespace from the value of this StringOrBuffer.

Sets the internally-held string to [internally-held string].trim()

**/ public final void trim() { s = s.trim(); } /** @return getString().charAt(i_dx) **/ public final char charAt(int i_dx) { return getString().charAt(i_dx); } /**

Append a string onto the end (right).

This executes
   [The internal string] += s_toAppend

**/ public final void append(String s_toAppend) { s += s_toAppend; } /**

Append a string to the start.

Equal to [The internal string] = [The internal string] + s_toAppend

**/ public final void appendToLeft(String s_toAppend) { s = s_toAppend + s; } /**

Insert a string.

Equal to [The internal string] = [The internal string].substring(0, i_dx) + s_toInsert + [The internal string].substring(i_dx, s.length())

**/ public final void insert(int i_dx, String s_toInsert) { s = s.substring(0, i_dx) + s_toInsert + s.substring(i_dx, s.length()); } /**

Append a character onto the end (right).

This executes
   [The internal string] += c_toAppend

**/ public final void append(char c_toAppend) { s += c_toAppend; } /**

Append a character to the start.

Equal to [The internal string] = [The internal string] + c_toAppend

**/ public final void appendToLeft(char c_toAppend) { s = c_toAppend + s; } /**

Insert a character.

Equal to [The internal string] = [The internal string].substring(0, i_dx) + c_toInsert + [The internal string].substring(i_dx, s.length()())

**/ public final void insert(int i_dx, char c_toInsert) { s = s.substring(0, i_dx) + c_toInsert + s.substring(i_dx, s.length()); } /**

Delete a character.

Equal to [The internal string] = [The internal string].substring(0, i_dx) + [The internal string].substring((i_dx + 1), s.length()())

**/ public final void deleteCharAt(int i_dx) { s = s.substring(0, i_dx) + s.substring((i_dx + 1), s.length()); } /**

Delete a range of characters.

Equal to [The internal string] = [The internal string].substring(0, i_dx) + [The internal string].substring(i_idxAfterRight, s.length()())

**/ public final void delete(int i_idxLeft, int i_idxAfterRight) { s = s.substring(0, i_idxLeft) + s.substring(i_idxAfterRight, s.length()); } //OVERRIDES sob public final void setLength(int i_newLength) { if(i_newLength >= length()) { StringBuffer sb = new StringBuffer(sES); sb.setLength(i_newLength - length()); s += sb.toString(); } else { s = s.substring(0, i_newLength); } } /** @return getString().startsWith(s_toSearchFor) **/ public final boolean startsWith(String s_toSearchFor) { return getString().startsWith(s_toSearchFor); } /** @return getString().endsWith(s_toSearchFor) **/ public final boolean endsWith(String s_toSearchFor) { return getString().endsWith(s_toSearchFor); } /** @return getString().substring(i_idxLeft) **/ public final String substring(int i_idxLeft) { return getString().substring(i_idxLeft); } /** @return getString().substring(i_idxLeft, i_idxAfterRight) **/ public final String substring(int i_idxLeft, int i_idxAfterRight) { return getString().substring(i_idxLeft, i_idxAfterRight); } }