File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change 1
1
---
2
- refs/heads/master: 546f1e98cb0da4a4f72b9f64afd0e38e6ea45c08
2
+ refs/heads/master: 001d7bfa174dc8097268bf41368c84474aafcd3a
Original file line number Diff line number Diff line change @@ -188,6 +188,35 @@ fn find(str haystack, str needle) -> int {
188
188
ret -1 ;
189
189
}
190
190
191
+ fn starts_with ( str haystack , str needle ) -> bool {
192
+ let uint haystack_len = byte_len ( haystack) ;
193
+ let uint needle_len = byte_len ( needle) ;
194
+ if ( needle_len == 0 u) {
195
+ ret true ;
196
+ }
197
+ if ( needle_len > haystack_len) {
198
+ ret false ;
199
+ }
200
+ ret eq( substr ( haystack, 0 u, needle_len) , needle) ;
201
+ }
202
+
203
+
204
+ fn ends_with ( str haystack , str needle ) -> bool {
205
+ let uint haystack_len = byte_len ( haystack) ;
206
+ let uint needle_len = byte_len ( needle) ;
207
+ if ( needle_len == 0 u) {
208
+ ret true ;
209
+ }
210
+ if ( needle_len > haystack_len) {
211
+ ret false ;
212
+ }
213
+ ret eq( substr ( haystack,
214
+ haystack_len - needle_len,
215
+ needle_len) ,
216
+ needle) ;
217
+ }
218
+
219
+
191
220
fn substr ( str s, uint begin , uint len) -> str {
192
221
let str accum = "" ;
193
222
let uint i = begin;
You can’t perform that action at this time.
0 commit comments