scoop:scoop.std:0.1.0
src/text/ascii.scoop
Selected production source · src/text/ascii.scoop
1
package scoop.text3
private fun String.convertAscii(uppercase: Boolean): String {4
val chars = toMutableCharArray()5
var index = 0L6
while (index < chars.size) {7
val code = chars[index].code8
if (uppercase && code >= 97 && code <= 122) chars[index] = (code - 32).toChar()9
if (!uppercase && code >= 65 && code <= 90) chars[index] = (code + 32).toChar()10
index += 1L11
}12
return String.fromChars(chars)13
}15
/**16
* Maps ASCII A-Z to a-z, leaving all other Unicode scalars unchanged.17
*/18
public fun String.lowercaseAscii(): String = convertAscii(false)19
/**20
* Maps ASCII a-z to A-Z, leaving all other Unicode scalars unchanged.21
*/22
public fun String.uppercaseAscii(): String = convertAscii(true)