comparison modules/string.tp @ 152:a6739206a9e3

Add splitOn and partitionOn to string objects
author Mike Pavone <pavone@retrodev.com>
date Fri, 09 Aug 2013 20:12:04 -0700
parents 3e9cb69e516d
children 6e579a75a0a9
comparison
equal deleted inserted replaced
151:3e9cb69e516d 152:a6739206a9e3
149 149
150 from <- :start { 150 from <- :start {
151 from: start withLength: length 151 from: start withLength: length
152 } 152 }
153 153
154 partitionOn <- :delim {
155 pos <- find: delim else: { -1 }
156 if: pos >= 0 {
157 _before <- from: 0 withLength: pos
158 _after <- from: (pos + (delim length))
159 #{
160 before <- _before
161 after <- _after
162 }
163 } else: {
164 _before <- self
165 #{
166 before <- _before
167 after <- ""
168 }
169 }
170 }
171
172 splitOn <- :delim {
173 pos <- 0
174 pieces <- #[]
175 while: {
176 pos <- find: delim else: { -1 }
177 pos >= 0
178 } do: {
179 pieces append: (from: 0 withLength: pos)
180 self <- from: pos + (delim length)
181 }
182 pieces append: self
183 }
184
154 isInteger? <- { false } 185 isInteger? <- { false }
155 } 186 }