Skip to content

Commit

Permalink
add is_empty api
Browse files Browse the repository at this point in the history
  • Loading branch information
Yu-zh committed Jan 27, 2025
1 parent 4a6e310 commit 9dbb833
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions string/view.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -447,3 +447,9 @@ pub fn StringView::iter(self : StringView) -> Iter[Char] {
}
})
}

///|
/// Returns true if the view is empty.
pub fn StringView::is_empty(self : StringView) -> Bool {
self.start == self.end
}
11 changes: 11 additions & 0 deletions string/view_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -514,3 +514,14 @@ test "panic stringview negative index3" {
let _ = str[-1:-2]

}

test "is_empty" {
let str = "hello"
let view = str[1:4]
inspect!(view.is_empty(), content="false")
let view = str[0:0]
inspect!(view.is_empty(), content="true")
let str = ""
let view = str[:]
inspect!(view.is_empty(), content="true")
}

0 comments on commit 9dbb833

Please sign in to comment.