44 lines
1.3 KiB
Ziran
44 lines
1.3 KiB
Ziran
// ASCII-only case folding keeps the result identical across native targets
|
|
// and the engine. UTF-8 bytes outside ASCII compare unchanged.
|
|
#program_export
|
|
LowerASCII :: (value: u8) -> u8 {
|
|
if value >= cast(u8)65 && value <= cast(u8)90 {
|
|
return value + cast(u8)32
|
|
}
|
|
return value
|
|
}
|
|
|
|
#program_export
|
|
StartsWithFoldASCII :: (value: string, prefix: string) -> bool {
|
|
if (cast(s32)prefix.count) > (cast(s32)value.count) { return false }
|
|
index: s32 = 0
|
|
while index < (cast(s32)prefix.count) {
|
|
if LowerASCII(value[index]) != LowerASCII(prefix[index]) {
|
|
return false
|
|
}
|
|
index = index + 1
|
|
}
|
|
return true
|
|
}
|
|
|
|
#program_export
|
|
ContainsFoldASCII :: (value: string, needle: string) -> bool {
|
|
if (cast(s32)needle.count) == 0 { return true }
|
|
if (cast(s32)needle.count) > (cast(s32)value.count) { return false }
|
|
start: s32 = 0
|
|
while start <= (cast(s32)value.count) - (cast(s32)needle.count) {
|
|
index: s32 = 0
|
|
same: bool = true
|
|
while index < (cast(s32)needle.count) {
|
|
if LowerASCII(value[start + index]) != LowerASCII(needle[index]) {
|
|
same = false
|
|
break
|
|
}
|
|
index = index + 1
|
|
}
|
|
if same { return true }
|
|
start = start + 1
|
|
}
|
|
return false
|
|
}
|