Mercurial > repos > tabletprog
annotate samples/stringops.tp @ 356:3b023e5a0b42
llcompile almost working well enough for fib sample
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 15 Apr 2015 23:03:24 -0700 |
parents | 056b8ad76559 |
children |
rev | line source |
---|---|
43
27a2167663dd
Improve compiler error reporting. Fix operator associativity. Add some more string operations and a string ops sample
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 #{ |
27a2167663dd
Improve compiler error reporting. Fix operator associativity. Add some more string operations and a string ops sample
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 main <- { |
27a2167663dd
Improve compiler error reporting. Fix operator associativity. Add some more string operations and a string ops sample
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 print: "foo: " . 42 . "\n" |
27a2167663dd
Improve compiler error reporting. Fix operator associativity. Add some more string operations and a string ops sample
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 print: (string: (length: "foo" . "bar")) . "\n" |
150
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
5 print: (string: ("foobarbaz" find: "foo" else: { "not found" })) . "\n" |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
6 print: (string: ("foobarbaz" find: "bar" else: { "not found" })) . "\n" |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
7 print: (string: ("foobarbaz" find: "baz" else: { "not found" })) . "\n" |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
8 print: (string: ("foobarbaz" find: "qux" else: { "not found" })) . "\n" |
151
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
9 |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
10 print: ("foobarbaz" from: 3) . "\n" |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
11 print: ("foobarbaz" from: 3 withLength: 3) . "\n" |
152
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
12 |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
13 foreach: ("foo,bar,baz,qux" splitOn: ",") :idx val { |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
14 print: val . "\n" |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
15 } |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
16 |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
17 res <- "foobarbaz" partitionOn: "bar" |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
18 print: "Before: " . (res before) . "\n" |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
19 print: "After: " . (res after) . "\n" |
158
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
20 |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
21 print: (string: ("12abcDEF" parseHex32)) . "\n" |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
22 print: (string: ("FFFFFFFFFF" parseHex64)) . "\n" |
259
32964a4e7a33
Add ltrim method to string
Michael Pavone <pavone@retrodev.com>
parents:
158
diff
changeset
|
23 print: "'" . (" \nfoobar baz " ltrim) . "'\n" |
307
056b8ad76559
Add a couple more trim cases to strinops sample
Michael Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
24 print: "'" . (" \nfoobar baz " trim) . "'\n" |
056b8ad76559
Add a couple more trim cases to strinops sample
Michael Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
25 print: "'" . (" \n\t\r" trim) . "'\n" |
288
a4c2b31acba7
Add utf8 method to integer types for converting a number into a utf8 string made up of the corresponding character code
Michael Pavone <pavone@retrodev.com>
parents:
259
diff
changeset
|
26 print: (72 utf8) . (101 utf8) . (108 utf8) . (108 utf8) . (111 utf8) . (0x1F604 utf8) . "\n" |
43
27a2167663dd
Improve compiler error reporting. Fix operator associativity. Add some more string operations and a string ops sample
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 } |
27a2167663dd
Improve compiler error reporting. Fix operator associativity. Add some more string operations and a string ops sample
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 } |