Mercurial > repos > rhope
comparison string.rhope @ 71:c40c3d399133
Add Int32@String and Get Char. Fix stack bug
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 18 Jun 2010 15:07:09 -0400 |
parents | d0ce696786cc |
children | f7bcf3db1342 |
comparison
equal
deleted
inserted
replaced
70:1bfcf5f8fa69 | 71:c40c3d399133 |
---|---|
94 //TODO: Sanitize string (remove terminal escapes and replace invalid UTF) | 94 //TODO: Sanitize string (remove terminal escapes and replace invalid UTF) |
95 write[1i32, [string]Buffer >>, Int64[[[string]Buffer >>]Length >>]] | 95 write[1i32, [string]Buffer >>, Int64[[[string]Buffer >>]Length >>]] |
96 { out <- write[1i32, [Array[]]Append[10u8], 1i64] } | 96 { out <- write[1i32, [Array[]]Append[10u8], 1i64] } |
97 } | 97 } |
98 | 98 |
99 Get Char[:out] | |
100 { | |
101 read[0, [Array[]]Set[0, 0u8], 1i64] | |
102 {} | |
103 { out <- String[~] } | |
104 } | |
105 | |
106 _String to Int32[current,index,array:out] | |
107 { | |
108 char <- [array]Index[index] | |
109 { | |
110 If[[char]<[48u8]] | |
111 { | |
112 out <- Val[current] | |
113 }{ | |
114 If[[char]>[57u8]] | |
115 { | |
116 out <- Val[current] | |
117 }{ | |
118 out <- _String to Int32[[[current]*[10i32]]+[Int32[[char]-[48u8]]], [index]+[1], array] | |
119 } | |
120 } | |
121 | |
122 }{ | |
123 out <- Val[current] | |
124 } | |
125 } | |
126 | |
127 Int32@String[string:out] | |
128 { | |
129 buf <- [string]Buffer >> | |
130 [buf]Index[0] | |
131 { | |
132 If[[~]=[45u8]] | |
133 { | |
134 out <- [0i32]-[_String to Int32[0i32, 1, buf]] | |
135 }{ | |
136 out <- _String to Int32[0i32, 0, buf] | |
137 } | |
138 }{ | |
139 out <- 0i32 | |
140 } | |
141 | |
142 } | |
143 | |
99 Flatten@String[string:out] | 144 Flatten@String[string:out] |
100 { | 145 { |
101 out <- string | 146 out <- string |
102 } | 147 } |
103 | 148 |