Skip to content

Commit 144c109

Browse files
committed
---
yaml --- r: 1184 b: refs/heads/master c: 001d7bf h: refs/heads/master v: v3
1 parent 7a4f557 commit 144c109

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 546f1e98cb0da4a4f72b9f64afd0e38e6ea45c08
2+
refs/heads/master: 001d7bfa174dc8097268bf41368c84474aafcd3a

trunk/src/lib/_str.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,35 @@ fn find(str haystack, str needle) -> int {
188188
ret -1;
189189
}
190190

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 == 0u) {
195+
ret true;
196+
}
197+
if (needle_len > haystack_len) {
198+
ret false;
199+
}
200+
ret eq(substr(haystack, 0u, 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 == 0u) {
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+
191220
fn substr(str s, uint begin, uint len) -> str {
192221
let str accum = "";
193222
let uint i = begin;

0 commit comments

Comments
 (0)