Sharkysoft home

lava.string
Class StringIndenter

java.lang.Object
  |
  +--lava.string.StringIndenter

public class StringIndenter
extends java.lang.Object

Indentation management.

Details: StringIndenter contains a variety of utility functions that will make dealing with indented strings and tabs in strings easier.

Since:
2000.01.29
Author:
Sharky

Field Summary
static int STANDARD_TAB_SIZE
          Standard tab size.
 
Constructor Summary
StringIndenter()
           
 
Method Summary
static java.lang.String convertTabs(java.lang.String s)
          Converts tabs to spaces.
static java.lang.String convertTabs(java.lang.String s, int ts)
          Converts tabs to spaces.
static int getIndent(java.lang.String s)
          Determines indent amount.
static int getIndent(java.lang.String s, int ts)
          Determines indent amount.
static java.lang.String makeIndentPrefix(int indent)
          Creates prefix for indenting.
static java.lang.String makeIndentPrefix(int indent, int tab_size)
          Creates prefix for indenting.
static java.lang.String setIndent(java.lang.String s, int i)
          Sets indent of string.
static java.lang.String setIndent(java.lang.String s, int i, int ts)
          Sets indent of string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STANDARD_TAB_SIZE

public static final int STANDARD_TAB_SIZE
Standard tab size.

Details: STANDARD_TAB_SIZE represents the traditional tab size of 8 spaces. It is defined here for convenience.

Constructor Detail

StringIndenter

public StringIndenter()
Method Detail

makeIndentPrefix

public static final java.lang.String makeIndentPrefix(int indent,
                                                      int tab_size)
Creates prefix for indenting.

Details: makeIndentPrefix creates a string of tabs and spaces suitable for prepending to a string you want to indent indent space. Calling this method is similar to a call to calling StringToolbox.repeat (' ', indent), except that consecutive blocks of tab_size spaces are replaced with tab ('\t') characters.

Parameters:
indent - the indent amount
tab_size - the tab size
Returns:
the indent prefix
Since:
2000.01.29

makeIndentPrefix

public static final java.lang.String makeIndentPrefix(int indent)
Creates prefix for indenting.

Details: makeIndentPrefix calls makeIndentPrefix (indent, STANDARD_TAB_SIZE) and returns the result. See makeIndentPrefix(int,int) for more details.

Parameters:
indent - the indent amount
Returns:
the indented string

getIndent

public static int getIndent(java.lang.String s,
                            int ts)
Determines indent amount.

Details: getIndent interprets the given string's leading spaces and tabs to determine the amount of indent. Tabs count as 1-tab_size spaces, depending on where the tabs occur in the string. This method recognizes only spaces and tabs. Scanning stops at all other characters, and the indent measured up to that point is returned.

Parameters:
s - the string
ts - the tab size
Returns:
the amount of indent
Since:
2000.01.29

getIndent

public static int getIndent(java.lang.String s)
Determines indent amount.

Details: getIndent calls getIndent (s, STANDARD_TAB_SIZE) and returns the result. See that method for more details.

Parameters:
s - the string
Returns:
the amount of indent
Since:
1998.11.05

setIndent

public static java.lang.String setIndent(java.lang.String s,
                                         int i,
                                         int ts)
Sets indent of string.

Details: setIndent trims s of spaces (on both sides) and then prefixes the string with a number of spaces and tabs sufficient to indent the string by i spaces. Tabs are assumed to be ts spaces. The re-indented string is returned.

Parameters:
s - the string
i - the amount of indent
ts - the tab size
Returns:
the re-indented string
Since:
1998.11.05

setIndent

public static java.lang.String setIndent(java.lang.String s,
                                         int i)
Sets indent of string.

Details: This method forwards to setIndent (s, i, STANDARD_TAB_SIZE). See that method for more details.

Parameters:
s - the string
i - the amount of indent
Returns:
the re-indented string
Since:
1998.11.05

convertTabs

public static java.lang.String convertTabs(java.lang.String s,
                                           int ts)
Converts tabs to spaces.

Details: convertTabs replaces tabs in a string with the correct number of spaces to maintain the string's original spacing, assuming a tab size of ts. Tabs occuring in the middle of a tab block are handled correctly.

Parameters:
s - the string to convert
ts - the tab size
Returns:
the converted string
Since:
1999.01.29

convertTabs

public static final java.lang.String convertTabs(java.lang.String s)
Converts tabs to spaces.

Details: This implementation of convertTabs forwards to convertTabs (s, STANDARD_TAB_SIZE). See convertTabs(String,int) for more details.

Parameters:
s - the string to convert
Returns:
the converted string
Since:
2000.01.29

Sharkysoft home