CSML-by-Clevy / csml-engine

CSML is an easy-to-use chatbot programming language and framework.

Home Page:https://csml.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

String methods: .slice(), .capitalize()

frsechet opened this issue · comments

Is your feature request related to a problem? Please describe.
It's quite hard to manipulate strings as they are currently not iterable.

Describe the solution you'd like
.slice(start, count) similar to the JS version of str.slice(): https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/String/slice
(careful for multibyte strings, unicode etc.)

.capitalize(): change the first letter to uppercase

Describe alternatives you've considered
It's recodable with native CSML code but it's quite cumbersome! For example:

fn capitalize(str):
  do acc = []
  do first = false
  foreach (letter) in str.split("") {
    if (!letter.length()) continue
    if (!first) do acc.push(letter.to_uppercase())
    else do acc.push(letter)
    do first = true
  }
  return acc.join("")