Package dev.gmitch215.bytebox.regex
Class Matcher
java.lang.Object
dev.gmitch215.bytebox.regex.Matcher
- All Implemented Interfaces:
MatchResult
A match in progress, standing in for
java.util.regex.Matcher.
The compiler substitutes java.util.regex.Matcher for this one. Finding is the platform's;
the replacement syntax is not, because Java writes $1 and ${name} where the platform
writes $1 and $<name>, so every replacement is assembled here rather than handed over.
What is not here, because it has no equivalent and a wrong answer would be worse than a build
failure: a search region, hitEnd and requireEnd. A program reaching for one fails to
compile.
- Since:
- 1.0.0
-
Method Summary
Modifier and TypeMethodDescriptionappendReplacement(StringBuilder into, String replacement) Appends everything up to the current match, then the replacement.appendTail(StringBuilder into) Appends everything after the last match.intend()intend(int index) intbooleanfind()Finds the next match after where the last one ended.booleanfind(int at) Finds the next match from a position, forgetting where the last one ended.group()group(int index) intbooleanWhether the start of the input matches.booleanmatches()Whether the whole input matches.pattern()Returns the pattern this matches with.static StringquoteReplacement(String text) A replacement that stands for itself, with nothing in it taken as a group.replaceAll(String replacement) Replaces every match.replaceFirst(String replacement) Replaces the first match.reset()Forgets everything found so far.reset(CharSequence input) Forgets everything found so far and takes a new input.results()Every match, as results that keep what they found.intstart()intstart(int index) intReturns what was found, kept as it is now.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.regex.MatchResult
hasMatch
-
Method Details
-
pattern
Returns the pattern this matches with.- Returns:
- the pattern this matches with
-
find
public boolean find()Finds the next match after where the last one ended.- Returns:
- whether one was found
-
find
public boolean find(int at) Finds the next match from a position, forgetting where the last one ended.- Parameters:
at- where to start- Returns:
- whether one was found
-
matches
public boolean matches()Whether the whole input matches.- Returns:
- whether it does
-
lookingAt
public boolean lookingAt()Whether the start of the input matches.- Returns:
- whether it does
-
reset
Forgets everything found so far.- Returns:
- this matcher
-
reset
Forgets everything found so far and takes a new input.- Parameters:
input- what to search- Returns:
- this matcher
-
group
- Specified by:
groupin interfaceMatchResult
-
group
- Specified by:
groupin interfaceMatchResult
-
group
- Specified by:
groupin interfaceMatchResult
-
groupCount
public int groupCount()- Specified by:
groupCountin interfaceMatchResult
-
start
public int start()- Specified by:
startin interfaceMatchResult
-
start
public int start(int index) - Specified by:
startin interfaceMatchResult
-
start
- Specified by:
startin interfaceMatchResult
-
end
public int end()- Specified by:
endin interfaceMatchResult
-
end
public int end(int index) - Specified by:
endin interfaceMatchResult
-
end
- Specified by:
endin interfaceMatchResult
-
namedGroups
- Specified by:
namedGroupsin interfaceMatchResult
-
results
Every match, as results that keep what they found.- Returns:
- the matches
-
toMatchResult
Returns what was found, kept as it is now.- Returns:
- what was found, kept as it is now
-
replaceAll
Replaces every match.- Parameters:
replacement- the replacement, where$1and${name}stand for groups- Returns:
- the result
-
replaceFirst
Replaces the first match.- Parameters:
replacement- the replacement, where$1and${name}stand for groups- Returns:
- the result
-
appendReplacement
Appends everything up to the current match, then the replacement.- Parameters:
into- where to appendreplacement- the replacement, where$1and${name}stand for groups- Returns:
- this matcher
-
appendTail
Appends everything after the last match.- Parameters:
into- where to append- Returns:
- what was appended to
-
quoteReplacement
A replacement that stands for itself, with nothing in it taken as a group.- Parameters:
text- the replacement- Returns:
- the escaped replacement
-