Category talk:Wren-str: Difference between revisions
→Source code: Improved the coverage of the 'lower' and 'upper' methods and added 'capitalize' and 'title' methods to the Utf8 class.
(→Source code: Added 'lower' and 'upper' methods to Utf8 class.) |
(→Source code: Improved the coverage of the 'lower' and 'upper' methods and added 'capitalize' and 'title' methods to the Utf8 class.) |
||
Line 724:
}
/* The next
Latin Extended-A,
Armenian and Georgian. */
// Converts a UTF-8 string to lower case.
Line 747 ⟶ 748:
} else if (c == 0x0178) {
chars[i] = "ÿ"
} else if (c == 0x0179 || c == 0x017B || c ==
chars[i] = String.fromCodePoint(c + 1)
} else if (c ==
chars[i] =
} else if (c ==
chars[i] = String.fromCodePoint(c + 1)
} else if ((c
} else if ((c >= 0x1E00 && c <= 0x1E94) && (c % 2 == 0)) {
chars[i] = String.fromCodePoint(c + 1)
} else if (c == 0x1E9E) {
chars[i] = "ß"
} else if ((c >= 0x1EA0 && c <= 0x1EFE) && (c % 2 ==
chars[i] =
} else if (c == 0x0386) {
chars[i] = "ά"
Line 794 ⟶ 800:
// Converts a UTF-8 string to upper case.
// Automatically uses title case for the first character if it's one of 4 supported digraphs.
static upper(s) {
if (!(s is String)) s = "%(s)"
Line 815 ⟶ 822:
} else if ((c >= 0x014B && c <= 0x0177) && (c % 2 == 1)) {
chars[i] = String.fromCodePoint(c - 1)
} else if (c == 0x017A || c == 0x017C || c == 0x017E
c == 0x01A1 || c == 0x01B0 || c == 0x01F5) {
chars[i] = String.fromCodePoint(c - 1)
} else if ((i > 0) && (c == 0x01C5 || c == 0x01C8 || c == 0x01CB || c ==
▲ chars[i] = "Ǿ"
▲ } else if (c == 0x0219 || c == 0x021B) {
chars[i] = String.fromCodePoint(c - 1)
} else if (c ==
chars[i] = String.fromCodePoint((i > 0) ? c - 2 : c - 1)
} else if ((c >= 0x01DF && c <= 0x01EF) && (c % 2 == 1)) {
chars[i] = String.fromCodePoint(c - 1)
} else if ((c >= 0x01F9 && c <= 0x021F) && (c % 2 == 1)) {
chars[i] = String.fromCodePoint(c - 1)
} else if ((c >= 0x1E01 && c <= 0x1E95) && (c % 2 == 1)) {
chars[i] = String.fromCodePoint(c - 1)
} else if (c == 0x1E9E) {
chars[i] = "ß"
} else if ((c >= 0x1EA1 && c <= 0x1EFF) && (c % 2 == 1)) {
chars[i] = String.fromCodePoint(c - 1)
▲ } else if (c == 0x1EF3) {
▲ chars[i] = "Ỳ"
} else if (c == 0x03AC) {
chars[i] = "Ά"
Line 857 ⟶ 871:
}
return (count < 1000) ? Strs.concat_(chars) : Strs.concat(chars, 1000)
}
// Capitalizes the first character of a UTF-8 string.
static capitalize(s) {
if (!(s is String)) s = "%(s)"
if (s == "") return s
var start = (s.startsWith("[") && s.count > 1) ? 1 : 0
var cs = upper(s[start])
if (s.count > start + 1) cs = cs + s[start+1..-1]
if (start == 1) cs = "[" + cs
return cs
}
// Capitalizes the first character of each word of a UTF-8 string.
static title(s) {
if (!(s is String)) s = "%(s)"
if (s == "") return s
var words = s.split(" ")
return Strs.join(words.map { |w| capitalize(w) }.toList, " ")
}
|