Skip to content

Commit

Permalink
7. [release:2.3.0]
Browse files Browse the repository at this point in the history
  • Loading branch information
just-do-halee committed Jan 5, 2022
1 parent 671f78c commit 3a14ee1
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 37 deletions.
15 changes: 13 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
## 2.3.0 (January 6, 2022)

### Release 2.3.0
* Patched:
- *Adding `Option` of return value*.
- cursor ***`.next_to_until(`fn`)`*** -> `Option<T>`
- cursor ***`.next_to_while(`fn`)`*** -> `Option<T>`


---

## 2.2.0 (January 2, 2022)

### Release 2.2.0
* New Feature:
* cursor ***`.prev()`*** : *next_back() without turnaround().*
* cursor ***`.extras_mut()`*** : *gets mutable extras.*
- cursor ***`.prev()`*** : *next_back() without turnaround().*
- cursor ***`.extras_mut()`*** : *gets mutable extras.*


---
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cursor"
version = "2.2.0"
version = "2.3.0"
authors = ["just-do-halee <[email protected]>"]
homepage = "https://github.com/just-do-halee/cursor"
repository = "https://github.com/just-do-halee/cursor"
Expand Down
44 changes: 12 additions & 32 deletions src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,25 +347,15 @@ where
}
/// bump until meets f() = `true`.
#[inline]
fn next_to_until(&mut self, f: fn(&T) -> bool) -> &'s T {
#[allow(clippy::while_let_on_iterator)]
while let Some(item) = self.next() {
if f(item) {
break;
}
}
self.current()
fn next_to_until(&mut self, f: fn(&T) -> bool) -> Option<&'s T> {
while !f(self.next()?) {}
Some(self.current())
}
/// bump while f() = `true`.
#[inline]
fn next_to_while(&mut self, f: fn(&T) -> bool) -> &'s T {
#[allow(clippy::while_let_on_iterator)]
while let Some(item) = self.next() {
if !f(item) {
break;
}
}
self.current()
fn next_to_while(&mut self, f: fn(&T) -> bool) -> Option<&'s T> {
while f(self.next()?) {}
Some(self.current())
}
/// bump until meets saved pos.
#[inline]
Expand Down Expand Up @@ -850,25 +840,15 @@ where
}
/// bump until meets f() = `true`.
#[inline]
fn next_to_until(&mut self, f: fn(char) -> bool) -> char {
#[allow(clippy::while_let_on_iterator)]
while let Some(ch) = self.next() {
if f(ch) {
break;
}
}
self.current()
fn next_to_until(&mut self, f: fn(char) -> bool) -> Option<char> {
while !f(self.next()?) {}
Some(self.current())
}
/// bump while f() = `true`.
#[inline]
fn next_to_while(&mut self, f: fn(char) -> bool) -> char {
#[allow(clippy::while_let_on_iterator)]
while let Some(ch) = self.next() {
if !f(ch) {
break;
}
}
self.current()
fn next_to_while(&mut self, f: fn(char) -> bool) -> Option<char> {
while f(self.next()?) {}
Some(self.current())
}
/// bump until meets saved pos.
#[inline]
Expand Down
22 changes: 22 additions & 0 deletions tests/cursor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,25 @@ fn extras_works() {
cursor.extras_mut()._reset();
assert_eq!(cursor.to_extras().0, 0);
}

#[test]
fn next_to_until() {
let mut cursor = Cursor::new_with_extras::<EvenCounter>(SLICE);
let c = cursor.next_to_until(|&i| i == 5);
assert_eq!(c, Some(&5));
let c = cursor.next_to_until(|&i| i == 10);
assert_eq!(c, Some(&10));
let c = cursor.next_to_until(|&i| i == 11);
assert_eq!(c, None);
}

#[test]
fn next_to_while() {
let mut cursor = Cursor::new_with_extras::<EvenCounter>(SLICE);
let c = cursor.next_to_while(|&i| i <= 4);
assert_eq!(c, Some(&5));
let c = cursor.next_to_while(|&i| i <= 9);
assert_eq!(c, Some(&10));
let c = cursor.next_to_while(|&i| i <= 10);
assert_eq!(c, None);
}
26 changes: 24 additions & 2 deletions tests/strcursor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use cursor::*;

const STRING: &str = "this is test. 안녕하세요. 이것은 #&*@( 테스트입니다. ^^ thanks.";
const STRING: &str = "this is test. 안녕하세요. 이것은 #&*@( 테스트입니다. ^^ thanks!";

#[derive(Debug, Default)]
struct SpaceCounter(pub usize);
Expand Down Expand Up @@ -133,7 +133,7 @@ fn str_works() {
cursor.current(),
cursor.as_remaining_str()
),
"this is test. 안 녕 하세요. 이것은 #&*@( 테스트입니다. ^^ thanks."
"this is test. 안 녕 하세요. 이것은 #&*@( 테스트입니다. ^^ thanks!"
);
}

Expand Down Expand Up @@ -198,3 +198,25 @@ fn extras_works() {
cursor.extras_mut()._reset();
assert_eq!(cursor.into_extras().0, 0);
}

#[test]
fn next_to_until() {
let mut cursor = StrCursor::new_with_extras::<SpaceCounter>(STRING);
let c = cursor.next_to_until(|c| c == 's');
assert_eq!(c, Some('s'));
let c = cursor.next_to_until(|c| c == '이');
assert_eq!(c, Some('이'));
let c = cursor.next_to_until(|c| c == '쀍');
assert_eq!(c, None);
}

#[test]
fn next_to_while() {
let mut cursor = StrCursor::new_with_extras::<SpaceCounter>(STRING);
let c = cursor.next_to_while(|c| "this is test.".contains(c));
assert_eq!(c, Some('안'));
let c = cursor.next_to_while(|c| matches!(c, '안' | '녕' | '하' | '세'));
assert_eq!(c, Some('요'));
cursor.next_to_while(|c| c != '!');
assert_eq!(cursor.next(), None);
}

0 comments on commit 3a14ee1

Please sign in to comment.