Mercurial > repos > tabletprog
annotate modules/string.tp @ 331:61f5b794d939
Breaking change: method call syntax now always uses the syntactic receiver as the actual receiver. This makes its behavior different from function call syntax, but solves some problems with methods being shadowed by local variables and the like.
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 28 Mar 2015 14:21:04 -0700 |
parents | 8dbb2d2522a5 |
children | 74cab9b5f2a4 |
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 |
265
d6a4c9e7716e
Remove remapping of most operators
Michael Pavone <pavone@retrodev.com>
parents:
259
diff
changeset
|
22 llMessage: "=" withVars: { |
88
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 |
243
5b830147c1cd
Use a lightweight substring object in a few places in the parser to improve performance for large files.
Mike Pavone <pavone@retrodev.com>
parents:
158
diff
changeset
|
30 llMessage: compareSub withVars: { |
5b830147c1cd
Use a lightweight substring object in a few places in the parser to improve performance for large files.
Mike Pavone <pavone@retrodev.com>
parents:
158
diff
changeset
|
31 argb <- string ptr |
5b830147c1cd
Use a lightweight substring object in a few places in the parser to improve performance for large files.
Mike Pavone <pavone@retrodev.com>
parents:
158
diff
changeset
|
32 myoff <- obj_int32 ptr |
5b830147c1cd
Use a lightweight substring object in a few places in the parser to improve performance for large files.
Mike Pavone <pavone@retrodev.com>
parents:
158
diff
changeset
|
33 boff <- obj_int32 ptr |
5b830147c1cd
Use a lightweight substring object in a few places in the parser to improve performance for large files.
Mike Pavone <pavone@retrodev.com>
parents:
158
diff
changeset
|
34 clen <- obj_int32 ptr |
5b830147c1cd
Use a lightweight substring object in a few places in the parser to improve performance for large files.
Mike Pavone <pavone@retrodev.com>
parents:
158
diff
changeset
|
35 intret <- obj_int32 ptr |
5b830147c1cd
Use a lightweight substring object in a few places in the parser to improve performance for large files.
Mike Pavone <pavone@retrodev.com>
parents:
158
diff
changeset
|
36 } andCode: :argb myoff boff clen { |
5b830147c1cd
Use a lightweight substring object in a few places in the parser to improve performance for large files.
Mike Pavone <pavone@retrodev.com>
parents:
158
diff
changeset
|
37 intret <- make_object: (addr_of: obj_int32_meta) NULL 0 |
5b830147c1cd
Use a lightweight substring object in a few places in the parser to improve performance for large files.
Mike Pavone <pavone@retrodev.com>
parents:
158
diff
changeset
|
38 intret num!: (memcmp: data + (myoff num) (argb data) + (boff num) (clen num)) |
5b830147c1cd
Use a lightweight substring object in a few places in the parser to improve performance for large files.
Mike Pavone <pavone@retrodev.com>
parents:
158
diff
changeset
|
39 intret |
5b830147c1cd
Use a lightweight substring object in a few places in the parser to improve performance for large files.
Mike Pavone <pavone@retrodev.com>
parents:
158
diff
changeset
|
40 } |
5b830147c1cd
Use a lightweight substring object in a few places in the parser to improve performance for large files.
Mike Pavone <pavone@retrodev.com>
parents:
158
diff
changeset
|
41 |
265
d6a4c9e7716e
Remove remapping of most operators
Michael Pavone <pavone@retrodev.com>
parents:
259
diff
changeset
|
42 llMessage: "!=" withVars: { |
88
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
43 argb <- (string ptr) |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
44 } andCode: :argb { |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
45 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
|
46 true |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
47 } |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
48 } |
147
4c96a393103e
Add support for receiving data from a socket
Mike Pavone <pavone@retrodev.com>
parents:
88
diff
changeset
|
49 |
295
9a30510f6e52
Fix trim method on strings
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
50 print <- { |
9a30510f6e52
Fix trim method on strings
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
51 (file stdout) write: self |
88
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
52 self |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
53 } |
147
4c96a393103e
Add support for receiving data from a socket
Mike Pavone <pavone@retrodev.com>
parents:
88
diff
changeset
|
54 |
88
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
55 llMessage: string withVars: {} andCode: { |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
56 self |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
57 } |
147
4c96a393103e
Add support for receiving data from a socket
Mike Pavone <pavone@retrodev.com>
parents:
88
diff
changeset
|
58 |
265
d6a4c9e7716e
Remove remapping of most operators
Michael Pavone <pavone@retrodev.com>
parents:
259
diff
changeset
|
59 llMessage: "." withVars: { |
88
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
60 argbo <- (object ptr) |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
61 argb <- (string ptr) |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
62 out <- (string ptr) |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
63 } andCode: :argbo { |
267 | 64 argb <- (mcall: string 1 argbo) castTo: (string ptr) |
88
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
65 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
|
66 out bytes!: bytes + (argb bytes) |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
67 out len!: len + (argb len) |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
68 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
|
69 memcpy: (out data) data bytes |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
70 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
|
71 out |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
72 } |
147
4c96a393103e
Add support for receiving data from a socket
Mike Pavone <pavone@retrodev.com>
parents:
88
diff
changeset
|
73 |
88
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
74 llMessage: byte withVars: { |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
75 index <- (obj_int32 ptr) |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
76 intret <- (obj_int32 ptr) |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
77 } andCode: :index { |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
78 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
|
79 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
|
80 intret |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
81 } |
147
4c96a393103e
Add support for receiving data from a socket
Mike Pavone <pavone@retrodev.com>
parents:
88
diff
changeset
|
82 |
88
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
83 llMessage: int32 withVars: { |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
84 intret <- (obj_int32 ptr) |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
85 } andCode: { |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
86 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
|
87 intret num!: (atoi: data) |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
88 intret |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
89 } |
147
4c96a393103e
Add support for receiving data from a socket
Mike Pavone <pavone@retrodev.com>
parents:
88
diff
changeset
|
90 |
158
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
91 parseHex32 <- { |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
92 num <- 0u32 |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
93 cur <- 0 |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
94 a <- uint32: ("a" byte: 0) |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
95 A <- uint32: ("A" byte: 0) |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
96 f <- uint32: ("f" byte: 0) |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
97 F <- uint32: ("F" byte: 0) |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
98 zero <- "0" byte: 0 |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
99 nine <- "9" byte: 0 |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
100 while: { cur < byte_length} do: { |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
101 b <- uint32: (byte: cur) |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
102 cur <- cur + 1 |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
103 if: b >= zero && b <= nine { |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
104 num <- num * 16 + (b - zero) |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
105 } else: { |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
106 if: b >= a && b <= f { |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
107 num <- num * 16 + (b - a) + 10u32 |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
108 } else: { |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
109 if: b >= A && b <= F { |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
110 num <- num * 16 + (b - A) + 10u32 |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
111 } else: { |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
112 cur <- byte_length |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
113 } |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
114 } |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
115 } |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
116 } |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
117 num |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
118 } |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
119 |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
120 parseHex64 <- { |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
121 num <- 0u64 |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
122 cur <- 0 |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
123 a <- uint64: ("a" byte: 0) |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
124 A <- uint64: ("A" byte: 0) |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
125 f <- uint64: ("f" byte: 0) |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
126 F <- uint64: ("F" byte: 0) |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
127 zero <- "0" byte: 0 |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
128 nine <- "9" byte: 0 |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
129 while: { cur < byte_length} do: { |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
130 b <- uint64: (byte: cur) |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
131 cur <- cur + 1 |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
132 if: b >= zero && b <= nine { |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
133 num <- num * 16 + (b - zero) |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
134 } else: { |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
135 if: b >= a && b <= f { |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
136 num <- num * 16 + (b - a) + 10u64 |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
137 } else: { |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
138 if: b >= A && b <= F { |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
139 num <- num * 16 + (b - A) + 10u64 |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
140 } else: { |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
141 cur <- byte_length |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
142 } |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
143 } |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
144 } |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
145 } |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
146 num |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
147 } |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
148 |
88
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
149 llMessage: hash withVars: { |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
150 intret <- (obj_int32 ptr) |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
151 i <- uint32_t |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
152 } andCode: { |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
153 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
|
154 intret num!: 0 |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
155 if: bytes { |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
156 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
|
157 i <- 0 |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
158 while: { i < bytes } do: { |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
159 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
|
160 i <- i + 1 |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
161 } |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
162 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
|
163 } |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
164 intret |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
165 } |
147
4c96a393103e
Add support for receiving data from a socket
Mike Pavone <pavone@retrodev.com>
parents:
88
diff
changeset
|
166 |
154
6e579a75a0a9
Add JSON parser and sample
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
167 llMessage: find:startingAt:else withVars: { |
150
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
168 intret <- obj_int32 ptr |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
169 oneedle <- object ptr |
154
6e579a75a0a9
Add JSON parser and sample
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
170 startpos <- obj_int32 ptr |
150
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
171 ifNotFound <- object ptr |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
172 sneedle <- string ptr |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
173 i <- uint32_t |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
174 notFound <- uint32_t |
154
6e579a75a0a9
Add JSON parser and sample
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
175 } andCode: :oneedle :startpos :ifNotFound { |
267 | 176 sneedle <- (mcall: string 1 oneedle) castTo: (string ptr) |
154
6e579a75a0a9
Add JSON parser and sample
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
177 i <- startpos num |
150
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
178 notFound <- 1 |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
179 while: { notFound && i + (sneedle bytes) <= bytes} do: { |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
180 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
|
181 notFound <- 0 |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
182 } else: { |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
183 i <- i + 1 |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
184 } |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
185 } |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
186 if: notFound { |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
187 ccall: ifNotFound 0 |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
188 } else: { |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
189 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
|
190 intret num!: i |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
191 intret |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
192 } |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
193 } |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
194 |
154
6e579a75a0a9
Add JSON parser and sample
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
195 find:else <- :toFind :orElse { |
6e579a75a0a9
Add JSON parser and sample
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
196 find: toFind startingAt: 0 else: orElse |
6e579a75a0a9
Add JSON parser and sample
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
197 } |
6e579a75a0a9
Add JSON parser and sample
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
198 |
151
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
199 llMessage: from:withLength withVars: { |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
200 from <- obj_int32 ptr |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
201 tocopy <- obj_int32 ptr |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
202 ret <- string ptr |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
203 start <- int32_t |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
204 clampedLen <- int32_t |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
205 } andCode: :from :tocopy { |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
206 start <- from num |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
207 if: start < 0 { |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
208 start <- bytes + start |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
209 } |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
210 if: start > bytes { |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
211 start <- bytes |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
212 } |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
213 clampedLen <- tocopy num |
306
8dbb2d2522a5
Fix a crash in from:withLength when given a negative length. Fix a bug in trim that was causing it to give a negative length to from:withLength
Michael Pavone <pavone@retrodev.com>
parents:
305
diff
changeset
|
214 if: clampedLen < 0 { |
8dbb2d2522a5
Fix a crash in from:withLength when given a negative length. Fix a bug in trim that was causing it to give a negative length to from:withLength
Michael Pavone <pavone@retrodev.com>
parents:
305
diff
changeset
|
215 clampedLen <- bytes - clampedLen |
8dbb2d2522a5
Fix a crash in from:withLength when given a negative length. Fix a bug in trim that was causing it to give a negative length to from:withLength
Michael Pavone <pavone@retrodev.com>
parents:
305
diff
changeset
|
216 if: clampedLen < 0 { |
8dbb2d2522a5
Fix a crash in from:withLength when given a negative length. Fix a bug in trim that was causing it to give a negative length to from:withLength
Michael Pavone <pavone@retrodev.com>
parents:
305
diff
changeset
|
217 clampedLen <- 0 |
8dbb2d2522a5
Fix a crash in from:withLength when given a negative length. Fix a bug in trim that was causing it to give a negative length to from:withLength
Michael Pavone <pavone@retrodev.com>
parents:
305
diff
changeset
|
218 } |
8dbb2d2522a5
Fix a crash in from:withLength when given a negative length. Fix a bug in trim that was causing it to give a negative length to from:withLength
Michael Pavone <pavone@retrodev.com>
parents:
305
diff
changeset
|
219 } |
151
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
220 if: start + clampedLen > bytes { |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
221 clampedLen <- bytes - start |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
222 } |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
223 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
|
224 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
|
225 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
|
226 ret len!: clampedLen |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
227 ret bytes!: clampedLen |
305
14b4e540af28
Properly null terminate result of from:withLength
Michael Pavone <pavone@retrodev.com>
parents:
301
diff
changeset
|
228 (ret data) set: clampedLen 0 |
151
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
229 ret |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
230 } |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
231 |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
232 from <- :start { |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
233 from: start withLength: length |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
234 } |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
235 |
152
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
236 partitionOn <- :delim { |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
237 pos <- find: delim else: { -1 } |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
238 if: pos >= 0 { |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
239 _before <- from: 0 withLength: pos |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
240 _after <- from: (pos + (delim length)) |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
241 #{ |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
242 before <- _before |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
243 after <- _after |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
244 } |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
245 } else: { |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
246 _before <- self |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
247 #{ |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
248 before <- _before |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
249 after <- "" |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
250 } |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
251 } |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
252 } |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
253 |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
254 splitOn <- :delim { |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
255 pos <- 0 |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
256 pieces <- #[] |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
257 while: { |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
258 pos <- find: delim else: { -1 } |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
259 pos >= 0 |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
260 } do: { |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
261 pieces append: (from: 0 withLength: pos) |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
262 self <- from: pos + (delim length) |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
263 } |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
264 pieces append: self |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
265 } |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
266 |
259
32964a4e7a33
Add ltrim method to string
Michael Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
267 ltrim <- { |
32964a4e7a33
Add ltrim method to string
Michael Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
268 l <- length |
32964a4e7a33
Add ltrim method to string
Michael Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
269 start <- 0 |
32964a4e7a33
Add ltrim method to string
Michael Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
270 space <- " " byte: 0 |
32964a4e7a33
Add ltrim method to string
Michael Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
271 tab <- "\t" byte: 0 |
32964a4e7a33
Add ltrim method to string
Michael Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
272 nl <- "\n" byte: 0 |
32964a4e7a33
Add ltrim method to string
Michael Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
273 cr <- "\r" byte: 0 |
32964a4e7a33
Add ltrim method to string
Michael Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
274 |
32964a4e7a33
Add ltrim method to string
Michael Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
275 while: { |
32964a4e7a33
Add ltrim method to string
Michael Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
276 if: start < l { |
32964a4e7a33
Add ltrim method to string
Michael Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
277 b <- byte: start |
32964a4e7a33
Add ltrim method to string
Michael Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
278 b = space || b = tab || b = nl || b = cr |
32964a4e7a33
Add ltrim method to string
Michael Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
279 } |
32964a4e7a33
Add ltrim method to string
Michael Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
280 } do: { |
32964a4e7a33
Add ltrim method to string
Michael Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
281 start <- start + 1 |
32964a4e7a33
Add ltrim method to string
Michael Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
282 } |
32964a4e7a33
Add ltrim method to string
Michael Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
283 from: start |
32964a4e7a33
Add ltrim method to string
Michael Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
284 } |
32964a4e7a33
Add ltrim method to string
Michael Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
285 |
157
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
286 trim <- { |
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
287 l <- length |
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
288 start <- 0 |
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
289 space <- " " byte: 0 |
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
290 tab <- "\t" byte: 0 |
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
291 nl <- "\n" byte: 0 |
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
292 cr <- "\r" byte: 0 |
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
293 |
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
294 while: { |
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
295 if: start < l { |
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
296 b <- byte: start |
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
297 b = space || b = tab || b = nl || b = cr |
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
298 } |
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
299 } do: { |
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
300 start <- start + 1 |
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
301 } |
306
8dbb2d2522a5
Fix a crash in from:withLength when given a negative length. Fix a bug in trim that was causing it to give a negative length to from:withLength
Michael Pavone <pavone@retrodev.com>
parents:
305
diff
changeset
|
302 end <- l - 1 |
157
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
303 while: { |
306
8dbb2d2522a5
Fix a crash in from:withLength when given a negative length. Fix a bug in trim that was causing it to give a negative length to from:withLength
Michael Pavone <pavone@retrodev.com>
parents:
305
diff
changeset
|
304 if: end > start { |
8dbb2d2522a5
Fix a crash in from:withLength when given a negative length. Fix a bug in trim that was causing it to give a negative length to from:withLength
Michael Pavone <pavone@retrodev.com>
parents:
305
diff
changeset
|
305 b <- byte: end |
157
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
306 b = space || b = tab || b = nl || b = cr |
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
307 } |
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
308 } do: { |
295
9a30510f6e52
Fix trim method on strings
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
309 end <- end - 1 |
157
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
310 } |
306
8dbb2d2522a5
Fix a crash in from:withLength when given a negative length. Fix a bug in trim that was causing it to give a negative length to from:withLength
Michael Pavone <pavone@retrodev.com>
parents:
305
diff
changeset
|
311 from: start withLength: (end + 1 - start) |
157
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
312 } |
301
5d24b3117aa7
Add startsWith? to string
Michael Pavone <pavone@retrodev.com>
parents:
295
diff
changeset
|
313 |
5d24b3117aa7
Add startsWith? to string
Michael Pavone <pavone@retrodev.com>
parents:
295
diff
changeset
|
314 startsWith? <- :prefix { |
5d24b3117aa7
Add startsWith? to string
Michael Pavone <pavone@retrodev.com>
parents:
295
diff
changeset
|
315 if: (prefix length) <= length { |
5d24b3117aa7
Add startsWith? to string
Michael Pavone <pavone@retrodev.com>
parents:
295
diff
changeset
|
316 0 = (compareSub: prefix 0 0 (prefix length)) |
5d24b3117aa7
Add startsWith? to string
Michael Pavone <pavone@retrodev.com>
parents:
295
diff
changeset
|
317 } |
5d24b3117aa7
Add startsWith? to string
Michael Pavone <pavone@retrodev.com>
parents:
295
diff
changeset
|
318 } |
157
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
319 |
270
b74956a2196f
Add a propertiesOf method to the object module that returns the names of things that look like getter messages
Michael Pavone <pavone@retrodev.com>
parents:
267
diff
changeset
|
320 endsWith? <- :suffix { |
b74956a2196f
Add a propertiesOf method to the object module that returns the names of things that look like getter messages
Michael Pavone <pavone@retrodev.com>
parents:
267
diff
changeset
|
321 if: (suffix length) <= length { |
b74956a2196f
Add a propertiesOf method to the object module that returns the names of things that look like getter messages
Michael Pavone <pavone@retrodev.com>
parents:
267
diff
changeset
|
322 0 = (compareSub: suffix (length - (suffix length)) 0 (suffix length)) |
b74956a2196f
Add a propertiesOf method to the object module that returns the names of things that look like getter messages
Michael Pavone <pavone@retrodev.com>
parents:
267
diff
changeset
|
323 } |
b74956a2196f
Add a propertiesOf method to the object module that returns the names of things that look like getter messages
Michael Pavone <pavone@retrodev.com>
parents:
267
diff
changeset
|
324 } |
b74956a2196f
Add a propertiesOf method to the object module that returns the names of things that look like getter messages
Michael Pavone <pavone@retrodev.com>
parents:
267
diff
changeset
|
325 |
271
bb4723fec05e
Support for encoding objects, dictionaries, lists and arrays to JSON in json module
Michael Pavone <pavone@retrodev.com>
parents:
270
diff
changeset
|
326 jsonEncode <- { |
bb4723fec05e
Support for encoding objects, dictionaries, lists and arrays to JSON in json module
Michael Pavone <pavone@retrodev.com>
parents:
270
diff
changeset
|
327 i <- 0 |
bb4723fec05e
Support for encoding objects, dictionaries, lists and arrays to JSON in json module
Michael Pavone <pavone@retrodev.com>
parents:
270
diff
changeset
|
328 start <- 0 |
bb4723fec05e
Support for encoding objects, dictionaries, lists and arrays to JSON in json module
Michael Pavone <pavone@retrodev.com>
parents:
270
diff
changeset
|
329 parts <- #["\""] |
bb4723fec05e
Support for encoding objects, dictionaries, lists and arrays to JSON in json module
Michael Pavone <pavone@retrodev.com>
parents:
270
diff
changeset
|
330 q <- "\"" byte: 0 |
bb4723fec05e
Support for encoding objects, dictionaries, lists and arrays to JSON in json module
Michael Pavone <pavone@retrodev.com>
parents:
270
diff
changeset
|
331 s <- "\\" byte: 0 |
bb4723fec05e
Support for encoding objects, dictionaries, lists and arrays to JSON in json module
Michael Pavone <pavone@retrodev.com>
parents:
270
diff
changeset
|
332 while: { i < byte_length } do: { |
bb4723fec05e
Support for encoding objects, dictionaries, lists and arrays to JSON in json module
Michael Pavone <pavone@retrodev.com>
parents:
270
diff
changeset
|
333 b <- byte: i |
bb4723fec05e
Support for encoding objects, dictionaries, lists and arrays to JSON in json module
Michael Pavone <pavone@retrodev.com>
parents:
270
diff
changeset
|
334 if: b = q { |
bb4723fec05e
Support for encoding objects, dictionaries, lists and arrays to JSON in json module
Michael Pavone <pavone@retrodev.com>
parents:
270
diff
changeset
|
335 parts append: (from: start withLength: i - start) |
bb4723fec05e
Support for encoding objects, dictionaries, lists and arrays to JSON in json module
Michael Pavone <pavone@retrodev.com>
parents:
270
diff
changeset
|
336 start <- i + 1 |
bb4723fec05e
Support for encoding objects, dictionaries, lists and arrays to JSON in json module
Michael Pavone <pavone@retrodev.com>
parents:
270
diff
changeset
|
337 parts append: "\\\"" |
bb4723fec05e
Support for encoding objects, dictionaries, lists and arrays to JSON in json module
Michael Pavone <pavone@retrodev.com>
parents:
270
diff
changeset
|
338 } else: { |
bb4723fec05e
Support for encoding objects, dictionaries, lists and arrays to JSON in json module
Michael Pavone <pavone@retrodev.com>
parents:
270
diff
changeset
|
339 if: b = s { |
bb4723fec05e
Support for encoding objects, dictionaries, lists and arrays to JSON in json module
Michael Pavone <pavone@retrodev.com>
parents:
270
diff
changeset
|
340 parts append: (from: start withLength: i - start) |
bb4723fec05e
Support for encoding objects, dictionaries, lists and arrays to JSON in json module
Michael Pavone <pavone@retrodev.com>
parents:
270
diff
changeset
|
341 start <- i + 1 |
bb4723fec05e
Support for encoding objects, dictionaries, lists and arrays to JSON in json module
Michael Pavone <pavone@retrodev.com>
parents:
270
diff
changeset
|
342 parts append: "\\\\" |
bb4723fec05e
Support for encoding objects, dictionaries, lists and arrays to JSON in json module
Michael Pavone <pavone@retrodev.com>
parents:
270
diff
changeset
|
343 } |
bb4723fec05e
Support for encoding objects, dictionaries, lists and arrays to JSON in json module
Michael Pavone <pavone@retrodev.com>
parents:
270
diff
changeset
|
344 } |
bb4723fec05e
Support for encoding objects, dictionaries, lists and arrays to JSON in json module
Michael Pavone <pavone@retrodev.com>
parents:
270
diff
changeset
|
345 |
bb4723fec05e
Support for encoding objects, dictionaries, lists and arrays to JSON in json module
Michael Pavone <pavone@retrodev.com>
parents:
270
diff
changeset
|
346 i <- i + 1 |
bb4723fec05e
Support for encoding objects, dictionaries, lists and arrays to JSON in json module
Michael Pavone <pavone@retrodev.com>
parents:
270
diff
changeset
|
347 } |
bb4723fec05e
Support for encoding objects, dictionaries, lists and arrays to JSON in json module
Michael Pavone <pavone@retrodev.com>
parents:
270
diff
changeset
|
348 if: start < byte_length { |
bb4723fec05e
Support for encoding objects, dictionaries, lists and arrays to JSON in json module
Michael Pavone <pavone@retrodev.com>
parents:
270
diff
changeset
|
349 parts append: (from: start) |
bb4723fec05e
Support for encoding objects, dictionaries, lists and arrays to JSON in json module
Michael Pavone <pavone@retrodev.com>
parents:
270
diff
changeset
|
350 } |
bb4723fec05e
Support for encoding objects, dictionaries, lists and arrays to JSON in json module
Michael Pavone <pavone@retrodev.com>
parents:
270
diff
changeset
|
351 parts append: "\"" |
bb4723fec05e
Support for encoding objects, dictionaries, lists and arrays to JSON in json module
Michael Pavone <pavone@retrodev.com>
parents:
270
diff
changeset
|
352 parts join: "" |
bb4723fec05e
Support for encoding objects, dictionaries, lists and arrays to JSON in json module
Michael Pavone <pavone@retrodev.com>
parents:
270
diff
changeset
|
353 } |
bb4723fec05e
Support for encoding objects, dictionaries, lists and arrays to JSON in json module
Michael Pavone <pavone@retrodev.com>
parents:
270
diff
changeset
|
354 |
147
4c96a393103e
Add support for receiving data from a socket
Mike Pavone <pavone@retrodev.com>
parents:
88
diff
changeset
|
355 isInteger? <- { false } |
154
6e579a75a0a9
Add JSON parser and sample
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
356 isString? <- { true } |
243
5b830147c1cd
Use a lightweight substring object in a few places in the parser to improve performance for large files.
Mike Pavone <pavone@retrodev.com>
parents:
158
diff
changeset
|
357 isBasicString? <- { true } |
88
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
358 } |