@@ -9,14 +9,29 @@ pub trait StringExt {
9
9
10
10
11
11
impl StringExt for string {
12
+ /// # index_of
13
+ ///
14
+ /// Returns the index of the first occurrence of the
15
+ /// specified substring in this string, or `None` if there is no such occurrence.
12
16
fn index_of(s:string) Option<i64> {
13
17
let chars = self.chars();
14
18
let subchars = s.chars();
15
19
return chars.index_of(subchars);
16
20
}
21
+ /// # contains
22
+ ///
23
+ /// Returns `true` if the specified substring is a
24
+ /// substring of this string, and `false` otherwise.
17
25
fn contains(s:string) bool {
18
26
return self.index_of(s) is i64;
19
27
}
28
+
29
+ /// # slice
30
+ ///
31
+ /// Returns a new string that is a substring of this string.
32
+ ///
33
+ /// The substring is a slice of the original string starting from the `start` index and
34
+ /// having `len` characters.
20
35
fn slice(start:i64, len:i64) string {
21
36
if start + len == 0 {
22
37
return "";
@@ -50,7 +65,7 @@ impl StringExt for string {
50
65
}
51
66
52
67
if byte_len == 0 && len != 0 {
53
- pl_panic();
68
+ pl_panic();
54
69
return string {
55
70
_len: 0,
56
71
_byte_len: 0,
@@ -67,6 +82,10 @@ impl StringExt for string {
67
82
68
83
}
69
84
85
+
86
+ /// # from_chars
87
+ ///
88
+ /// Converts a list of characters to a string.
70
89
pub fn from_chars(chars:[char]) string {
71
90
let bytes:[u8] = [u8*4*arr_len(chars);];
72
91
let i = 0;
0 commit comments