Category talk:Wren-str: Difference between revisions
Content added Content deleted
(→Source code: Adjustments mostly to extend case change methods to Latin-1 (ASCII only previously).) |
(Added Str.fromBytes and Str.fromCodePoints methods. Removed type aliases which are no longer needed.) |
||
Line 268: | Line 268: | ||
} |
} |
||
/* The indices (or ranges thereof) for all the following functions are measured in codepoints |
/* The indices (or ranges thereof) for all the following functions are measured in codepoints |
||
(not bytes). Negative indices count backwards from the end of the string. As with core |
|||
library methods, the indices must be within bounds or errors will be generated. */ |
|||
// Extracts the sub-string of 's' over the range 'r'. |
// Extracts the sub-string of 's' over the range 'r'. |
||
Line 425: | Line 426: | ||
if (final > 0) res.add(sub(s, first..-1)) |
if (final > 0) res.add(sub(s, first..-1)) |
||
return res |
return res |
||
} |
|||
// Creates and returns a string from a list of bytes. |
|||
static fromBytes(ba) { |
|||
if (!(ba is List)) Fiber.abort("Argument must be list of bytes.") |
|||
var count = ba.count |
|||
if (count == 0) return "" |
|||
var chars = ba.map { |b| String.fromByte(b) }.toList |
|||
return (count < 1000) ? Strs.concat_(chars) : Strs.concat(chars, 1000) |
|||
} |
|||
// Creates and returns a string from a list of code points. |
|||
static fromCodePoints(ca) { |
|||
if (!(ca is List)) Fiber.abort("Argument must be list of code points.") |
|||
var count = ca.count |
|||
if (count == 0) return "" |
|||
var chars = ca.map { |c| String.fromCodePoint(c) }.toList |
|||
return (count < 1000) ? Strs.concat_(chars) : Strs.concat(chars, 1000) |
|||
} |
} |
||
} |
} |
||
Line 553: | Line 572: | ||
} |
} |
||
} |
} |
||
}</lang> |
|||
} |
|||
// Type aliases for classes in case of any name clashes with other modules. |
|||
var Str_Char = Char |
|||
var Str_Str = Str |
|||
var Str_Strs = Strs |
|||
var Str_Utf8 = Utf8</lang> |