Skip to content

Commit

Permalink
command-parser: remove 'unicode-segmentation' dep (#585)
Browse files Browse the repository at this point in the history
Remove the `unicode-segmentation` dependency from the Command Parser.
It was added in #575 to support unicode via
`unicode_segmentation::GrapheneIndices`, but it's not actually required,
as the `std::str::CharIndices` iterator is effectively the same with how
it's used. Tests for unicode support are unchanged and continue to pass.

Approved-by: Cassandra McCarthy <cassie@7596ff.com>
Approved-by: Zachary Kohnen <me@dusterthefirst.com>
Merged-by: Vivian Hellyer <vivian@hellyer.dev>
Signed-off-by: Vivian Hellyer <vivian@hellyer.dev>
  • Loading branch information
zeylahellyer authored Nov 2, 2020
1 parent 5b06113 commit 0c740ed
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
1 change: 0 additions & 1 deletion command-parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ version = "0.2.1"

[dependencies]
unicase = { default-features = false, version = "2" }
unicode-segmentation = "1"

[dev-dependencies]
criterion = "0.3"
Expand Down
16 changes: 9 additions & 7 deletions command-parser/src/arguments.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use std::fmt::{Debug, Formatter, Result as FmtResult};
use unicode_segmentation::{GraphemeIndices, UnicodeSegmentation};
use std::{
fmt::{Debug, Formatter, Result as FmtResult},
str::CharIndices,
};

/// An iterator over command arguments.
#[derive(Clone)]
pub struct Arguments<'a> {
buf: &'a str,
indices: GraphemeIndices<'a>,
indices: CharIndices<'a>,
idx: usize,
}

Expand Down Expand Up @@ -67,7 +69,7 @@ impl<'a> From<&'a str> for Arguments<'a> {
fn from(buf: &'a str) -> Self {
Self {
buf: buf.trim(),
indices: buf.trim().grapheme_indices(true),
indices: buf.trim().char_indices(),
idx: 0,
}
}
Expand Down Expand Up @@ -97,13 +99,13 @@ impl<'a> Iterator for Arguments<'a> {

while let Some((i, ch)) = self.indices.next() {
if quoted {
if ch == r#"""# {
if ch == '"' {
let v = self.buf.get(start_idx..i);
self.idx = i + 1;

return v.map(str::trim);
}
} else if ch == " " {
} else if ch == ' ' {
if started {
let v = self.buf.get(start_idx..i);
self.idx = i + 1;
Expand All @@ -115,7 +117,7 @@ impl<'a> Iterator for Arguments<'a> {
started = true;
continue;
}
} else if ch == r#"""# {
} else if ch == '"' {
start_idx = i + 1;
quoted = true;
}
Expand Down

0 comments on commit 0c740ed

Please # to comment.