Add lowercase and uppercase string functions, update documentation accordingly.

This commit is contained in:
Sergey Chernov 2025-12-17 17:59:51 +01:00
parent 5d8fdce637
commit 1aef64e0fa
2 changed files with 41 additions and 25 deletions

View File

@ -1378,31 +1378,31 @@ Part match:
Typical set of String functions includes: Typical set of String functions includes:
| fun/prop | description / notes | | fun/prop | description / notes |
|--------------------|------------------------------------------------------------| |----------------------|------------------------------------------------------------|
| lower() | change case to unicode upper | | lower(), lowercase() | change case to unicode upper |
| upper() | change case to unicode lower | | upper(), uppercase() | change case to unicode lower |
| trim() | trim space chars from both ends | | trim() | trim space chars from both ends |
| startsWith(prefix) | true if starts with a prefix | | startsWith(prefix) | true if starts with a prefix |
| endsWith(prefix) | true if ends with a prefix | | endsWith(prefix) | true if ends with a prefix |
| last() | get last character of a string or throw | | last() | get last character of a string or throw |
| take(n) | get a new string from up to n first characters | | take(n) | get a new string from up to n first characters |
| takeLast(n) | get a new string from up to n last characters | | takeLast(n) | get a new string from up to n last characters |
| drop(n) | get a new string dropping n first chars, or empty string | | drop(n) | get a new string dropping n first chars, or empty string |
| dropLast(n) | get a new string dropping n last chars, or empty string | | dropLast(n) | get a new string dropping n last chars, or empty string |
| size | size in characters like `length` because String is [Array] | | size | size in characters like `length` because String is [Array] |
| (args...) | sprintf-like formatting, see [string formatting] | | (args...) | sprintf-like formatting, see [string formatting] |
| [index] | character at index | | [index] | character at index |
| [Range] | substring at range (2) | | [Range] | substring at range (2) |
| [Regex] | find first match of regex, like [Regex.find] (2) | | [Regex] | find first match of regex, like [Regex.find] (2) |
| s1 + s2 | concatenation | | s1 + s2 | concatenation |
| s1 += s2 | self-modifying concatenation | | s1 += s2 | self-modifying concatenation |
| toReal() | attempts to parse string as a Real value | | toReal() | attempts to parse string as a Real value |
| toInt() | parse string to Int value | | toInt() | parse string to Int value |
| characters() | create [List] of characters (1) | | characters() | create [List] of characters (1) |
| encodeUtf8() | returns [Buffer] with characters encoded to utf8 | | encodeUtf8() | returns [Buffer] with characters encoded to utf8 |
| matches(re) | matches the regular expression (2) | | matches(re) | matches the regular expression (2) |
| | | | | |
(1) (1)
: List is mutable therefore a new copy is created on each call. : List is mutable therefore a new copy is created on each call.

View File

@ -216,6 +216,14 @@ data class ObjString(val value: String) : Obj() {
) { ) {
thisAs<ObjString>().value.lowercase().let(::ObjString) thisAs<ObjString>().value.lowercase().let(::ObjString)
} }
addFnDoc(
name = "lowercase",
doc = "Lowercase version of this string (default locale).",
returns = type("lyng.String"),
moduleName = "lyng.stdlib"
) {
thisAs<ObjString>().value.lowercase().let(::ObjString)
}
addFnDoc( addFnDoc(
name = "upper", name = "upper",
doc = "Uppercase version of this string (default locale).", doc = "Uppercase version of this string (default locale).",
@ -224,6 +232,14 @@ data class ObjString(val value: String) : Obj() {
) { ) {
thisAs<ObjString>().value.uppercase().let(::ObjString) thisAs<ObjString>().value.uppercase().let(::ObjString)
} }
addFnDoc(
name = "uppercase",
doc = "Uppercase version of this string (default locale).",
returns = type("lyng.String"),
moduleName = "lyng.stdlib"
) {
thisAs<ObjString>().value.uppercase().let(::ObjString)
}
addFnDoc( addFnDoc(
name = "characters", name = "characters",
doc = "List of characters of this string.", doc = "List of characters of this string.",