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 twofour methods extend the casing performed by the corresponding 'Str' methods to include
Latin Extended-A, Greek,parts Cyrillic,of ArmenianLatin Extended-B, GeorgianLatin andExtended aAdditional, fewGreek, other Latin characters. */Cyrillic,
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 == 0x17D)0x017D {||
} else if ( c == 0x01A0 || c == 0x02190x01AF || c == 0x021B0x01F4) {
chars[i] = String.fromCodePoint(c + 1)
} else if (c == 0x01FE0x01C4 || c == 0x01C7 || c == 0x01CA || c == 0x01F1) {
chars[i] = "ǿ"String.fromCodePoint(c + 2)
} else if (c == 0x02180x01C5 || c == 0x021A0x01C8 || c == 0x01CB || c == 0x01F2) {
chars[i] = String.fromCodePoint(c + 1)
} else if ((c =>= 0x1E800x01DE ||&& c =<= 0x1E820x01EE) ||&& (c % 2 == 0x1E840)) {
chars[i] = "Ǿ"String.fromCodePoint(c + 1)
} else if ((c >= 0x01F8 && c <= 0x021E) && (c % 2 == 0x1EF30)) {
chars[i] = "Ỳ"String.fromCodePoint(c + 1)
} 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 == 0x1EF20)) {
chars[i] = "ỳ"String.fromCodePoint(c + 1)
} 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 == 0x01FF0x01F2)) {
chars[i] = "Ǿ"
} else if (c == 0x0219 || c == 0x021B) {
chars[i] = String.fromCodePoint(c - 1)
} else if (c == 0x1E810x01C6 || c == 0x1E830x01C9 || c == 0x1E850x01CC || c == 0x01F3) {
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, " ")
}
 
9,476

edits