Skip to content

Commit

Permalink
fix: add workaround for android
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip Müller committed Jul 3, 2023
1 parent bd71a61 commit 9c55f2b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/src/main/java/com/knuddels/jtokkit/EncodingFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,14 @@ private static Encoding fromPredefinedParameters(
final String fileName,
final Map<String, Integer> specialTokens
) {
final Pattern regex = Pattern.compile(patternString, Pattern.UNICODE_CHARACTER_CLASS);
Pattern regex;
try {
regex = Pattern.compile(patternString, Pattern.UNICODE_CHARACTER_CLASS);
} catch (final IllegalArgumentException exception) {
// Workaround for Android where an IllegalArgumentException is thrown when using UNICODE_CHARACTER_CLASS
regex = Pattern.compile(patternString);
}

final GptBytePairEncodingParams params = new GptBytePairEncodingParams(name, regex, loadMergeableRanks(fileName), specialTokens);
return fromParameters(params);
}
Expand Down

0 comments on commit 9c55f2b

Please sign in to comment.