Skip to content

Commit f9a48a2

Browse files
author
Marcel Vilas
committed
stdlib: Added new string function: splt.
1 parent 09fdbcf commit f9a48a2

3 files changed

Lines changed: 34 additions & 2 deletions

File tree

Exscript/stdlib/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
'list.length': list.length,
6565
'list.unique': list.unique,
6666
'string.replace': string.replace,
67+
'string.split': string.split,
6768
'string.tolower': string.tolower,
6869
'string.toupper': string.toupper,
6970
'sys.env': mysys.env,

Exscript/stdlib/string.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,26 @@ def replace(scope, strings, source, dest):
4040
"""
4141
return [s.replace(source[0], dest[0]) for s in strings]
4242

43+
@secure_function
44+
def split(scope, strings, separator):
45+
"""
46+
Returns a list with the split values of the given string (or list of strings).
47+
The values are split at the seperator
48+
49+
:type strings: string
50+
:param strings: A string, or a list of strings.
51+
:type source: string
52+
:param source: What to replace.
53+
:type dest: string
54+
:param dest: What to replace it with.
55+
:rtype: string
56+
:return: The resulting string, or list of strings.
57+
"""
58+
result = []
59+
for s in strings:
60+
result.extend(s.split(separator[0]))
61+
return result
62+
4363

4464
@secure_function
4565
def tolower(scope, strings):

tests/templates/stdlib.string/test.exscript

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22
string = string.replace("ssuccessss", "ss", "s")
33
fail "string.otp" if string is not "success"
44

5-
string = string.tolower("LOWER")
6-
fail "string.otp" if string is not "lower"
5+
string = string.tolower("Low3R")
6+
fail "string.otp" if string is not "low3r"
7+
8+
string = string.toupper("Upp3R")
9+
fail "string.otp" if string is not "UPP3R"
10+
11+
result = list.new()
12+
append "10" to result
13+
append "234" to result
14+
append "65" to result
15+
append "8" to result
16+
string = string.split("10,234,65,8", ",")
17+
fail "string.otp" if string is not result
718
}

0 commit comments

Comments
 (0)