On this page

StrMatcher

@Deprecated public abstract class org.apache.commons.lang3.text.StrMatcher[source]

Deprecated: As of 3.6, use Apache Commons Text StringMatcherFactory.

A matcher class that can be queried to determine if a character array portion matches.

This class comes complete with various factory methods. If these do not suffice, you can subclass and implement your own matcher.

Since:

2.2

Constructors

StrMatcher()

Constructs a new instance.

protected StrMatcher()[source]

Constructs a new instance.

Methods

charMatcher(char)

Creates a matcher from a character.

charSetMatcher(char[])

Creates a matcher from a set of characters.

charSetMatcher(String)

Creates a matcher from a string representing a set of characters.

commaMatcher()

Gets the matcher for the comma character.

doubleQuoteMatcher()

Gets the matcher for the double quote character.

isMatch(char[], int)

Tests whether the number of matching characters, zero for no match.

isMatch(char[], int, int, int)

Tests whether the number of matching characters, zero for no match.

noneMatcher()

Gets the matcher for no characters.

quoteMatcher()

Gets the matcher for the single or double quote character.

singleQuoteMatcher()

Gets the matcher for the single quote character.

spaceMatcher()

Gets the matcher for the space character.

splitMatcher()

Gets the matcher for the same characters as StringTokenizer, namely space, tab, newline and form-feed.

stringMatcher(String)

Creates a matcher for a string.

tabMatcher()

Gets the matcher for the tab character.

trimMatcher()

Gets the matcher to String trim() whitespace characters.

public static StrMatcher charMatcher(char ch)[source]

Creates a matcher from a character.

Parameters:

ch – The character to match, must not be null.

Returns:

A new Matcher for the given char.

public static StrMatcher charSetMatcher(char... chars)[source]

Creates a matcher from a set of characters.

Parameters:

chars – The characters to match, null or empty matches nothing.

Returns:

A new matcher for the given char[].

public static StrMatcher charSetMatcher(String chars)[source]

Creates a matcher from a string representing a set of characters.

Parameters:

chars – The characters to match, null or empty matches nothing.

Returns:

A new Matcher for the given characters.

public static StrMatcher commaMatcher()[source]

Gets the matcher for the comma character.

Returns:

The matcher for a comma.

public static StrMatcher doubleQuoteMatcher()[source]

Gets the matcher for the double quote character.

Returns:

The matcher for a double quote.

public int isMatch(char[] buffer, int pos)[source]

Tests whether the number of matching characters, zero for no match.

This method is called to check for a match. The parameter pos represents the current position to be checked in the string buffer (a character array which must not be changed). The API guarantees that pos is a valid index for buffer.

The matching code may check one character or many. It may check characters preceding pos as well as those after.

It must return zero for no match, or a positive number if a match was found. The number indicates the number of characters that matched.

Parameters:
  • buffer – The text content to match against, do not change.

  • pos – The starting position for the match, valid for buffer.

Returns:

The number of matching characters, zero for no match.

Since:

2.4

public abstract int isMatch(char[] buffer, int pos, int bufferStart, int bufferEnd)[source]

Tests whether the number of matching characters, zero for no match.

This method is called to check for a match. The parameter pos represents the current position to be checked in the string buffer (a character array which must not be changed). The API guarantees that pos is a valid index for buffer.

The character array may be larger than the active area to be matched. Only values in the buffer between the specified indices may be accessed.

The matching code may check one character or many. It may check characters preceding pos as well as those after, so long as no checks exceed the bounds specified.

It must return zero for no match, or a positive number if a match was found. The number indicates the number of characters that matched.

Parameters:
  • buffer – The text content to match against, do not change.

  • pos – The starting position for the match, valid for buffer.

  • bufferStart – The first active index in the buffer, valid for buffer.

  • bufferEnd – The end index (exclusive) of the active buffer, valid for buffer.

Returns:

The number of matching characters, zero for no match.

public static StrMatcher noneMatcher()[source]

Gets the matcher for no characters.

Returns:

The matcher that matches nothing.

public static StrMatcher quoteMatcher()[source]

Gets the matcher for the single or double quote character.

Returns:

The matcher for a single or double quote.

public static StrMatcher singleQuoteMatcher()[source]

Gets the matcher for the single quote character.

Returns:

The matcher for a single quote.

public static StrMatcher spaceMatcher()[source]

Gets the matcher for the space character.

Returns:

The matcher for a space.

public static StrMatcher splitMatcher()[source]

Gets the matcher for the same characters as StringTokenizer, namely space, tab, newline and form-feed.

Returns:

The split matcher.

public static StrMatcher stringMatcher(String str)[source]

Creates a matcher for a string.

Parameters:

str – The string to match, null or empty matches nothing.

Returns:

A new Matcher for the given String.

public static StrMatcher tabMatcher()[source]

Gets the matcher for the tab character.

Returns:

The matcher for a tab.

public static StrMatcher trimMatcher()[source]

Gets the matcher to String trim() whitespace characters.

Returns:

The trim matcher.