1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 20:42:21 +02:00

Add Startswith & Endswith char32 overload for StringView

This commit is contained in:
disarray2077 2021-08-01 18:47:46 -03:00
parent e5f92fb21b
commit 4061d4b58e

View file

@ -3137,6 +3137,15 @@ namespace System
return Ptr[0] == c;
}
public bool StartsWith(char32 c)
{
if (c < '\x80')
return StartsWith((char8)c);
if (mLength == 0)
return false;
return UTF8.Decode(Ptr, mLength).c == c;
}
public bool EndsWith(char8 c)
{
if (mLength == 0)
@ -3144,6 +3153,19 @@ namespace System
return Ptr[mLength - 1] == c;
}
public bool EndsWith(char32 c)
{
if (c < '\x80')
return EndsWith((char8)c);
if (mLength == 0)
return false;
char8* ptr = Ptr;
int idx = mLength - 1;
while ((idx > 0) && ((uint8)ptr[idx] & 0xC0 == 0x80))
idx--;
return UTF8.Decode(ptr + idx, mLength - idx).c == c;
}
public void QuoteString(String outString)
{
String.QuoteString(Ptr, Length, outString);