Skip to content

Commit

Permalink
Add a method to style matching strings with groups
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Apr 4, 2019
1 parent 4c66dfd commit 2a4646a
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package org.jline.utils;

import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -393,4 +394,17 @@ public AttributedStringBuilder styleMatches(Pattern pattern, AttributedStyle s)
return this;
}

public AttributedStringBuilder styleMatches(Pattern pattern, List<AttributedStyle> styles) {
Matcher matcher = pattern.matcher(this);
while (matcher.find()) {
for (int group = 0; group < matcher.groupCount(); group++) {
AttributedStyle s = styles.get(group);
for (int i = matcher.start(group + 1); i < matcher.end(group + 1); i++) {
style[i] = (style[i] & ~s.getMask()) | s.getStyle();
}
}
}
return this;
}

}

0 comments on commit 2a4646a

Please sign in to comment.