-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram_string.bpl
More file actions
54 lines (41 loc) · 1.4 KB
/
Copy pathprogram_string.bpl
File metadata and controls
54 lines (41 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
implements program
imports {
bapel.core
bapel.stl
}
fn mkString() -> () {
let s: String = "...".to_string;
()
}
fn testStringView() -> () {
let s: String = "hello".to_string;
let sv: StringView = String::view &s;
core::print [bool] (StringView::empty sv);
core::print [i64] (StringView::size sv);
core::print [i8] (StringView::front sv);
core::print [i8] (StringView::at (sv, 1));
let sub: StringView = StringView::substr (sv, 1, 3);
core::print [i64] (StringView::size sub);
core::print [i8] (StringView::front sub);
let empty_sv: StringView = StringView::substr (sv, 10, 3);
core::print [bool] (StringView::empty empty_sv);
let pref_str: String = "he".to_string;
core::print [bool] (s.starts_with &pref_str);
core::print [bool] (sv.starts_with "he");
let suff_str: String = "lo".to_string;
core::print [bool] (s.ends_with &suff_str);
core::print [bool] (sv.ends_with "lo");
StringView::remove_prefix (&sv, 1);
core::print [i64] (StringView::size sv);
StringView::remove_suffix (&sv, 1);
core::print [i64] (StringView::size sv);
let trimmed_s: bool = s.trim_prefix &pref_str;
core::print [bool] trimmed_s;
let trimmed_sv: bool = sv.trim_prefix "el";
core::print [bool] trimmed_sv;
let target_str: String = "l".to_string;
core::print [i64] (s.rfind &target_str);
let not_found_str: String = "z".to_string;
core::print [i64] (s.rfind ¬_found_str);
()
}