Javolution 6.0.0 java
javolution.text.CharSet Class Reference
Inheritance diagram for javolution.text.CharSet:
[legend]
Collaboration diagram for javolution.text.CharSet:
[legend]

Public Member Functions

boolean contains (char c)
 
int indexIn (CharSequence csq)
 
int indexIn (CharSequence csq, int fromIndex)
 
int indexIn (char[] chars)
 
int indexIn (char[] chars, int fromIndex)
 
int lastIndexIn (CharSequence csq)
 
int lastIndexIn (CharSequence csq, int fromIndex)
 
int lastIndexIn (char[] chars)
 
int lastIndexIn (char[] chars, int fromIndex)
 
CharSet plus (CharSet that)
 
CharSet minus (CharSet that)
 
String toString ()
 
CharSet value ()
 

Static Public Member Functions

static CharSet valueOf (char... chars)
 
static CharSet rangeOf (char first, char last)
 

Static Public Attributes

static final CharSet EMPTY = new CharSet(new long[0])
 
static final CharSet WHITESPACES
 
static final CharSet SPACES
 
static final CharSet ISO_CONTROLS
 

Private Member Functions

 CharSet (long[] mapping)
 
CharSet copy ()
 

Private Attributes

final long[] _mapping
 

Detailed Description

A set of characters (typically used for parsing purpose where it is significantly faster than regular expressions for simple patterns). For example: [code] // Integration with Text. Text number; int exponentIndex = num.indexOfAny(CharSet.valueOf('e', 'E'));

// Integration with TextFormat. public List<Integer> parse(CharSequence csq, Cursor cursor) { FastTable<Integer> numbers = FastTable.newInstance(); while (cursor.skip(CharSet.WHITESPACES, csq)) { numbers.add(TypeFormat.parseInt(csq, cursor)); } return numbers; } [/code]


Author
Jean-Marie Dautelle
Version
3.7, January 1, 2006

Definition at line 35 of file CharSet.java.

Constructor & Destructor Documentation

◆ CharSet()

javolution.text.CharSet.CharSet ( long[]  mapping)
private

Creates a character set with the specified mapping.

Parameters
mappingthe character set mapping.

Definition at line 82 of file CharSet.java.

82  {
83  _mapping = mapping;
84  }

References javolution.text.CharSet._mapping.

Referenced by javolution.text.CharSet.copy(), javolution.text.CharSet.rangeOf(), and javolution.text.CharSet.valueOf().

Here is the caller graph for this function:

Member Function Documentation

◆ contains()

boolean javolution.text.CharSet.contains ( char  c)

Indicates if the specified character is contained by this character set.

Parameters
cthe character to test.
Returns
true if this character set contains the specified character; false otherwise.

Definition at line 135 of file CharSet.java.

135  {
136  final int i = c >> 6;
137  return i < _mapping.length ? (_mapping[i] & (1L << (c & 63))) != 0
138  : false;
139  }

References javolution.text.CharSet._mapping.

Referenced by javolution.text.Cursor.at(), javolution.text.CharSet.indexIn(), javolution.text.Text.indexOfAny(), javolution.text.CharSet.lastIndexIn(), javolution.text.Text.lastIndexOfAny(), javolution.text.Cursor.nextToken(), javolution.text.Cursor.skipAny(), and javolution.text.CharSet.toString().

Here is the caller graph for this function:

◆ copy()

CharSet javolution.text.CharSet.copy ( )
private

Returns a copy of this character set.

Definition at line 315 of file CharSet.java.

315  {
316  CharSet charSet = new CharSet(new long[this._mapping.length]);
317  for (int i = _mapping.length; --i >= 0;) {
318  charSet._mapping[i] = _mapping[i];
319  }
320  return charSet;
321  }

References javolution.text.CharSet._mapping, and javolution.text.CharSet.CharSet().

Referenced by javolution.text.CharSet.minus(), and javolution.text.CharSet.plus().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ indexIn() [1/4]

int javolution.text.CharSet.indexIn ( char[]  chars)

Equivalent to indexIn(chars, 0)

Returns
the index in the specified character sequence or -1 if none found.

Definition at line 176 of file CharSet.java.

176  {
177  return indexIn(chars, 0);
178  }

References javolution.text.CharSet.indexIn().

Here is the call graph for this function:

◆ indexIn() [2/4]

int javolution.text.CharSet.indexIn ( char[]  chars,
int  fromIndex 
)

Returns the first index in the specified character array of one of the character of this set.

Parameters
charsthe character array to be searched.
fromIndexthe index to search from.
Returns
the index in the specified character sequence or -1 if none found.

Definition at line 189 of file CharSet.java.

189  {
190  for (int i = fromIndex, n = chars.length; i < n; i++) {
191  if (contains(chars[i]))
192  return i;
193  }
194  return -1;
195  }

References javolution.text.CharSet.contains().

Here is the call graph for this function:

◆ indexIn() [3/4]

int javolution.text.CharSet.indexIn ( CharSequence  csq)

Equivalent to indexIn(csq, 0)

Parameters
csqthe character sequence to be searched.
Returns
the index in the specified character sequence or -1 if none found.

Definition at line 149 of file CharSet.java.

149  {
150  return indexIn(csq, 0);
151  }

Referenced by javolution.text.CharSet.indexIn().

Here is the caller graph for this function:

◆ indexIn() [4/4]

int javolution.text.CharSet.indexIn ( CharSequence  csq,
int  fromIndex 
)

Returns the first index in the specified character sequence of one of the character of this set.

Parameters
csqthe character sequence to be searched.
fromIndexthe index to search from.
Returns
the index in the specified character sequence or -1 if none found.

Definition at line 162 of file CharSet.java.

162  {
163  for (int i = fromIndex, n = csq.length(); i < n; i++) {
164  if (contains(csq.charAt(i)))
165  return i;
166  }
167  return -1;
168  }

References javolution.text.CharSet.contains().

Here is the call graph for this function:

◆ lastIndexIn() [1/4]

int javolution.text.CharSet.lastIndexIn ( char[]  chars)

Equivalent to lastIndexIn(chars, chars.length-1)

Returns
the index in the specified character sequence or -1 if none found.

Definition at line 234 of file CharSet.java.

234  {
235  return lastIndexIn(chars, chars.length - 1);
236  }

References javolution.text.CharSet.lastIndexIn().

Here is the call graph for this function:

◆ lastIndexIn() [2/4]

int javolution.text.CharSet.lastIndexIn ( char[]  chars,
int  fromIndex 
)

Returns the last index in the specified character array of one of the character of this set.

Parameters
charsthe character array to be searched.
fromIndexthe index to search from (backward).
Returns
the index in the specified character sequence or -1 if none found.

Definition at line 247 of file CharSet.java.

247  {
248  for (int i = fromIndex; i >= 0; i--) {
249  if (contains(chars[i]))
250  return i;
251  }
252  return -1;
253  }

References javolution.text.CharSet.contains().

Here is the call graph for this function:

◆ lastIndexIn() [3/4]

int javolution.text.CharSet.lastIndexIn ( CharSequence  csq)

Equivalent to lastIndexIn(csq, csq.length()-1)

Parameters
csqthe character sequence to be searched.
Returns
the last index in the specified character sequence or -1 if none found.

Definition at line 206 of file CharSet.java.

206  {
207  return lastIndexIn(csq, csq.length() - 1);
208  }

Referenced by javolution.text.CharSet.lastIndexIn().

Here is the caller graph for this function:

◆ lastIndexIn() [4/4]

int javolution.text.CharSet.lastIndexIn ( CharSequence  csq,
int  fromIndex 
)

Returns the last index in the specified character sequence of one of the character of this set.

Parameters
csqthe character sequence to be searched.
fromIndexthe index to search from (backward).
Returns
the index in the specified character sequence or -1 if none found.

Definition at line 219 of file CharSet.java.

219  {
220  for (int i = fromIndex; i >= 0; --i) {
221  if (contains(csq.charAt(i)))
222  return i;
223  }
224  return -1;
225  }

References javolution.text.CharSet.contains().

Here is the call graph for this function:

◆ minus()

CharSet javolution.text.CharSet.minus ( CharSet  that)

Returns the character set containing the characters from this character minus the characters from the character set specified.

Parameters
thatthe set containing the character to be removed.
Returns
this - that

Definition at line 279 of file CharSet.java.

279  {
280  CharSet result = this.copy();
281  for (int i = MathLib.min(this._mapping.length, that._mapping.length); --i >= 0;) {
282  result._mapping[i] &= ~that._mapping[i];
283  }
284  return result;
285  }

References javolution.text.CharSet._mapping, javolution.text.CharSet.copy(), and javolution.lang.MathLib.min().

Here is the call graph for this function:

◆ plus()

CharSet javolution.text.CharSet.plus ( CharSet  that)

Returns the character set containing the characters from this character set plus the characters from the character set specified.

Parameters
thatthe set containing the characters to be added.
Returns
this + that

Definition at line 262 of file CharSet.java.

262  {
263  if (that._mapping.length > this._mapping.length)
264  return that.plus(this);
265  CharSet result = this.copy();
266  for (int i = that._mapping.length; --i >= 0;) {
267  result._mapping[i] |= that._mapping[i];
268  }
269  return result;
270  }

References javolution.text.CharSet._mapping, javolution.text.CharSet.copy(), and javolution.text.CharSet.plus().

Referenced by javolution.text.CharSet.plus().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rangeOf()

static CharSet javolution.text.CharSet.rangeOf ( char  first,
char  last 
)
static

Returns the character set holding the characters in the specified range.

Parameters
firstthe first character.
lastthe last character.
Returns
the corresponding character set.
Exceptions
IllegalArgumentExceptionif first > last

Definition at line 116 of file CharSet.java.

116  {
117  if (first > last)
118  throw new IllegalArgumentException(
119  "first should be less or equal to last");
120  CharSet charSet = new CharSet(new long[(last >> 6) + 1]);
121  for (char c = first; c <= last; c++) {
122  charSet._mapping[c >> 6] |= 1L << (c & 63);
123  }
124  return charSet;
125 
126  }

References javolution.text.CharSet._mapping, and javolution.text.CharSet.CharSet().

Here is the call graph for this function:

◆ toString()

String javolution.text.CharSet.toString ( )

Returns the textual representation of this character set.

Returns
the textual representation.

Definition at line 293 of file CharSet.java.

293  {
294  TextBuilder tb = new TextBuilder();
295  tb.append('{');
296  int length = _mapping.length << 6;
297  for (int i = 0; i < length; i++) {
298  if (this.contains((char) i)) {
299  if (tb.length() > 1) {
300  tb.append(',');
301  tb.append(' ');
302  }
303  tb.append('\'');
304  tb.append((char) i);
305  tb.append('\'');
306  }
307  }
308  tb.append('}');
309  return tb.toString();
310  }

References javolution.text.CharSet._mapping, javolution.text.TextBuilder.append(), javolution.text.CharSet.contains(), javolution.text.TextBuilder.length(), and javolution.text.TextBuilder.toString().

Here is the call graph for this function:

◆ value()

CharSet javolution.text.CharSet.value ( )

Returns the constant value held by this object.

Implements javolution.lang.Immutable< T >.

Definition at line 324 of file CharSet.java.

324  {
325  return this;
326  }

◆ valueOf()

static CharSet javolution.text.CharSet.valueOf ( char...  chars)
static

Returns the character set holding the specified characters.

Parameters
charsthe characters contained by this character set.
Returns
the corresponding character set.

Definition at line 92 of file CharSet.java.

92  {
93  int maxChar = 0;
94  for (int i = chars.length; --i >= 0;) {
95  if (chars[i] > maxChar) {
96  maxChar = chars[i];
97  }
98  }
99  CharSet charSet = new CharSet(new long[(maxChar >> 6) + 1]);
100  for (int i = chars.length; --i >= 0;) {
101  char c = chars[i];
102  charSet._mapping[c >> 6] |= 1L << (c & 63);
103  }
104  return charSet;
105  }

References javolution.text.CharSet._mapping, and javolution.text.CharSet.CharSet().

Here is the call graph for this function:

Member Data Documentation

◆ _mapping

◆ EMPTY

final CharSet javolution.text.CharSet.EMPTY = new CharSet(new long[0])
static

Represents an empty character set.

Definition at line 40 of file CharSet.java.

◆ ISO_CONTROLS

final CharSet javolution.text.CharSet.ISO_CONTROLS
static
Initial value:
= CharSet.valueOf(new char[] {
0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xA, 0xB, 0xC,
0xD, 0xE, 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x7F, 0x80, 0x81,
0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C,
0x8D, 0x8E, 0x8F, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F })

Represents ISO control characters according to Java (see Character#isISOControl(char)).

Definition at line 64 of file CharSet.java.

◆ SPACES

final CharSet javolution.text.CharSet.SPACES
static
Initial value:
= CharSet.valueOf(new char[] { 0x20,
0xA0, 0x1680, 0x180E, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004,
0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x200B, 0x2028,
0x2029, 0x202F, 0x205F, 0x3000 })

Represents spaces characters according to Java (see Character#isSpaceChar(char)).

Definition at line 55 of file CharSet.java.

◆ WHITESPACES

final CharSet javolution.text.CharSet.WHITESPACES
static
Initial value:
= CharSet.valueOf(new char[] { 0x9,
0xA, 0xB, 0xC, 0xD, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x1680, 0x180E,
0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2008,
0x2009, 0x200A, 0x200B, 0x2028, 0x2029, 0x205F, 0x3000 })

Represents white spaces characters according to Java (see Character#isWhitespace(char)).

Definition at line 46 of file CharSet.java.


The documentation for this class was generated from the following file:
javolution.text.CharSet.copy
CharSet copy()
Definition: CharSet.java:315
javolution.text.CharSet.lastIndexIn
int lastIndexIn(CharSequence csq)
Definition: CharSet.java:206
javolution.text.CharSet.CharSet
CharSet(long[] mapping)
Definition: CharSet.java:82
javolution.text.CharSet.contains
boolean contains(char c)
Definition: CharSet.java:135
javolution.text.CharSet._mapping
final long[] _mapping
Definition: CharSet.java:75
javolution.text.CharSet.indexIn
int indexIn(CharSequence csq)
Definition: CharSet.java:149