mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 16:08:37 +00:00
The old coverage text used N0, whose group separator is not always one of . , ' or a space: de-CH writes U+2019, ar-* U+066C, nqo U+060C, ff-Adlm U+2E41. Accept any punctuation or space between the digits. With ICU, the old pattern failed for 77 of 852 cultures and the new one for none; the diagnostics test now checks every culture. Reported by kotorvr in the review of #853. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
22 lines
1.1 KiB
C#
22 lines
1.1 KiB
C#
using System.Text.RegularExpressions;
|
|
|
|
// Scan-level counts for the manifest. Candidates that RecoverAtOffsets rejects never reach Program.cs, so
|
|
// Candidates - Recovered is the only place those rejects show up.
|
|
internal static class ScanCounts
|
|
{
|
|
// Written into the index cache's coverage text on a full scan.
|
|
public static string Coverage(int candidates, int recovered) =>
|
|
FormattableString.Invariant($"rpf9dump full scan, {candidates} candidates, {recovered} recovered");
|
|
|
|
// Reads the candidate count back from a cached index. Older caches wrote culture-formatted numbers
|
|
// ("183,801", "183'801", "183\u2019801", ...), so any punctuation or space between the digits is dropped. Null when the text is not ours or not readable.
|
|
public static int? Candidates(string? coverage)
|
|
{
|
|
if (coverage is null) return null;
|
|
var m = Regex.Match(coverage, @"^rpf9dump full scan, ([0-9][0-9\p{P}\p{Zs}]*) candidates,");
|
|
if (!m.Success) return null;
|
|
string digits = new(m.Groups[1].Value.Where(char.IsAsciiDigit).ToArray());
|
|
return int.TryParse(digits, out int n) ? n : null;
|
|
}
|
|
}
|