Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions csharp/PhoneNumbers.MetadataBuilder/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ public static int Main(string[] args)
try { return Run(args); }
finally { mutex.ReleaseMutex(); }
}
// Deliberately broad: this is the process-wide handler for a build-time tool, and the
// work it guards reaches XML parsing, file I/O and named-mutex code that between them
// can throw a dozen unrelated types. Nothing is swallowed — the full exception goes to
// stderr and the non-zero exit code fails the MSBuild target that invoked us — so
// narrowing this would only trade a readable one-line diagnostic for an unhandled-
// exception crash dump, with no change to whether the build fails.
catch (Exception ex)
{
Console.Error.WriteLine($"PhoneNumbers.MetadataBuilder failed: {ex.Message}");
Expand Down
5 changes: 5 additions & 0 deletions csharp/PhoneNumbers.Test/TestPhoneNumberMatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ public void TestIsLatinLetter()
Assert.True(PhoneNumberMatcher.IsLatinLetter('C'));
Assert.True(PhoneNumberMatcher.IsLatinLetter('\u00C9'));
Assert.True(PhoneNumberMatcher.IsLatinLetter('\u0301')); // Combining acute accent
// One letter from each remaining accepted block, so every arm of the range test is
// exercised: these were the blocks no assertion reached.
Assert.True(PhoneNumberMatcher.IsLatinLetter('\u0100')); // Latin Extended-A
Assert.True(PhoneNumberMatcher.IsLatinLetter('\u0180')); // Latin Extended-B
Assert.True(PhoneNumberMatcher.IsLatinLetter('\u1E00')); // Latin Extended Additional
// Punctuation, digits and white-space are not considered "latin letters".
Assert.False(PhoneNumberMatcher.IsLatinLetter(':'));
Assert.False(PhoneNumberMatcher.IsLatinLetter('5'));
Expand Down
17 changes: 9 additions & 8 deletions csharp/PhoneNumbers/PhoneNumberMatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,15 @@ public static bool IsLatinLetter(char letter)
// Combining marks are a subset of non-spacing-mark.
if (!char.IsLetter(letter) && CharUnicodeInfo.GetUnicodeCategory(letter) != UnicodeCategory.NonSpacingMark)
return false;
return
letter <= 0x007F // BASIC_LATIN
|| letter >= 0x0080 && letter <= 0x00FF // LATIN_1_SUPPLEMENT
|| letter >= 0x0100 && letter <= 0x017F // LATIN_EXTENDED_A
|| letter >= 0x1E00 && letter <= 0x1EFF // LATIN_EXTENDED_ADDITIONAL
|| letter >= 0x0180 && letter <= 0x024F // LATIN_EXTENDED_B
|| letter >= 0x0300 && letter <= 0x036F // COMBINING_DIACRITICAL_MARKS
;
// The Unicode blocks Java's isLatinLetter() accepts, expressed as the code point
// ranges that define them (C# has no Character.UnicodeBlock equivalent).
return letter is
<= '\u007F' // BASIC_LATIN
or (>= '\u0080' and <= '\u00FF') // LATIN_1_SUPPLEMENT
or (>= '\u0100' and <= '\u017F') // LATIN_EXTENDED_A
or (>= '\u1E00' and <= '\u1EFF') // LATIN_EXTENDED_ADDITIONAL
or (>= '\u0180' and <= '\u024F') // LATIN_EXTENDED_B
or (>= '\u0300' and <= '\u036F'); // COMBINING_DIACRITICAL_MARKS
}

private static bool IsInvalidPunctuationSymbol(char character)
Expand Down