Skip to content

Commit d35693d

Browse files
authored
Merge pull request #521 from alrun3/char-isasciiletter
feat: add `Char.IsAsciiLetter`
2 parents 337d67a + 869b108 commit d35693d

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

CSharp.lua/CoreSystem.Lua/CoreSystem/Char.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ local function get(s, index)
7373
return c
7474
end
7575

76+
local function isAsciiLetter(c)
77+
return (c >= 65 and c <= 90) or (c >= 97 and c <= 122)
78+
end
79+
7680
local function isDigit(c, index)
7781
if index then
7882
c = get(c, index)
@@ -86,7 +90,7 @@ local function isLetter(c, index)
8690
c = get(c, index)
8791
end
8892
if c < 128 then
89-
return (c >= 65 and c <= 90) or (c >= 97 and c <= 122)
93+
return isAsciiLetter(c)
9094
else
9195
return (c >= 0x0400 and c <= 0x042F)
9296
or (c >= 0x03AC and c <= 0x03CE)
@@ -107,6 +111,7 @@ local Char = System.defStc("System.Char", {
107111
EqualsObj = Int.EqualsObj,
108112
GetHashCode = Int.GetHashCode,
109113
default = Int.default,
114+
IsAsciiLetter = isAsciiLetter,
110115
IsControl = function (c, index)
111116
if index then
112117
c = get(c, index)

test/BridgeNetTests/Batch1/src/SimpleTypes/CharTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,5 +329,20 @@ public void IsLetterWithStringAndIndexWorks()
329329
#endif
330330
Assert.False(char.IsLetter("0" + '\u0100', 0), "#10");
331331
}
332+
333+
[Test]
334+
public void IsAsciiLetterWorks()
335+
{
336+
Assert.True(char.IsAsciiLetter('A'), "Should match uppercase letter (first)");
337+
Assert.True(char.IsAsciiLetter('Z'), "Should match uppercase letter (last)");
338+
Assert.True(char.IsAsciiLetter('a'), "Should match lowercase letter (first)");
339+
Assert.True(char.IsAsciiLetter('z'), "Should match lowercase letter (last)");
340+
341+
Assert.False(char.IsAsciiLetter('@'), "Should not match character before 'A'");
342+
Assert.False(char.IsAsciiLetter('['), "Should not match character after 'Z'");
343+
Assert.False(char.IsAsciiLetter('`'), "Should not match character before 'a'");
344+
Assert.False(char.IsAsciiLetter('{'), "Should not match character after 'z'");
345+
Assert.False(char.IsAsciiLetter('0'), "Should not match digit");
346+
}
332347
}
333348
}

0 commit comments

Comments
 (0)