Skip to content

Commit 9dbb833

Browse files
committed
add is_empty api
1 parent 4a6e310 commit 9dbb833

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

string/view.mbt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,3 +447,9 @@ pub fn StringView::iter(self : StringView) -> Iter[Char] {
447447
}
448448
})
449449
}
450+
451+
///|
452+
/// Returns true if the view is empty.
453+
pub fn StringView::is_empty(self : StringView) -> Bool {
454+
self.start == self.end
455+
}

string/view_test.mbt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,3 +514,14 @@ test "panic stringview negative index3" {
514514
let _ = str[-1:-2]
515515

516516
}
517+
518+
test "is_empty" {
519+
let str = "hello"
520+
let view = str[1:4]
521+
inspect!(view.is_empty(), content="false")
522+
let view = str[0:0]
523+
inspect!(view.is_empty(), content="true")
524+
let str = ""
525+
let view = str[:]
526+
inspect!(view.is_empty(), content="true")
527+
}

0 commit comments

Comments
 (0)