| Title: Tokenizer
Description: None
Copyright (c) 1999 Steven J. Metsker.
Copyright (c) 2001 The Open For Business Project - www.ofbiz.org
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
THE USE OR OTHER DEALINGS IN THE SOFTWARE.
A tokenizer divides a string into tokens. This class is
highly customizable with regard to exactly how this division
occurs, but it also has defaults that are suitable for many
languages. This class assumes that the character values read
from the string lie in the range 0-255. For example, the
Unicode value of a capital A is 65, so
System.out.println((char)65); prints out a
capital A.
The behavior of a tokenizer depends on its character state
table. This table is an array of 256 TokenizerState
states. The state table decides which state to
enter upon reading a character from the input
string.
For example, by default, upon reading an 'A', a tokenizer
will enter a "word" state. This means the tokenizer will
ask a WordState object to consume the 'A',
along with the characters after the 'A' that form a word.
The state's responsibility is to consume characters and
return a complete token.
The default table sets a SymbolState for every character
from 0 to 255, and then overrides this with:
From To State
0 ' ' whitespaceState
'a' 'z' wordState
'A' 'Z' wordState
160 255 wordState
'0' '9' numberState
'-' '-' numberState
'.' '.' numberState
'"' '"' quoteState
'\'' '\'' quoteState
'/' '/' slashState
In addition to allowing modification of the state table,
this class makes each of the states above available. Some
of these states are customizable. For example, wordState
allows customization of what characters can be part of a
word, after the first character.
author: Steven J. Metsker version: 1.0 |