diff --git a/CSharp.lua/CoreSystem.Lua/CoreSystem/Char.lua b/CSharp.lua/CoreSystem.Lua/CoreSystem/Char.lua index b0ae7d24..463d93c2 100644 --- a/CSharp.lua/CoreSystem.Lua/CoreSystem/Char.lua +++ b/CSharp.lua/CoreSystem.Lua/CoreSystem/Char.lua @@ -73,6 +73,10 @@ local function get(s, index) return c end +local function isAsciiLetter(c) + return (c >= 65 and c <= 90) or (c >= 97 and c <= 122) +end + local function isDigit(c, index) if index then c = get(c, index) @@ -86,7 +90,7 @@ local function isLetter(c, index) c = get(c, index) end if c < 128 then - return (c >= 65 and c <= 90) or (c >= 97 and c <= 122) + return isAsciiLetter(c) else return (c >= 0x0400 and c <= 0x042F) or (c >= 0x03AC and c <= 0x03CE) @@ -107,6 +111,7 @@ local Char = System.defStc("System.Char", { EqualsObj = Int.EqualsObj, GetHashCode = Int.GetHashCode, default = Int.default, + IsAsciiLetter = isAsciiLetter, IsControl = function (c, index) if index then c = get(c, index) diff --git a/test/BridgeNetTests/Batch1/src/SimpleTypes/CharTests.cs b/test/BridgeNetTests/Batch1/src/SimpleTypes/CharTests.cs index 530dc424..9880b63a 100644 --- a/test/BridgeNetTests/Batch1/src/SimpleTypes/CharTests.cs +++ b/test/BridgeNetTests/Batch1/src/SimpleTypes/CharTests.cs @@ -329,5 +329,20 @@ public void IsLetterWithStringAndIndexWorks() #endif Assert.False(char.IsLetter("0" + '\u0100', 0), "#10"); } + + [Test] + public void IsAsciiLetterWorks() + { + Assert.True(char.IsAsciiLetter('A'), "Should match uppercase letter (first)"); + Assert.True(char.IsAsciiLetter('Z'), "Should match uppercase letter (last)"); + Assert.True(char.IsAsciiLetter('a'), "Should match lowercase letter (first)"); + Assert.True(char.IsAsciiLetter('z'), "Should match lowercase letter (last)"); + + Assert.False(char.IsAsciiLetter('@'), "Should not match character before 'A'"); + Assert.False(char.IsAsciiLetter('['), "Should not match character after 'Z'"); + Assert.False(char.IsAsciiLetter('`'), "Should not match character before 'a'"); + Assert.False(char.IsAsciiLetter('{'), "Should not match character after 'z'"); + Assert.False(char.IsAsciiLetter('0'), "Should not match digit"); + } } }