Mercurial > repos > tabletprog
annotate modules/string.tp @ 344:7de6ac24eb64
Add map to dict hash
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 08 Apr 2015 19:29:22 -0700 |
parents | 6871e72b6db2 |
children |
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 } |
341
6871e72b6db2
Added int64 message to string type
Michael Pavone <pavone@retrodev.com>
parents:
339
diff
changeset
|
90 |
6871e72b6db2
Added int64 message to string type
Michael Pavone <pavone@retrodev.com>
parents:
339
diff
changeset
|
91 llMessage: int64 withVars: { |
6871e72b6db2
Added int64 message to string type
Michael Pavone <pavone@retrodev.com>
parents:
339
diff
changeset
|
92 int64ret <- (obj_int64 ptr) |
6871e72b6db2
Added int64 message to string type
Michael Pavone <pavone@retrodev.com>
parents:
339
diff
changeset
|
93 } andCode: { |
6871e72b6db2
Added int64 message to string type
Michael Pavone <pavone@retrodev.com>
parents:
339
diff
changeset
|
94 int64ret <- make_object: (addr_of: obj_int64_meta) NULL 0 |
6871e72b6db2
Added int64 message to string type
Michael Pavone <pavone@retrodev.com>
parents:
339
diff
changeset
|
95 int64ret num!: (atoll: data) |
6871e72b6db2
Added int64 message to string type
Michael Pavone <pavone@retrodev.com>
parents:
339
diff
changeset
|
96 int64ret |
6871e72b6db2
Added int64 message to string type
Michael Pavone <pavone@retrodev.com>
parents:
339
diff
changeset
|
97 } |
147
4c96a393103e
Add support for receiving data from a socket
Mike Pavone <pavone@retrodev.com>
parents:
88
diff
changeset
|
98 |
158
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
99 parseHex32 <- { |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
100 num <- 0u32 |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
101 cur <- 0 |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
102 a <- uint32: ("a" byte: 0) |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
103 A <- uint32: ("A" byte: 0) |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
104 f <- uint32: ("f" byte: 0) |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
105 F <- uint32: ("F" byte: 0) |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
106 zero <- "0" byte: 0 |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
107 nine <- "9" byte: 0 |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
108 while: { cur < byte_length} do: { |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
109 b <- uint32: (byte: cur) |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
110 cur <- cur + 1 |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
111 if: b >= zero && b <= nine { |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
112 num <- num * 16 + (b - zero) |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
113 } else: { |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
114 if: b >= a && b <= f { |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
115 num <- num * 16 + (b - a) + 10u32 |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
116 } else: { |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
117 if: b >= A && b <= F { |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
118 num <- num * 16 + (b - A) + 10u32 |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
119 } else: { |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
120 cur <- byte_length |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
121 } |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
122 } |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
123 } |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
124 } |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
125 num |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
126 } |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
127 |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
128 parseHex64 <- { |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
129 num <- 0u64 |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
130 cur <- 0 |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
131 a <- uint64: ("a" byte: 0) |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
132 A <- uint64: ("A" byte: 0) |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
133 f <- uint64: ("f" byte: 0) |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
134 F <- uint64: ("F" byte: 0) |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
135 zero <- "0" byte: 0 |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
136 nine <- "9" byte: 0 |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
137 while: { cur < byte_length} do: { |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
138 b <- uint64: (byte: cur) |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
139 cur <- cur + 1 |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
140 if: b >= zero && b <= nine { |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
141 num <- num * 16 + (b - zero) |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
142 } else: { |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
143 if: b >= a && b <= f { |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
144 num <- num * 16 + (b - a) + 10u64 |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
145 } else: { |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
146 if: b >= A && b <= F { |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
147 num <- num * 16 + (b - A) + 10u64 |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
148 } else: { |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
149 cur <- byte_length |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
150 } |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
151 } |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
152 } |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
153 } |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
154 num |
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
155 } |
339
74cab9b5f2a4
Added parseFloat64 and parseFloat32 along with a sample that exercises number parsing from a string
Michael Pavone <pavone@retrodev.com>
parents:
306
diff
changeset
|
156 |
74cab9b5f2a4
Added parseFloat64 and parseFloat32 along with a sample that exercises number parsing from a string
Michael Pavone <pavone@retrodev.com>
parents:
306
diff
changeset
|
157 llMessage: parseFloat64 withVars: { |
74cab9b5f2a4
Added parseFloat64 and parseFloat32 along with a sample that exercises number parsing from a string
Michael Pavone <pavone@retrodev.com>
parents:
306
diff
changeset
|
158 fret64 <- obj_float64 ptr |
74cab9b5f2a4
Added parseFloat64 and parseFloat32 along with a sample that exercises number parsing from a string
Michael Pavone <pavone@retrodev.com>
parents:
306
diff
changeset
|
159 } andCode: { |
74cab9b5f2a4
Added parseFloat64 and parseFloat32 along with a sample that exercises number parsing from a string
Michael Pavone <pavone@retrodev.com>
parents:
306
diff
changeset
|
160 //TODO: This should probably detect non-numeric values and return an option type |
74cab9b5f2a4
Added parseFloat64 and parseFloat32 along with a sample that exercises number parsing from a string
Michael Pavone <pavone@retrodev.com>
parents:
306
diff
changeset
|
161 fret64 <- make_object: (addr_of: obj_float64_meta) NULL 0 |
74cab9b5f2a4
Added parseFloat64 and parseFloat32 along with a sample that exercises number parsing from a string
Michael Pavone <pavone@retrodev.com>
parents:
306
diff
changeset
|
162 fret64 num!: (atof: data) |
74cab9b5f2a4
Added parseFloat64 and parseFloat32 along with a sample that exercises number parsing from a string
Michael Pavone <pavone@retrodev.com>
parents:
306
diff
changeset
|
163 fret64 |
74cab9b5f2a4
Added parseFloat64 and parseFloat32 along with a sample that exercises number parsing from a string
Michael Pavone <pavone@retrodev.com>
parents:
306
diff
changeset
|
164 } |
74cab9b5f2a4
Added parseFloat64 and parseFloat32 along with a sample that exercises number parsing from a string
Michael Pavone <pavone@retrodev.com>
parents:
306
diff
changeset
|
165 |
74cab9b5f2a4
Added parseFloat64 and parseFloat32 along with a sample that exercises number parsing from a string
Michael Pavone <pavone@retrodev.com>
parents:
306
diff
changeset
|
166 parseFloat32 <- { |
74cab9b5f2a4
Added parseFloat64 and parseFloat32 along with a sample that exercises number parsing from a string
Michael Pavone <pavone@retrodev.com>
parents:
306
diff
changeset
|
167 parseFloat64 f32 |
74cab9b5f2a4
Added parseFloat64 and parseFloat32 along with a sample that exercises number parsing from a string
Michael Pavone <pavone@retrodev.com>
parents:
306
diff
changeset
|
168 } |
158
38140b7dbe3d
Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents:
157
diff
changeset
|
169 |
88
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
170 llMessage: hash withVars: { |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
171 intret <- (obj_int32 ptr) |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
172 i <- uint32_t |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
173 } andCode: { |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
174 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
|
175 intret num!: 0 |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
176 if: bytes { |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
177 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
|
178 i <- 0 |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
179 while: { i < bytes } do: { |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
180 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
|
181 i <- i + 1 |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
182 } |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
183 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
|
184 } |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
185 intret |
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
186 } |
147
4c96a393103e
Add support for receiving data from a socket
Mike Pavone <pavone@retrodev.com>
parents:
88
diff
changeset
|
187 |
154
6e579a75a0a9
Add JSON parser and sample
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
188 llMessage: find:startingAt:else withVars: { |
150
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
189 intret <- obj_int32 ptr |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
190 oneedle <- object ptr |
154
6e579a75a0a9
Add JSON parser and sample
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
191 startpos <- obj_int32 ptr |
150
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
192 ifNotFound <- object ptr |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
193 sneedle <- string ptr |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
194 i <- uint32_t |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
195 notFound <- uint32_t |
154
6e579a75a0a9
Add JSON parser and sample
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
196 } andCode: :oneedle :startpos :ifNotFound { |
267 | 197 sneedle <- (mcall: string 1 oneedle) castTo: (string ptr) |
154
6e579a75a0a9
Add JSON parser and sample
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
198 i <- startpos num |
150
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
199 notFound <- 1 |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
200 while: { notFound && i + (sneedle bytes) <= bytes} do: { |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
201 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
|
202 notFound <- 0 |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
203 } else: { |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
204 i <- i + 1 |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
205 } |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
206 } |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
207 if: notFound { |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
208 ccall: ifNotFound 0 |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
209 } else: { |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
210 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
|
211 intret num!: i |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
212 intret |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
213 } |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
214 } |
7dfa4481deb0
Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
215 |
154
6e579a75a0a9
Add JSON parser and sample
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
216 find:else <- :toFind :orElse { |
6e579a75a0a9
Add JSON parser and sample
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
217 find: toFind startingAt: 0 else: orElse |
6e579a75a0a9
Add JSON parser and sample
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
218 } |
6e579a75a0a9
Add JSON parser and sample
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
219 |
151
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
220 llMessage: from:withLength withVars: { |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
221 from <- obj_int32 ptr |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
222 tocopy <- obj_int32 ptr |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
223 ret <- string ptr |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
224 start <- int32_t |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
225 clampedLen <- int32_t |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
226 } andCode: :from :tocopy { |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
227 start <- from num |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
228 if: start < 0 { |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
229 start <- bytes + start |
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 if: start > bytes { |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
232 start <- bytes |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
233 } |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
234 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
|
235 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
|
236 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
|
237 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
|
238 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
|
239 } |
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
|
240 } |
151
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
241 if: start + clampedLen > bytes { |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
242 clampedLen <- bytes - start |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
243 } |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
244 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
|
245 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
|
246 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
|
247 ret len!: clampedLen |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
248 ret bytes!: clampedLen |
305
14b4e540af28
Properly null terminate result of from:withLength
Michael Pavone <pavone@retrodev.com>
parents:
301
diff
changeset
|
249 (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
|
250 ret |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
251 } |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
252 |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
253 from <- :start { |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
254 from: start withLength: length |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
255 } |
3e9cb69e516d
Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
256 |
152
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
257 partitionOn <- :delim { |
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 if: pos >= 0 { |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
260 _before <- from: 0 withLength: pos |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
261 _after <- from: (pos + (delim length)) |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
262 #{ |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
263 before <- _before |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
264 after <- _after |
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 } else: { |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
267 _before <- self |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
268 #{ |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
269 before <- _before |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
270 after <- "" |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
271 } |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
272 } |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
273 } |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
274 |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
275 splitOn <- :delim { |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
276 pos <- 0 |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
277 pieces <- #[] |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
278 while: { |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
279 pos <- find: delim else: { -1 } |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
280 pos >= 0 |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
281 } do: { |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
282 pieces append: (from: 0 withLength: pos) |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
283 self <- from: pos + (delim length) |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
284 } |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
285 pieces append: self |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
286 } |
a6739206a9e3
Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
287 |
259
32964a4e7a33
Add ltrim method to string
Michael Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
288 ltrim <- { |
32964a4e7a33
Add ltrim method to string
Michael Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
289 l <- length |
32964a4e7a33
Add ltrim method to string
Michael Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
290 start <- 0 |
32964a4e7a33
Add ltrim method to string
Michael Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
291 space <- " " byte: 0 |
32964a4e7a33
Add ltrim method to string
Michael Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
292 tab <- "\t" byte: 0 |
32964a4e7a33
Add ltrim method to string
Michael Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
293 nl <- "\n" byte: 0 |
32964a4e7a33
Add ltrim method to string
Michael Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
294 cr <- "\r" byte: 0 |
32964a4e7a33
Add ltrim method to string
Michael Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
295 |
32964a4e7a33
Add ltrim method to string
Michael Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
296 while: { |
32964a4e7a33
Add ltrim method to string
Michael Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
297 if: start < l { |
32964a4e7a33
Add ltrim method to string
Michael Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
298 b <- byte: start |
32964a4e7a33
Add ltrim method to string
Michael Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
299 b = space || b = tab || b = nl || b = cr |
32964a4e7a33
Add ltrim method to string
Michael Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
300 } |
32964a4e7a33
Add ltrim method to string
Michael Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
301 } do: { |
32964a4e7a33
Add ltrim method to string
Michael Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
302 start <- start + 1 |
32964a4e7a33
Add ltrim method to string
Michael Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
303 } |
32964a4e7a33
Add ltrim method to string
Michael Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
304 from: start |
32964a4e7a33
Add ltrim method to string
Michael Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
305 } |
32964a4e7a33
Add ltrim method to string
Michael Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
306 |
157
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
307 trim <- { |
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
308 l <- length |
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
309 start <- 0 |
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
310 space <- " " byte: 0 |
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
311 tab <- "\t" byte: 0 |
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
312 nl <- "\n" byte: 0 |
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
313 cr <- "\r" byte: 0 |
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
314 |
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
315 while: { |
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
316 if: start < l { |
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
317 b <- byte: start |
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
318 b = space || b = tab || b = nl || b = cr |
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
319 } |
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
320 } do: { |
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
321 start <- start + 1 |
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
322 } |
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
|
323 end <- l - 1 |
157
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
324 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
|
325 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
|
326 b <- byte: end |
157
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
327 b = space || b = tab || b = nl || b = cr |
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
328 } |
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
329 } do: { |
295
9a30510f6e52
Fix trim method on strings
Michael Pavone <pavone@retrodev.com>
parents:
271
diff
changeset
|
330 end <- end - 1 |
157
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
331 } |
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
|
332 from: start withLength: (end + 1 - start) |
157
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
333 } |
301
5d24b3117aa7
Add startsWith? to string
Michael Pavone <pavone@retrodev.com>
parents:
295
diff
changeset
|
334 |
5d24b3117aa7
Add startsWith? to string
Michael Pavone <pavone@retrodev.com>
parents:
295
diff
changeset
|
335 startsWith? <- :prefix { |
5d24b3117aa7
Add startsWith? to string
Michael Pavone <pavone@retrodev.com>
parents:
295
diff
changeset
|
336 if: (prefix length) <= length { |
5d24b3117aa7
Add startsWith? to string
Michael Pavone <pavone@retrodev.com>
parents:
295
diff
changeset
|
337 0 = (compareSub: prefix 0 0 (prefix length)) |
5d24b3117aa7
Add startsWith? to string
Michael Pavone <pavone@retrodev.com>
parents:
295
diff
changeset
|
338 } |
5d24b3117aa7
Add startsWith? to string
Michael Pavone <pavone@retrodev.com>
parents:
295
diff
changeset
|
339 } |
157
55e0dca7d3d7
Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents:
154
diff
changeset
|
340 |
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
|
341 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
|
342 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
|
343 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
|
344 } |
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
|
345 } |
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
|
346 |
271
bb4723fec05e
Support for encoding objects, dictionaries, lists and arrays to JSON in json module
Michael Pavone <pavone@retrodev.com>
parents:
270
diff
changeset
|
347 jsonEncode <- { |
bb4723fec05e
Support for encoding objects, dictionaries, lists and arrays to JSON in json module
Michael Pavone <pavone@retrodev.com>
parents:
270
diff
changeset
|
348 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
|
349 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
|
350 parts <- #["\""] |
bb4723fec05e
Support for encoding objects, dictionaries, lists and arrays to JSON in json module
Michael Pavone <pavone@retrodev.com>
parents:
270
diff
changeset
|
351 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
|
352 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
|
353 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
|
354 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
|
355 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
|
356 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
|
357 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
|
358 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
|
359 } else: { |
bb4723fec05e
Support for encoding objects, dictionaries, lists and arrays to JSON in json module
Michael Pavone <pavone@retrodev.com>
parents:
270
diff
changeset
|
360 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
|
361 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
|
362 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
|
363 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
|
364 } |
bb4723fec05e
Support for encoding objects, dictionaries, lists and arrays to JSON in json module
Michael Pavone <pavone@retrodev.com>
parents:
270
diff
changeset
|
365 } |
bb4723fec05e
Support for encoding objects, dictionaries, lists and arrays to JSON in json module
Michael Pavone <pavone@retrodev.com>
parents:
270
diff
changeset
|
366 |
bb4723fec05e
Support for encoding objects, dictionaries, lists and arrays to JSON in json module
Michael Pavone <pavone@retrodev.com>
parents:
270
diff
changeset
|
367 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
|
368 } |
bb4723fec05e
Support for encoding objects, dictionaries, lists and arrays to JSON in json module
Michael Pavone <pavone@retrodev.com>
parents:
270
diff
changeset
|
369 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
|
370 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
|
371 } |
bb4723fec05e
Support for encoding objects, dictionaries, lists and arrays to JSON in json module
Michael Pavone <pavone@retrodev.com>
parents:
270
diff
changeset
|
372 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
|
373 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
|
374 } |
bb4723fec05e
Support for encoding objects, dictionaries, lists and arrays to JSON in json module
Michael Pavone <pavone@retrodev.com>
parents:
270
diff
changeset
|
375 |
147
4c96a393103e
Add support for receiving data from a socket
Mike Pavone <pavone@retrodev.com>
parents:
88
diff
changeset
|
376 isInteger? <- { false } |
154
6e579a75a0a9
Add JSON parser and sample
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
377 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
|
378 isBasicString? <- { true } |
88
474f17ebaaa0
Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
379 } |