blob: 9a6c3f342bd20319c502151cc5c166aa84b561c9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
// Named str to avoid name collisions with the Erlang string module.
// Will rename later once we have namespaces for modules.
import iodata
import list
pub external fn length(String) -> Int = "string" "length"
pub enum ParseError =
| ParseError
pub external fn lowercase(String) -> String = "string" "lowercase"
pub external fn uppercase(String) -> String = "string" "uppercase"
pub fn reverse(string) {
string
|> iodata:new
|> iodata:reverse
|> iodata:to_string
}
pub fn split(string, on) {
string
|> iodata:new
|> iodata:split(_, on)
|> list:map(_, iodata:to_string)
}
pub fn replace(string, pattern, with) {
string
|> iodata:new
|> iodata:replace(_, pattern, with)
|> iodata:to_string
}
pub fn append(s1, s2) {
iodata:new(s1) |> iodata:append(_, s2) |> iodata:to_string(_)
}
|