Skip to content

Commit

Permalink
Fixed empty string replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
VincenzoArceri committed Aug 22, 2023
1 parent 2028460 commit 87a748e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ public RegexAutomaton replace(String toReplace, RegexAutomaton str, boolean must
}

private RegexAutomaton emptyStringReplace(RegexAutomaton str) {
AtomicInteger counter = new AtomicInteger();
int maxId = origin.getStates().stream().mapToInt(s -> s.getId()).max().getAsInt();
AtomicInteger counter = new AtomicInteger(maxId + 1);
SortedSet<State> states = new TreeSet<>();
SortedSet<Transition<RegularExpression>> delta = new TreeSet<>();

Expand All @@ -132,6 +133,7 @@ private RegexAutomaton emptyStringReplace(RegexAutomaton str) {
Map<State, State> mapper = new HashMap<>();
origin.getStates().forEach(s -> mapper.put(s, new State(s.getId(), s.isInitial(), false)));
states.addAll(mapper.values());


Function<State, State> maker = s -> new State(counter.getAndIncrement(), false, false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,9 @@ public Tarsis concat(Tarsis other) {
* @return the domain instance containing the replaced automaton
*/
public Tarsis replace(Tarsis search, Tarsis repl) {
if (isBottom() || search.isBottom() || repl.isBottom())
return bottom();

try {
return new Tarsis(this.a.replace(search.a, repl.a));
} catch (CyclicAutomatonException e) {
Expand Down

0 comments on commit 87a748e

Please sign in to comment.