Files
mandy/tools/rpf9dump/ScanCounts.cs
cxchhh eea367772d rpf9dump: read back cache counts written under any culture
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>
2026-11-22 04:21:29 +00:00

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;
}
}