eapms
Class ANSIFormat

java.lang.Object
  |
  +--eapms.ANSIFormat
Direct Known Subclasses:
ColorFormatter

public abstract class ANSIFormat
extends java.lang.Object

Base class for ANSI formatting of text


Nested Class Summary
static class ANSIFormat.Attrs
          ANSI Attribute Modifiers
static class ANSIFormat.BGColors
          ANSI Background Colors
static class ANSIFormat.FGColors
          ANSI Foreground Colors
 
Field Summary
static java.lang.String CHAR_CLASS
          The required character class for code matching.
static int DEFAULT_FLAGS
          Default flags for regex compile.
static int DEFAULT_INDEX
          Default capturing group index
static java.lang.String DEFAULT_REGEX
          The default regular expression: html-like tags.
protected static int mFlags
           
protected static boolean mFlagsSet
           
protected static java.util.regex.Pattern mPattern
           
protected static java.lang.String mRegex
           
protected static int mRepndx
           
static java.lang.String PLACEHOLDER
          Placeholder for user-entered regex's.
static java.lang.String UNICODE_ESCAPE
          The Unicode value for an Escape sequence.
 
Constructor Summary
ANSIFormat()
           
 
Method Summary
 void compilePattern()
           
 void compilePattern(java.lang.String re)
           
 void compilePattern(java.lang.String re, int ndx)
           
abstract  void compilePattern(java.lang.String regex, int repndx, int flags)
          Compiles the regex supplied with the supplied flags.
 int getFlags()
           
 java.util.regex.Pattern getPattern()
           
 java.lang.String getRegex()
           
abstract  java.lang.String stringReplace(java.lang.String str)
          Simply takes the string str and returns a much prettier version of it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PLACEHOLDER

public static final java.lang.String PLACEHOLDER
Placeholder for user-entered regex's.

See Also:
Constant Field Values

DEFAULT_REGEX

public static final java.lang.String DEFAULT_REGEX
The default regular expression: html-like tags.

See Also:
Constant Field Values

CHAR_CLASS

public static final java.lang.String CHAR_CLASS
The required character class for code matching.

See Also:
Constant Field Values

UNICODE_ESCAPE

public static final java.lang.String UNICODE_ESCAPE
The Unicode value for an Escape sequence.

See Also:
Constant Field Values

DEFAULT_FLAGS

public static final int DEFAULT_FLAGS
Default flags for regex compile.

See Also:
Regex Pattern Class, Constant Field Values

DEFAULT_INDEX

public static final int DEFAULT_INDEX
Default capturing group index

See Also:
Constant Field Values

mFlags

protected static int mFlags

mRepndx

protected static int mRepndx

mRegex

protected static java.lang.String mRegex

mPattern

protected static java.util.regex.Pattern mPattern

mFlagsSet

protected static boolean mFlagsSet
Constructor Detail

ANSIFormat

public ANSIFormat()
Method Detail

getRegex

public java.lang.String getRegex()

getPattern

public java.util.regex.Pattern getPattern()

getFlags

public int getFlags()

compilePattern

public void compilePattern()

compilePattern

public void compilePattern(java.lang.String re)

compilePattern

public void compilePattern(java.lang.String re,
                           int ndx)

compilePattern

public abstract void compilePattern(java.lang.String regex,
                                    int repndx,
                                    int flags)
                             throws java.lang.IllegalArgumentException,
                                    java.util.regex.PatternSyntaxException
Compiles the regex supplied with the supplied flags. The string passed to this method as the regex must be in a certain form. As there is a specific character class that must be used in the matching, a placeholder is used in the regex string. You must therefore pass a regex string with this placeholder, such as

\<("+ANSIFormat.PLACEHOLDER+"*?)\>([^<]*)

The placeholder is the string "%%%", so the above would be:

\<(%%%*?)\>([^<]*)"

which will then be replaced with the character class to become

\<([brnglmcw~+-_*;?!]*?)\>([^<]*)"

Also, you'll need to pass a repndx integer as the second argument - this value tells the stringReplace method which capturing group to look in to find where the actual color codes are held (otherwise it won't know which part is color codes and which is text).

Simple, isn't it

Throws:
java.util.regex.PatternSyntaxException - Wrong syntax, retard.
java.lang.IllegalArgumentException - The repndx value must be greater than zero - can also be thrown from something in the regex class, but I don't know why...go look it up, idiot.

stringReplace

public abstract java.lang.String stringReplace(java.lang.String str)
Simply takes the string str and returns a much prettier version of it.