kmy.regex.interp
Class InterpretedRegex

java.lang.Object
  |
  +--kmy.regex.util.Regex
        |
        +--kmy.regex.interp.InterpretedRegex

class InterpretedRegex
extends Regex
implements RInterpCommands, CharClassCodes


Inner Class Summary
(package private) static interface InterpretedRegex.AbortException
           
(package private) static class InterpretedRegex.Fork
           
(package private) static class InterpretedRegex.MultiFork
           
(package private) static class InterpretedRegex.Restore
           
 
Field Summary
(package private)  int addHeadIncrement
          Used to optimize HINT_CHAR_STAR_HEAD.
(package private)  byte[] bstring
           
(package private)  int[] cells
           
(package private)  byte[] code
           
(package private)  int end
           
(package private)  char[][] extCells
           
(package private)  int extVarCells
           
(package private)  java.util.Stack forks
           
(package private)  int headIncrement
          Used to optimize HINT_CHAR_STAR_HEAD.
(package private)  int headStart
           
(package private)  int hints
           
(package private)  int matchEnd
           
(package private)  int matchStart
           
(package private)  int maxLength
           
(package private)  int maxStart
           
(package private)  int mfCounter
           
(package private)  int minLength
           
(package private)  int nCells
           
(package private)  int pc
           
(package private)  RegexRefiller refiller
           
(package private)  int start
           
(package private)  char[] string
           
(package private)  java.util.Hashtable vars
           
 
Fields inherited from class kmy.regex.util.Regex
factory
 
Fields inherited from interface kmy.regex.interp.RInterpCommands
ASSERT_CHAR, ASSERT_CLASS, ASSERT_CLASS_RANGE, ASSERT_EXT_VAR, ASSERT_RANGE, ASSERT_VAR, ASSIGN, BOUNDARY, CHARLEFT, DECFAIL, DECJUMP, FAIL, FORK, HARDASSIGN, JUMP, JUMP_CHAR, JUMP_MAX_LEFT, JUMP_MIN_LEFT, JUMP_RANGE, MFEND, MFENDLIMIT, MFSTART, MFSTART_HEAD, PICK, SHIFTTBL, SKIP, SKIP_NON_NEWLINE, STOP
 
Fields inherited from interface kmy.regex.tree.CharClassCodes
CLASS_ALL, CLASS_DISABLED, CLASS_LETTER, CLASS_LOWERCASE, CLASS_NONE, CLASS_NONLETTER, CLASS_NONLOWERCASE, CLASS_NONUPPERCASE, CLASS_UPPERCASE
 
Constructor Summary
(package private) InterpretedRegex(byte[] code, java.util.Hashtable vars, int varCells, int hints, int minLength, int maxLength, int extVarCells)
           
 
Method Summary
private  int assign(int var, int val)
           
private  int fail()
           
private  void fork(int label, int head)
           
private  void fork(int decrement, int label, int head)
           
 byte[] getByteBuffer(int extHandle)
           
 char[] getCharBuffer(int extHandle)
          Returns external variable buffer by its buffer handle.
 int getExtVariableHandle(java.lang.String var)
          Returns external variable buffer handle that can be used later to get or set variable value efficiently.
 int getIndex(int handle)
          Returns external or internal variable index using its index handle.
 int getMatchEnd()
          After successiful search returns matching substring's final position in the input buffer (that was set up by init method).
 int getMatchStart()
          After successiful search returns matching substring's initial position in the input buffer (that was set up by init method).
 int getVariableHandle(java.lang.String var, boolean begin)
          Returns variable index handle that can be used later to get or set variable value efficiently.
private static boolean inClass(char c, int charClass)
           
 void init(byte[] arr, int off, int len)
           
 void init(char[] arr, int off, int len)
          Prepares to match or search.
 boolean match()
          Match the beginning of the buffer (that was set up by init method) against this regex.
 boolean matchWhole()
          Match the buffer (that was set up by init method) against this regex.
private  boolean nextMatchInt()
           
private  int readCode()
           
private  int readLabel()
           
private  boolean refill()
           
 boolean search()
          Search the buffer (that was set up by init method) for a substring that matches this regex.
 boolean searchAgain()
          Search the buffer (that was set up by init method) for a substring that matches this regex.
 void setExtVariableBuffer(int extHandle, char[] arr)
          Assignes external variable buffer by its buffer handle.
 void setIndex(int handle, int value)
          Returns internal variable index using its index handle.
 void setRefilledBuffer(char[] buffer)
          Refiller can call this method after refilling the buffer, if buffer has been reallocated.
 void setRefiller(RegexRefiller refiller)
           
 java.util.Enumeration variables()
          Enumerates all external and internal variables in this regex.
 
Methods inherited from class kmy.regex.util.Regex
accept, clone, cloneRegex, createFilePattern, createLowerCaseRegex, createRegex, createRegex, createRegex, get, getMatch, getMatchString, init, init, initFactory, matches, matches, matchesWhole, matchesWhole, searchOnce, searchOnce, searchOnce, searchOnce, set, setExtVariable, setExtVariable, setExtVariable, setExtVariable, setFactory
 
Methods inherited from class java.lang.Object
, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

nCells

int nCells

vars

java.util.Hashtable vars

code

byte[] code

hints

int hints

minLength

int minLength

maxLength

int maxLength

string

char[] string

bstring

byte[] bstring

cells

int[] cells

start

int start

end

int end

forks

java.util.Stack forks

pc

int pc

matchStart

int matchStart

matchEnd

int matchEnd

headStart

int headStart

maxStart

int maxStart

extCells

char[][] extCells

extVarCells

int extVarCells

mfCounter

int mfCounter

refiller

RegexRefiller refiller

headIncrement

int headIncrement
Used to optimize HINT_CHAR_STAR_HEAD. How much headStart can be incremented if matching fails the first attempt at any position.

addHeadIncrement

int addHeadIncrement
Used to optimize HINT_CHAR_STAR_HEAD. Needed to calculate headIncrement. It actually equals the minimum number of repetitions for the first subpattern and -1 to indicate that optimization should not be used.
Constructor Detail

InterpretedRegex

InterpretedRegex(byte[] code,
                 java.util.Hashtable vars,
                 int varCells,
                 int hints,
                 int minLength,
                 int maxLength,
                 int extVarCells)
Method Detail

readCode

private int readCode()

readLabel

private int readLabel()

fork

private void fork(int label,
                  int head)

fork

private void fork(int decrement,
                  int label,
                  int head)

assign

private int assign(int var,
                   int val)

fail

private int fail()

inClass

private static boolean inClass(char c,
                               int charClass)

refill

private boolean refill()

nextMatchInt

private boolean nextMatchInt()

getVariableHandle

public int getVariableHandle(java.lang.String var,
                             boolean begin)
Description copied from class: Regex
Returns variable index handle that can be used later to get or set variable value efficiently. If efficiency is not a concern, use get and set methods instead. Every variable has two index handles - 'begin' and 'end' index handle.
Overrides:
getVariableHandle in class Regex

variables

public java.util.Enumeration variables()
Description copied from class: Regex
Enumerates all external and internal variables in this regex.
Overrides:
variables in class Regex

getExtVariableHandle

public int getExtVariableHandle(java.lang.String var)
Description copied from class: Regex
Returns external variable buffer handle that can be used later to get or set variable value efficiently. If efficiency is not a concern, use get and set methods instead. Only external variables have buffer handle. This is different from index handles. For internal variables this method returs -1.
Overrides:
getExtVariableHandle in class Regex

setExtVariableBuffer

public void setExtVariableBuffer(int extHandle,
                                 char[] arr)
Description copied from class: Regex
Assignes external variable buffer by its buffer handle. It is needed to completely specify value of an external variable.
Overrides:
setExtVariableBuffer in class Regex

init

public void init(char[] arr,
                 int off,
                 int len)
Description copied from class: Regex
Prepares to match or search. Sets up an input buffer and a range of characters in it that is to be searched or matched.
Overrides:
init in class Regex

init

public void init(byte[] arr,
                 int off,
                 int len)

getCharBuffer

public char[] getCharBuffer(int extHandle)
Description copied from class: Regex
Returns external variable buffer by its buffer handle. If -1 is passed as a handle the input buffer that was set up for matching (using init) is returned.
Overrides:
getCharBuffer in class Regex

getByteBuffer

public byte[] getByteBuffer(int extHandle)

getMatchStart

public int getMatchStart()
Description copied from class: Regex
After successiful search returns matching substring's initial position in the input buffer (that was set up by init method).
Overrides:
getMatchStart in class Regex

getMatchEnd

public int getMatchEnd()
Description copied from class: Regex
After successiful search returns matching substring's final position in the input buffer (that was set up by init method).
Overrides:
getMatchEnd in class Regex

getIndex

public int getIndex(int handle)
Description copied from class: Regex
Returns external or internal variable index using its index handle. Every variable has two indices - 'begin' and 'end'. Use 'begin' and 'end' handles to get them. These indices can be used to determine which part of the input buffer (set by init method) corresponding internal variable matched. An external variable 'begin' and 'end' indices point to its own buffer. They are assinged by setIndex and are never changed.
Overrides:
getIndex in class Regex

setIndex

public void setIndex(int handle,
                     int value)
Description copied from class: Regex
Returns internal variable index using its index handle. Every variable has two indices - 'begin' and 'end'. Use 'begin' and 'end' handles to assign them. These indices are needed to completely specify value of an external variable.
Overrides:
setIndex in class Regex

setRefiller

public void setRefiller(RegexRefiller refiller)
Overrides:
setRefiller in class Regex

setRefilledBuffer

public void setRefilledBuffer(char[] buffer)
Description copied from class: Regex
Refiller can call this method after refilling the buffer, if buffer has been reallocated.
Overrides:
setRefilledBuffer in class Regex

search

public boolean search()
Description copied from class: Regex
Search the buffer (that was set up by init method) for a substring that matches this regex. See description of this class for difference between search and match. All records for other possible matches withing matching substring that was found are destroyed, so if this method is called again, search will start at the first position after previously found substring.
Overrides:
search in class Regex

searchAgain

public boolean searchAgain()
Description copied from class: Regex
Search the buffer (that was set up by init method) for a substring that matches this regex. See description of this class for difference between search and match. On success do not discard record of all other possible matches, so if this method is called again, different way of matching can be found for already found substring or a substring overlapping already found substring. Most often, search(), not searchAgain() should be used.
Overrides:
searchAgain in class Regex

matchWhole

public boolean matchWhole()
Description copied from class: Regex
Match the buffer (that was set up by init method) against this regex. See description of this class for difference between search/match/matchWhole.
Overrides:
matchWhole in class Regex

match

public boolean match()
Description copied from class: Regex
Match the beginning of the buffer (that was set up by init method) against this regex. See description of this class for difference between search/match/matchWhole.
Overrides:
match in class Regex