Category talk:Wren-str: Difference between revisions

→‎Source code: Added 'lower' and 'upper' methods to Utf8 class.
(→‎Source code: Added Str.occurs method.)
(→‎Source code: Added 'lower' and 'upper' methods to Utf8 class.)
Line 722:
return (b0 & b4Mask) << 18 | (b[1] & mbMask) << 12 | (b[2] & mbMask) << 6 | (b[3] & mbMask)
}
}
 
/* The next two methods extend the casing performed by the corresponding 'Str' methods to include
Latin Extended-A, Greek, Cyrillic, Armenian, Georgian and a few other Latin characters. */
 
// Converts a UTF-8 string to lower case.
static lower(s) {
if (!(s is String)) s = "%(s)"
if (s == "") return s
var chars = s.toList
var count = chars.count
var i = 0
for (c in s.codePoints) {
if ((c >= 65 && c <= 90) || (c >= 192 && c <= 214) || (c >= 216 && c <= 222)) {
chars[i] = String.fromCodePoint(c + 32)
} else if (c < 256) {
// catch other Latin-1 characters quickly.
} else if ((c >= 0x0100 && c <= 0x0136) && (c % 2 == 0)) {
chars[i] = String.fromCodePoint(c + 1)
} else if ((c >= 0x0139 && c <= 0x0147) && (c % 2 == 1)) {
chars[i] = String.fromCodePoint(c + 1)
} else if ((c >= 0x014A && c <= 0x0176) && (c % 2 == 0)) {
chars[i] = String.fromCodePoint(c + 1)
} else if (c == 0x0178) {
chars[i] = "ÿ"
} else if (c == 0x0179 || c == 0x017B || c == 0x17D) {
chars[i] = String.fromCodePoint(c + 1)
} else if (c == 0x01FE) {
chars[i] = "ǿ"
} else if (c == 0x0218 || c == 0x021A) {
chars[i] = String.fromCodePoint(c + 1)
} else if (c == 0x1E80 || c == 0x1E82 || c == 0x1E84) {
chars[i] = String.fromCodePoint(c + 1)
} else if (c == 0x1E9E) {
chars[i] = "ß"
} else if (c == 0x1EF2) {
chars[i] = "ỳ"
} else if (c == 0x0386) {
chars[i] = "ά"
} else if (c == 0x0388 || c == 0x0389 || c == 0x038A) {
chars[i] = String.fromCodePoint(c + 37)
} else if (c == 0x038C) {
chars[i] = "ό"
} else if (c == 0x038E || c == 0x038F) {
chars[i] = String.fromCodePoint(c + 63)
} else if (c >= 0x0391 && c <= 0x03A1) {
chars[i] = String.fromCodePoint(c + 32)
} else if (c == 0x03A3) {
chars[i] = (i == count - 1) ? "ς" : "σ"
} else if (c >= 0x03A4 && c <= 0x03AB) {
chars[i] = String.fromCodePoint(c + 32)
} else if (c >= 0x0400 && c <= 0x041F) {
chars[i] = String.fromCodePoint(c + 80)
} else if (c >= 0x0410 && c <= 0x042F) {
chars[i] = String.fromCodePoint(c + 32)
} else if ((c >= 0x048A && c <= 0x04BE) && (c % 2 == 0)) {
chars[i] = String.fromCodePoint(c + 1)
} else if ((c >= 0x04C1 && c <= 0x04CD) && (c % 2 == 1)) {
chars[i] = String.fromCodePoint(c + 1)
} else if ((c >= 0x04D0 && c <= 0x052E) && (c % 2 == 0)) {
chars[i] = String.fromCodePoint(c + 1)
} else if (c >= 0x0531 && c <= 0x0556) {
chars[i] = String.fromCodePoint(c + 48)
} else if (c >= 0x10A0 && c <= 0x10C5) {
chars[i] = String.fromCodePoint(c + 48)
}
i = i + 1
}
return (count < 1000) ? Strs.concat_(chars) : Strs.concat(chars, 1000)
}
 
// Converts a UTF-8 string to upper case.
static upper(s) {
if (!(s is String)) s = "%(s)"
if (s == "") return s
var chars = s.toList
var count = chars.count
var i = 0
for (c in s.codePoints) {
if ((c >= 97 && c <= 122) || (c >= 224 && c <= 246) || (c >= 248 && c <= 254)) {
chars[i] = String.fromCodePoint(c - 32)
} else if (c == 223) {
chars[i] = "ẞ"
} else if (c == 255) {
chars[i] = "Ŷ"
} else if (c < 255) {
// catch other Latin-1 characters quickly.
} else if ((c >= 0x0101 && c <= 0x0137) && (c % 2 == 1)) {
chars[i] = String.fromCodePoint(c - 1)
} else if ((c >= 0x013A && c <= 0x0148) && (c % 2 == 0)) {
chars[i] = String.fromCodePoint(c - 1)
} else if ((c >= 0x014B && c <= 0x0177) && (c % 2 == 1)) {
chars[i] = String.fromCodePoint(c - 1)
} else if (c == 0x017A || c == 0x017C || c == 0x017E) {
chars[i] = String.fromCodePoint(c - 1)
} else if (c == 0x01FF) {
chars[i] = "Ǿ"
} else if (c == 0x0219 || c == 0x021B) {
chars[i] = String.fromCodePoint(c - 1)
} else if (c == 0x1E81 || c == 0x1E83 || c == 0x1E85) {
chars[i] = String.fromCodePoint(c - 1)
} else if (c == 0x1EF3) {
chars[i] = "Ỳ"
} else if (c == 0x03AC) {
chars[i] = "Ά"
} else if (c == 0x03AD || c == 0x03AE || c == 0x03AF) {
chars[i] = String.fromCodePoint(c - 37)
} else if (c >= 0x03B1 && c <= 0x03C1) {
chars[i] = String.fromCodePoint(c - 32)
} else if (c == 0x03C2) {
chars[i] = "Σ"
} else if (c >= 0x03C3 && c <= 0x03CB) {
chars[i] = String.fromCodePoint(c - 32)
} else if (c == 0x03CC) {
chars[i] = "Ό"
} else if (c == 0x03CD || c == 0x03CE) {
chars[i] = String.fromCodePoint(c - 63)
} else if (c >= 0x0430 && c <= 0x044F) {
chars[i] = String.fromCodePoint(c - 32)
} else if (c >= 0x0450 && c <= 0x045F) {
chars[i] = String.fromCodePoint(c - 80)
} else if ((c >= 0x048B && c <= 0x04BF) && (c % 2 == 1)) {
chars[i] = String.fromCodePoint(c - 1)
} else if ((c >= 0x04C2 && c <= 0x04CE) && (c % 2 == 0)) {
chars[i] = String.fromCodePoint(c - 1)
} else if ((c >= 0x04D1 && c <= 0x052F) && (c % 2 == 1)) {
chars[i] = String.fromCodePoint(c - 1)
} else if (c >= 0x0561 && c <= 0x0586) {
chars[i] = String.fromCodePoint(c - 48)
} else if (c >= 0x10D0 && c <= 0x10F5) {
chars[i] = String.fromCodePoint(c - 48)
}
i = i + 1
}
return (count < 1000) ? Strs.concat_(chars) : Strs.concat(chars, 1000)
}
 
9,476

edits