EX
- The exception type that the "match replacer" (see Substitutor(Pattern, FunctionWhichThrows)
is allowed to throw; use NoException
if your match replacer does not throw any (checked)
exceptionspublic class Substitutor<EX extends Throwable> extends Object implements TransformerWhichThrows<CharSequence,CharSequence,EX>
As the substitutor consumes chunks, it produces a sequence of strings, and the concatenation of the chunks read equals the concatenation of the produced strings, except that all matches of the pattern are substituted with the replacements generated by the matchReplacer.
Iff the input to the transformer is ""
(the empty string), then the "rest" of any pending matches is
returned. This is sort of a "flush" operation.
The substitutor attempts to keep as little characters as possible in memory, which make it possible to find matches in documents that are too large to load into memory.
If you plan to use "look-behinds" (the most common of which is "^"), bear in mind that the look-behind memory is
limited; by default to 10. If you need more look-behind space, use Substitutor(Pattern, FunctionWhichThrows, int)
.
Also bear in mind that, specifically when using "greedy quantifiers", that it may happen quite easily that the
entire input must be read into memory, only to find that there is no match. E.g. the pattern "a.*b"
, as
soon as it hits the letter "a", will load all the remaining text into memory, because there might still come
(another) "b".
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_LOOKBEHIND_LIMIT
The number of characters that can safely be used for look-behind, unless a different value is configured through
Substitutor(Pattern, FunctionWhichThrows, int) . |
Constructor and Description |
---|
Substitutor(Pattern pattern,
FunctionWhichThrows<? super Matcher,? extends CharSequence,? extends EX> matchReplacer) |
Substitutor(Pattern pattern,
FunctionWhichThrows<? super Matcher,? extends CharSequence,? extends EX> matchReplacer,
int lookBehindLimit) |
Modifier and Type | Method and Description |
---|---|
int |
substitutionCount() |
CharSequence |
transform(CharSequence in)
Substitutes all matches in the subject and returns it.
|
public static final int DEFAULT_LOOKBEHIND_LIMIT
Substitutor(Pattern, FunctionWhichThrows, int)
.public Substitutor(Pattern pattern, FunctionWhichThrows<? super Matcher,? extends CharSequence,? extends EX> matchReplacer)
public Substitutor(Pattern pattern, FunctionWhichThrows<? super Matcher,? extends CharSequence,? extends EX> matchReplacer, int lookBehindLimit)
public CharSequence transform(CharSequence in) throws EX extends Throwable
transform
in interface TransformerWhichThrows<CharSequence,CharSequence,EX extends Throwable>
EX extends Throwable
public int substitutionCount()
null
valueCopyright © 2018 Arno Unkrig. All rights reserved.