Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hunspell: tolerate REP rule count mismatches #14079

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -405,10 +405,18 @@ private void readAffixFile(InputStream affixStream, CharsetDecoder decoder, Flag
} else if ("TRY".equals(firstWord)) {
tryChars = firstArgument(reader, line);
} else if ("REP".equals(firstWord)) {
int count = parseNum(reader, line);
for (int i = 0; i < count; i++) {
String[] parts = splitBySpace(reader, reader.readLine(), 3, Integer.MAX_VALUE);
repTable.add(new RepEntry(parts[1], parts[2]));
if (tolerateRepRuleCountMismatches()) {
String[] parts = splitBySpace(reader, line, 2, Integer.MAX_VALUE);
// ignore REP N, as actual N may be incorrect
if (parts.length >= 3) {
repTable.add(new RepEntry(parts[1], parts[2]));
}
} else {
int count = parseNum(reader, line);
for (int i = 0; i < count; i++) {
String[] parts = splitBySpace(reader, reader.readLine(), 3, Integer.MAX_VALUE);
repTable.add(new RepEntry(parts[1], parts[2]));
}
}
} else if ("MAP".equals(firstWord)) {
int count = parseNum(reader, line);
Expand Down Expand Up @@ -1168,6 +1176,14 @@ protected boolean tolerateAffixRuleCountMismatches() {
return false;
}

/**
* Whether incorrect REP rule counts will be silently ignored. False by default: a {@link
* ParseException} will happen.
*/
protected boolean tolerateRepRuleCountMismatches() {
return false;
}

/**
* Whether duplicate ICONV/OCONV lines should be silently ignored. False by default: an {@link
* IllegalStateException} will happen.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ static Dictionary loadDictionary(Path aff) throws IOException, ParseException {
protected boolean tolerateAffixRuleCountMismatches() {
return true;
}

@Override
protected boolean tolerateRepRuleCountMismatches() {
return true;
}
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ protected boolean tolerateAffixRuleCountMismatches() {
return true;
}

@Override
protected boolean tolerateRepRuleCountMismatches() {
return true;
}

@Override
protected boolean tolerateDuplicateConversionMappings() {
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
REP 1
REP 0
REP foo bar goo doo zoo

COMPOUNDWORDMAX 2 y
Expand All @@ -16,4 +16,4 @@ SFX A b c d

ICONV 2
ICONV x y
ICONV x y
ICONV x y
Loading