Mercurial > repos > tabletprog
annotate modules/string.tp @ 152:a6739206a9e3
Add splitOn and partitionOn to string objects
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 09 Aug 2013 20:12:04 -0700 |
parents | 3e9cb69e516d |
children | 6e579a75a0a9 |
rev | line source |
---|---|
88
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 #{ |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 llProperty: len withType: uint32_t |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 llProperty: bytes withType: uint32_t |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 llProperty: data withType: (char ptr) |
147
4c96a393103e
Add support for receiving data from a socket
Mike Pavone <pavone@retrodev.com>
parents:
88
diff
changeset
|
5 |
88
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 llMessage: length withVars: { |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 intret <- (obj_int32 ptr) |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 } andCode: { |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 intret <- make_object: (addr_of: obj_int32_meta) NULL 0 |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 intret num!: len |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 intret |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 } |
147
4c96a393103e
Add support for receiving data from a socket
Mike Pavone <pavone@retrodev.com>
parents:
88
diff
changeset
|
13 |
88
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 llMessage: byte_length withVars: { |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 intret <- (obj_int32 ptr) |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 } andCode: { |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 intret <- make_object: (addr_of: obj_int32_meta) NULL 0 |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 intret num!: bytes |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 intret |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 } |
147
4c96a393103e
Add support for receiving data from a socket
Mike Pavone <pavone@retrodev.com>
parents:
88
diff
changeset
|
21 |
88
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 llMessage: EQ_ withVars: { |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 argb <- (string ptr) |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 } andCode: :argb { |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 if: len = (argb len) && bytes = (argb bytes) && (not: (memcmp: data (argb data) bytes)) { |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 true |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 } |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 } |
147
4c96a393103e
Add support for receiving data from a socket
Mike Pavone <pavone@retrodev.com>
parents:
88
diff
changeset
|
29 |
88
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 llMessage: NEQ_ withVars: { |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
31 argb <- (string ptr) |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
32 } andCode: :argb { |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
33 if: len != (argb len) || bytes != (argb bytes) || (memcmp: data (argb data) bytes) { |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
34 true |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
35 } |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
36 } |
147
4c96a393103e
Add support for receiving data from a socket
Mike Pavone <pavone@retrodev.com>
parents:
88
diff
changeset
|
37 |
88
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
38 llMessage: print withVars: {} andCode: { |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
39 fwrite: data 1 bytes stdout |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
40 self |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
41 } |
147
4c96a393103e
Add support for receiving data from a socket
Mike Pavone <pavone@retrodev.com>
parents:
88
diff
changeset
|
42 |
88
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
43 llMessage: string withVars: {} andCode: { |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
44 self |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
45 } |
147
4c96a393103e
Add support for receiving data from a socket
Mike Pavone <pavone@retrodev.com>
parents:
88
diff
changeset
|
46 |
88
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
47 llMessage: CAT_ withVars: { |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
48 argbo <- (object ptr) |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
49 argb <- (string ptr) |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
50 out <- (string ptr) |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
51 } andCode: :argbo { |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
52 argb <- mcall: string 1 argbo |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
53 out <- make_object: (addr_of: string_meta) NULL 0 |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
54 out bytes!: bytes + (argb bytes) |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
55 out len!: len + (argb len) |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
56 out data!: (GC_MALLOC_ATOMIC: (out bytes) + 1) |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
57 memcpy: (out data) data bytes |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
58 memcpy: (out data) + bytes (argb data) (argb bytes) + 1 |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
59 out |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
60 } |
147
4c96a393103e
Add support for receiving data from a socket
Mike Pavone <pavone@retrodev.com>
parents:
88
diff
changeset
|
61 |
88
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
62 llMessage: byte withVars: { |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
63 index <- (obj_int32 ptr) |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
64 intret <- (obj_int32 ptr) |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
65 } andCode: :index { |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
66 intret <- make_object: (addr_of: obj_int32_meta) NULL 0 |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
67 intret num!: (if: (index num) < bytes { data get: (index num) } else: {0}) |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
68 intret |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
69 } |
147
4c96a393103e
Add support for receiving data from a socket
Mike Pavone <pavone@retrodev.com>
parents:
88
diff
changeset
|
70 |
88
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
71 llMessage: int32 withVars: { |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
72 intret <- (obj_int32 ptr) |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
73 } andCode: { |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
74 intret <- make_object: (addr_of: obj_int32_meta) NULL 0 |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
75 intret num!: (atoi: data) |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
76 intret |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
77 } |
147
4c96a393103e
Add support for receiving data from a socket
Mike Pavone <pavone@retrodev.com>
parents:
88
diff
changeset
|
78 |
88
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
79 llMessage: hash withVars: { |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
80 intret <- (obj_int32 ptr) |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
81 i <- uint32_t |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
82 } andCode: { |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
83 intret <- make_object: (addr_of: obj_int32_meta) NULL 0 |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
84 intret num!: 0 |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
85 if: bytes { |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
86 intret num!: (data get: 0) * 128 |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
87 i <- 0 |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
88 while: { i < bytes } do: { |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
89 intret num!: (1000003 * (intret num)) xor (data get: i) |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
90 i <- i + 1 |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
91 } |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
92 intret num!: (intret num) xor bytes |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
93 } |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
94 intret |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
95 } |
147
4c96a393103e
Add support for receiving data from a socket
Mike Pavone <pavone@retrodev.com>
parents:
88
diff
changeset
|
96 |
150
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
97 llMessage: find:else withVars: { |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
98 intret <- obj_int32 ptr |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
99 oneedle <- object ptr |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
100 ifNotFound <- object ptr |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
101 sneedle <- string ptr |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
102 i <- uint32_t |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
103 notFound <- uint32_t |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
104 } andCode: :oneedle :ifNotFound { |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
105 sneedle <- mcall: string 1 oneedle |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
106 i <- 0 |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
107 notFound <- 1 |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
108 while: { notFound && i + (sneedle bytes) <= bytes} do: { |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
109 if: (memcmp: data + i (sneedle data) (sneedle bytes)) = 0 { |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
110 notFound <- 0 |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
111 } else: { |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
112 i <- i + 1 |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
113 } |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
114 } |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
115 if: notFound { |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
116 ccall: ifNotFound 0 |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
117 } else: { |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
118 intret <- make_object: (addr_of: obj_int32_meta) NULL 0 |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
119 intret num!: i |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
120 intret |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
121 } |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
122 } |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
123 |
151
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
124 llMessage: from:withLength withVars: { |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
125 from <- obj_int32 ptr |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
126 tocopy <- obj_int32 ptr |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
127 ret <- string ptr |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
128 start <- int32_t |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
129 clampedLen <- int32_t |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
130 } andCode: :from :tocopy { |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
131 start <- from num |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
132 if: start < 0 { |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
133 start <- bytes + start |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
134 } |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
135 if: start > bytes { |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
136 start <- bytes |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
137 } |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
138 clampedLen <- tocopy num |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
139 if: start + clampedLen > bytes { |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
140 clampedLen <- bytes - start |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
141 } |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
142 ret <- make_object: (addr_of: string_meta) NULL 0 |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
143 ret data!: (GC_MALLOC_ATOMIC: clampedLen + 1) |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
144 memcpy: (ret data) data + start clampedLen |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
145 ret len!: clampedLen |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
146 ret bytes!: clampedLen |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
147 ret |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
148 } |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
149 |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
150 from <- :start { |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
151 from: start withLength: length |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
152 } |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
153 |
152
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
154 partitionOn <- :delim { |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
155 pos <- find: delim else: { -1 } |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
156 if: pos >= 0 { |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
157 _before <- from: 0 withLength: pos |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
158 _after <- from: (pos + (delim length)) |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
159 #{ |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
160 before <- _before |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
161 after <- _after |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
162 } |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
163 } else: { |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
164 _before <- self |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
165 #{ |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
166 before <- _before |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
167 after <- "" |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
168 } |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
169 } |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
170 } |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
171 |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
172 splitOn <- :delim { |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
173 pos <- 0 |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
174 pieces <- #[] |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
175 while: { |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
176 pos <- find: delim else: { -1 } |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
177 pos >= 0 |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
178 } do: { |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
179 pieces append: (from: 0 withLength: pos) |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
180 self <- from: pos + (delim length) |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
181 } |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
182 pieces append: self |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
183 } |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
184 |
147
4c96a393103e
Add support for receiving data from a socket
Mike Pavone <pavone@retrodev.com>
parents:
88
diff
changeset
|
185 isInteger? <- { false } |
88
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
186 } |