avrora.util
Class StringUtil

java.lang.Object
  extended byavrora.util.StringUtil

public class StringUtil
extends java.lang.Object

The StringUtil class implements several useful functions for dealing with strings such as parsing pieces of syntax, formatting, etc.


Field Summary
static java.lang.String COMMA
           
static java.lang.String COMMA_SPACE
           
static int DAYS
           
static int[] DAYSECS
           
static int[] DENOM
           
static java.lang.String[] EMPTY_STRING_ARRAY
           
static char[] HEX_CHARS
           
static int HOURS
           
static int ID_LENGTH
           
static java.lang.String LPAREN
           
static int MILLIS
           
static long MILLISECS_PER_DAY
           
static long MILLISECS_PER_HOUR
           
static long MILLISECS_PER_MIN
           
static long MILLISECS_PER_SEC
           
static int MINS
           
static java.lang.String QUOTE
           
static boolean REPORT_SECONDS
           
static java.lang.String RPAREN
           
static int SECONDS_PRECISION
           
static int SECS
           
static int SECS_PER_DAY
           
static int SECS_PER_HOUR
           
static int SECS_PER_MIN
           
static java.lang.String SQUOTE
           
static int TIME_LENGTH
           
 
Constructor Summary
StringUtil()
           
 
Method Summary
static java.lang.String addrToString(int address)
          The addToString() method converts a numerical address (represented as a signed 32-bit integer) and converts it to a string in the format 0xXXXX where 'X' represents a hexadecimal character.
static char alpha(int num)
           
static java.lang.String commalist(java.util.List l)
           
static java.lang.String commalist(java.lang.Object o1, java.lang.Object o2)
           
static java.lang.String commalist(java.lang.Object o1, java.lang.Object o2, java.lang.Object o3)
           
static java.lang.String commalist(java.lang.Object o1, java.lang.Object o2, java.lang.Object o3, java.lang.Object o4)
           
static java.lang.String dup(char c, int len)
          The dup() method takes a character and a count and returns a string where that character has been duplicated the specified number of times.
static java.lang.String embed(java.lang.Object s)
          The embed() method simply adds parentheses around a string.
static java.lang.String embed(java.lang.Object lead, java.lang.Object arg)
           
static java.lang.String embed(java.lang.Object lead, java.lang.Object arg1, java.lang.Object arg2)
           
static java.lang.String embed(java.lang.Object lead, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3)
           
static java.lang.String embed(java.lang.Object lead, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3, java.lang.Object arg4)
           
static char evaluateCharLiteral(java.lang.String literal)
           
static int evaluateIntegerLiteral(java.lang.String val)
           
static java.lang.String evaluateStringLiteral(java.lang.String literal)
           
static java.lang.String getIDTimeString(Simulator s)
           
static void getIDTimeString(java.lang.StringBuffer buf, Simulator s)
           
static int hexValueOf(char c)
           
static java.lang.String interval(int low, int high)
           
static boolean isHexDigit(char c)
          The isHexDigit() method tests whether the given character corresponds to one of the characters used in the hexadecimal representation (i.e. is '0'-'9' or 'a'-'b', case insensitive.
static boolean isOctalDigit(char c)
           
static java.lang.String leftJustify(float v, int width)
          The leftJustify() method pads a string to a specified length by adding spaces on the right, thus justifying the string to the left margin.
static java.lang.String leftJustify(long v, int width)
          The leftJustify() method pads a string to a specified length by adding spaces on the right, thus justifying the string to the left margin.
static java.lang.String leftJustify(java.lang.String s, int width)
          The leftJustify() method pads a string to a specified length by adding spaces on the right, thus justifying the string to the left margin.
static java.lang.String linelist(java.util.List l)
           
static void linelist(java.lang.StringBuffer buf, java.util.List l)
           
static java.lang.String makeParagraphs(java.lang.String s, int leftJust, int indent, int width)
           
static long[] millisToDays(long millis)
          The millisToDays() method converts the given milliseconds into a breakdown of days, hours, minutes, seconds, and milliseconds, returning a long array where the expr 0 corresponds to days, expr 1 corresponds to hours, etc.
static java.lang.String milliToSecs(long millis)
           
static int octalValueOf(char c)
           
static char peek(java.text.CharacterIterator i)
           
static boolean peekAndEat(java.text.CharacterIterator i, char c)
           
static java.lang.String qembed(java.lang.String s1, java.lang.String s2, java.lang.String s3)
           
static java.lang.String quote(java.lang.Object s)
          The quote() method simply adds double quotes around a string.
static java.lang.String readDecimalString(java.text.CharacterIterator i, int max_chars)
           
static int readDecimalValue(java.text.CharacterIterator i, int max_chars)
           
static java.lang.String readDotIdentifier(java.text.CharacterIterator i)
           
static int readHexValue(java.text.CharacterIterator i, int max_chars)
           
static java.lang.String readIdentifier(java.text.CharacterIterator i)
           
static int readOctalValue(java.text.CharacterIterator i, int max_chars)
           
static java.lang.String rightJustify(float v, int width)
          The rightJustify() method pads a string to a specified length by adding spaces on the left, thus justifying the string to the right margin.
static java.lang.String rightJustify(long v, int width)
          The rightJustify() method pads a string to a specified length by adding spaces on the left, thus justifying the string to the right margin.
static java.lang.String rightJustify(java.lang.String s, int width)
          The rightJustify() method pads a string to a specified length by adding spaces on the left, thus justifying the string to the right margin.
static void skipWhiteSpace(java.text.CharacterIterator i)
           
static java.lang.String splice(java.lang.String[] a, java.lang.String[] b)
           
static java.lang.String squote(char c)
          The squote() method simply adds single quotes around a character.
static java.lang.String to0xHex(long value, int width)
           
static java.lang.String toBin(long value, int width)
           
static char toBit(boolean f)
           
static java.lang.String toDecimal(long val, int places)
           
static java.lang.String toFixedFloat(float fval, int places)
           
static java.lang.String toHex(long value, int width)
          The toHex() converts the specified long value into a hexadecimal string of the given with.
static void toHex(java.lang.StringBuffer buf, long value, int width)
           
static java.lang.String toIDTimeString(int id, Clock clk)
           
static void toIDTimeString(java.lang.StringBuffer buf, int id, Clock clk)
           
static java.lang.String toMultirepString(int value, int bits)
           
static java.lang.String trimquotes(java.lang.String s)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HEX_CHARS

public static final char[] HEX_CHARS

QUOTE

public static final java.lang.String QUOTE

SQUOTE

public static final java.lang.String SQUOTE

LPAREN

public static final java.lang.String LPAREN

RPAREN

public static final java.lang.String RPAREN

COMMA

public static final java.lang.String COMMA

COMMA_SPACE

public static final java.lang.String COMMA_SPACE

EMPTY_STRING_ARRAY

public static final java.lang.String[] EMPTY_STRING_ARRAY

DENOM

public static final int[] DENOM

DAYSECS

public static final int[] DAYSECS

SECS_PER_DAY

public static final int SECS_PER_DAY
See Also:
Constant Field Values

SECS_PER_HOUR

public static final int SECS_PER_HOUR
See Also:
Constant Field Values

SECS_PER_MIN

public static final int SECS_PER_MIN
See Also:
Constant Field Values

MILLISECS_PER_DAY

public static final long MILLISECS_PER_DAY
See Also:
Constant Field Values

MILLISECS_PER_HOUR

public static final long MILLISECS_PER_HOUR
See Also:
Constant Field Values

MILLISECS_PER_MIN

public static final long MILLISECS_PER_MIN
See Also:
Constant Field Values

MILLISECS_PER_SEC

public static final long MILLISECS_PER_SEC
See Also:
Constant Field Values

DAYS

public static final int DAYS
See Also:
Constant Field Values

HOURS

public static final int HOURS
See Also:
Constant Field Values

MINS

public static final int MINS
See Also:
Constant Field Values

SECS

public static final int SECS
See Also:
Constant Field Values

MILLIS

public static final int MILLIS
See Also:
Constant Field Values

ID_LENGTH

public static int ID_LENGTH

TIME_LENGTH

public static int TIME_LENGTH

REPORT_SECONDS

public static boolean REPORT_SECONDS

SECONDS_PRECISION

public static int SECONDS_PRECISION
Constructor Detail

StringUtil

public StringUtil()
Method Detail

addrToString

public static java.lang.String addrToString(int address)
The addToString() method converts a numerical address (represented as a signed 32-bit integer) and converts it to a string in the format 0xXXXX where 'X' represents a hexadecimal character. The address is assumed to fit in 4 hexadecimal characters. If it does not, the string will have as many characters as necessary (max 8) to represent the address.

Parameters:
address - the address value as an integer
Returns:
a standard string representation of the address

readIdentifier

public static java.lang.String readIdentifier(java.text.CharacterIterator i)

readDotIdentifier

public static java.lang.String readDotIdentifier(java.text.CharacterIterator i)

readHexValue

public static int readHexValue(java.text.CharacterIterator i,
                               int max_chars)

readOctalValue

public static int readOctalValue(java.text.CharacterIterator i,
                                 int max_chars)

readDecimalValue

public static int readDecimalValue(java.text.CharacterIterator i,
                                   int max_chars)

readDecimalString

public static java.lang.String readDecimalString(java.text.CharacterIterator i,
                                                 int max_chars)

skipWhiteSpace

public static void skipWhiteSpace(java.text.CharacterIterator i)

peek

public static char peek(java.text.CharacterIterator i)

peekAndEat

public static boolean peekAndEat(java.text.CharacterIterator i,
                                 char c)

isHexDigit

public static boolean isHexDigit(char c)
The isHexDigit() method tests whether the given character corresponds to one of the characters used in the hexadecimal representation (i.e. is '0'-'9' or 'a'-'b', case insensitive. This method is generally used in parsing and lexing of input.

Parameters:
c - the character to test
Returns:
true if this character is a hexadecimal digit; false otherwise

hexValueOf

public static int hexValueOf(char c)

octalValueOf

public static int octalValueOf(char c)

isOctalDigit

public static boolean isOctalDigit(char c)

rightJustify

public static java.lang.String rightJustify(long v,
                                            int width)
The rightJustify() method pads a string to a specified length by adding spaces on the left, thus justifying the string to the right margin. This is extremely useful in generating columnar output in textual tables.

Parameters:
v - a long value to convert to a string and justify
width - the number of characters to pad the string to
Returns:
a string representation of the input, padded on the left with spaces to achieve the desired length.

rightJustify

public static java.lang.String rightJustify(float v,
                                            int width)
The rightJustify() method pads a string to a specified length by adding spaces on the left, thus justifying the string to the right margin. This is extremely useful in generating columnar output in textual tables.

Parameters:
v - a floating point value to convert to a string and justify
width - the number of characters to pad the string to
Returns:
a string representation of the input, padded on the left with spaces to achieve the desired length.

rightJustify

public static java.lang.String rightJustify(java.lang.String s,
                                            int width)
The rightJustify() method pads a string to a specified length by adding spaces on the left, thus justifying the string to the right margin. This is extremely useful in generating columnar output in textual tables.

Parameters:
s - a string to justify
width - the number of characters to pad the string to
Returns:
a string representation of the input, padded on the left with spaces to achieve the desired length.

leftJustify

public static java.lang.String leftJustify(long v,
                                           int width)
The leftJustify() method pads a string to a specified length by adding spaces on the right, thus justifying the string to the left margin. This is extremely useful in generating columnar output in textual tables.

Parameters:
v - a long value to convert to a string and justify
width - the number of characters to pad the string to
Returns:
a string representation of the input, padded on the right with spaces to achieve the desired length.

leftJustify

public static java.lang.String leftJustify(float v,
                                           int width)
The leftJustify() method pads a string to a specified length by adding spaces on the right, thus justifying the string to the left margin. This is extremely useful in generating columnar output in textual tables.

Parameters:
v - a floating point value to convert to a string and justify
width - the number of characters to pad the string to
Returns:
a string representation of the input, padded on the right with spaces to achieve the desired length.

leftJustify

public static java.lang.String leftJustify(java.lang.String s,
                                           int width)
The leftJustify() method pads a string to a specified length by adding spaces on the right, thus justifying the string to the left margin. This is extremely useful in generating columnar output in textual tables.

Parameters:
s - a string to justify
width - the number of characters to pad the string to
Returns:
a string representation of the input, padded on the right with spaces to achieve the desired length.

milliToSecs

public static java.lang.String milliToSecs(long millis)

millisToDays

public static long[] millisToDays(long millis)
The millisToDays() method converts the given milliseconds into a breakdown of days, hours, minutes, seconds, and milliseconds, returning a long array where the expr 0 corresponds to days, expr 1 corresponds to hours, etc.

Parameters:
millis - the number of milliseconds to convert
Returns:
the breakdown of milliseconds into days, hours, minutes, seconds, and milliseconds in an array, with most significant units first

toHex

public static java.lang.String toHex(long value,
                                     int width)
The toHex() converts the specified long value into a hexadecimal string of the given with. The value will be padded on the left with zero values to achieve the desired with.

Parameters:
value - the long value to convert to a string
width - the desired length of the string
Returns:
a hexadecimal string representation of the given value, padded on the left with zeroes to the length specified

to0xHex

public static java.lang.String to0xHex(long value,
                                       int width)

toBin

public static java.lang.String toBin(long value,
                                     int width)

toHex

public static void toHex(java.lang.StringBuffer buf,
                         long value,
                         int width)

splice

public static java.lang.String splice(java.lang.String[] a,
                                      java.lang.String[] b)

quote

public static java.lang.String quote(java.lang.Object s)
The quote() method simply adds double quotes around a string.

Parameters:
s - the string to add double quotes to
Returns:
a new string that is the result of concatenating the double quote character, the specified string, and another double quote character in sequence

squote

public static java.lang.String squote(char c)
The squote() method simply adds single quotes around a character.

Parameters:
c - the character to add double quotes to
Returns:
a new string that is the result of concatenating the double quote character, the specified string, and another double quote character in sequence

embed

public static java.lang.String embed(java.lang.Object s)
The embed() method simply adds parentheses around a string.

Parameters:
s - the string to add parentheses to
Returns:
a new string that is the result of concatenating the parenthesis character, the specified string, and another parenthesis character in sequence

embed

public static java.lang.String embed(java.lang.Object lead,
                                     java.lang.Object arg)

embed

public static java.lang.String embed(java.lang.Object lead,
                                     java.lang.Object arg1,
                                     java.lang.Object arg2)

embed

public static java.lang.String embed(java.lang.Object lead,
                                     java.lang.Object arg1,
                                     java.lang.Object arg2,
                                     java.lang.Object arg3)

embed

public static java.lang.String embed(java.lang.Object lead,
                                     java.lang.Object arg1,
                                     java.lang.Object arg2,
                                     java.lang.Object arg3,
                                     java.lang.Object arg4)

commalist

public static java.lang.String commalist(java.util.List l)

linelist

public static java.lang.String linelist(java.util.List l)

linelist

public static void linelist(java.lang.StringBuffer buf,
                            java.util.List l)

commalist

public static java.lang.String commalist(java.lang.Object o1,
                                         java.lang.Object o2)

commalist

public static java.lang.String commalist(java.lang.Object o1,
                                         java.lang.Object o2,
                                         java.lang.Object o3)

commalist

public static java.lang.String commalist(java.lang.Object o1,
                                         java.lang.Object o2,
                                         java.lang.Object o3,
                                         java.lang.Object o4)

interval

public static java.lang.String interval(int low,
                                        int high)

alpha

public static char alpha(int num)

qembed

public static java.lang.String qembed(java.lang.String s1,
                                      java.lang.String s2,
                                      java.lang.String s3)

evaluateIntegerLiteral

public static int evaluateIntegerLiteral(java.lang.String val)

evaluateStringLiteral

public static java.lang.String evaluateStringLiteral(java.lang.String literal)

evaluateCharLiteral

public static char evaluateCharLiteral(java.lang.String literal)

trimquotes

public static java.lang.String trimquotes(java.lang.String s)

makeParagraphs

public static java.lang.String makeParagraphs(java.lang.String s,
                                              int leftJust,
                                              int indent,
                                              int width)

dup

public static java.lang.String dup(char c,
                                   int len)
The dup() method takes a character and a count and returns a string where that character has been duplicated the specified number of times.

Parameters:
c - the character to duplicate
len - the number of times to duplicate the character
Returns:
a string representation of the particular character duplicated the specified number of times

toFixedFloat

public static java.lang.String toFixedFloat(float fval,
                                            int places)

toDecimal

public static java.lang.String toDecimal(long val,
                                         int places)

toMultirepString

public static java.lang.String toMultirepString(int value,
                                                int bits)

toBit

public static char toBit(boolean f)

toIDTimeString

public static void toIDTimeString(java.lang.StringBuffer buf,
                                  int id,
                                  Clock clk)

toIDTimeString

public static java.lang.String toIDTimeString(int id,
                                              Clock clk)

getIDTimeString

public static java.lang.String getIDTimeString(Simulator s)

getIDTimeString

public static void getIDTimeString(java.lang.StringBuffer buf,
                                   Simulator s)