Updated to lastest master Ropey.
This commit is contained in:
parent
e31f464702
commit
a3d98a59fb
6
Cargo.lock
generated
6
Cargo.lock
generated
|
@ -3,7 +3,7 @@ name = "Led"
|
|||
version = "0.0.2"
|
||||
dependencies = [
|
||||
"docopt 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ropey 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ropey 0.7.0 (git+https://github.com/cessen/ropey)",
|
||||
"serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"smallvec 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -88,7 +88,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
[[package]]
|
||||
name = "ropey"
|
||||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
source = "git+https://github.com/cessen/ropey#cdf2d63c0da51e3d990c1c65bec0bc934e630e5a"
|
||||
dependencies = [
|
||||
"smallvec 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
@ -208,7 +208,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"
|
||||
"checksum regex 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "744554e01ccbd98fff8c457c3b092cd67af62a555a43bfe97ae8a0451f7799fa"
|
||||
"checksum regex-syntax 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8e931c58b93d86f080c734bfd2bce7dd0079ae2331235818133c8be7f422e20e"
|
||||
"checksum ropey 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f825595a4a03c0b23456ce265c5ee18e21eb2bde86144568d065bbeb7de73dde"
|
||||
"checksum ropey 0.7.0 (git+https://github.com/cessen/ropey)" = "<none>"
|
||||
"checksum serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)" = "db99f3919e20faa51bb2996057f5031d8685019b5a06139b1ce761da671b8526"
|
||||
"checksum serde_derive 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)" = "f4ba7591cfe93755e89eeecdbcc668885624829b020050e6aec99c2a03bd3fd0"
|
||||
"checksum serde_derive_internals 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6e03f1c9530c3fb0a0a5c9b826bdd9246a5921ae995d75f512ac917fc4dd55b5"
|
||||
|
|
|
@ -9,8 +9,8 @@ name = "led"
|
|||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
ropey = "0.7"
|
||||
# ropey = { git = "https://github.com/cessen/ropey", branch = "master" }
|
||||
# ropey = "0.7"
|
||||
ropey = { git = "https://github.com/cessen/ropey", branch = "master" }
|
||||
unicode-segmentation = "1.2.1"
|
||||
unicode-width = "0.1"
|
||||
serde = "1.*"
|
||||
|
|
18
src/utils.rs
18
src/utils.rs
|
@ -1,4 +1,4 @@
|
|||
use ropey::{iter::Chunks, RopeSlice};
|
||||
use ropey::{iter::Chunks, RopeSlice, str_utils::byte_to_char_idx};
|
||||
use unicode_segmentation::{GraphemeCursor, GraphemeIncomplete};
|
||||
use unicode_width::UnicodeWidthStr;
|
||||
|
||||
|
@ -34,7 +34,7 @@ pub fn prev_grapheme_boundary(slice: &RopeSlice, char_idx: usize) -> usize {
|
|||
let byte_idx = slice.char_to_byte(char_idx);
|
||||
|
||||
// Get the chunk with our byte index in it.
|
||||
let (mut chunk, mut chunk_byte_idx, mut chunk_char_idx) = slice.chunk_at_byte(byte_idx);
|
||||
let (mut chunk, mut chunk_byte_idx, mut chunk_char_idx, _) = slice.chunk_at_byte(byte_idx);
|
||||
|
||||
// Set up the grapheme cursor.
|
||||
let mut gc = GraphemeCursor::new(byte_idx, slice.len_bytes(), true);
|
||||
|
@ -44,11 +44,11 @@ pub fn prev_grapheme_boundary(slice: &RopeSlice, char_idx: usize) -> usize {
|
|||
match gc.prev_boundary(chunk, chunk_byte_idx) {
|
||||
Ok(None) => return 0,
|
||||
Ok(Some(n)) => {
|
||||
let tmp = chunk[..(n - chunk_byte_idx)].chars().count();
|
||||
let tmp = byte_to_char_idx(chunk, n - chunk_byte_idx);
|
||||
return chunk_char_idx + tmp;
|
||||
}
|
||||
Err(GraphemeIncomplete::PrevChunk) => {
|
||||
let (a, b, c) = slice.chunk_at_byte(chunk_byte_idx - 1);
|
||||
let (a, b, c, _) = slice.chunk_at_byte(chunk_byte_idx - 1);
|
||||
chunk = a;
|
||||
chunk_byte_idx = b;
|
||||
chunk_char_idx = c;
|
||||
|
@ -71,7 +71,7 @@ pub fn next_grapheme_boundary(slice: &RopeSlice, char_idx: usize) -> usize {
|
|||
let byte_idx = slice.char_to_byte(char_idx);
|
||||
|
||||
// Get the chunk with our byte index in it.
|
||||
let (mut chunk, mut chunk_byte_idx, mut chunk_char_idx) = slice.chunk_at_byte(byte_idx);
|
||||
let (mut chunk, mut chunk_byte_idx, mut chunk_char_idx, _) = slice.chunk_at_byte(byte_idx);
|
||||
|
||||
// Set up the grapheme cursor.
|
||||
let mut gc = GraphemeCursor::new(byte_idx, slice.len_bytes(), true);
|
||||
|
@ -81,12 +81,12 @@ pub fn next_grapheme_boundary(slice: &RopeSlice, char_idx: usize) -> usize {
|
|||
match gc.next_boundary(chunk, chunk_byte_idx) {
|
||||
Ok(None) => return slice.len_chars(),
|
||||
Ok(Some(n)) => {
|
||||
let tmp = chunk[..(n - chunk_byte_idx)].chars().count();
|
||||
let tmp = byte_to_char_idx(chunk, n - chunk_byte_idx);
|
||||
return chunk_char_idx + tmp;
|
||||
}
|
||||
Err(GraphemeIncomplete::NextChunk) => {
|
||||
chunk_byte_idx += chunk.len();
|
||||
let (a, _, c) = slice.chunk_at_byte(chunk_byte_idx);
|
||||
let (a, _, c, _) = slice.chunk_at_byte(chunk_byte_idx);
|
||||
chunk = a;
|
||||
chunk_char_idx = c;
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ pub fn is_grapheme_boundary(slice: &RopeSlice, char_idx: usize) -> bool {
|
|||
let byte_idx = slice.char_to_byte(char_idx);
|
||||
|
||||
// Get the chunk with our byte index in it.
|
||||
let (chunk, chunk_byte_idx, _) = slice.chunk_at_byte(byte_idx);
|
||||
let (chunk, chunk_byte_idx, _, _) = slice.chunk_at_byte(byte_idx);
|
||||
|
||||
// Set up the grapheme cursor.
|
||||
let mut gc = GraphemeCursor::new(byte_idx, slice.len_bytes(), true);
|
||||
|
@ -118,7 +118,7 @@ pub fn is_grapheme_boundary(slice: &RopeSlice, char_idx: usize) -> bool {
|
|||
match gc.is_boundary(chunk, chunk_byte_idx) {
|
||||
Ok(n) => return n,
|
||||
Err(GraphemeIncomplete::PreContext(n)) => {
|
||||
let (ctx_chunk, ctx_byte_start, _) = slice.chunk_at_byte(n - 1);
|
||||
let (ctx_chunk, ctx_byte_start, _, _) = slice.chunk_at_byte(n - 1);
|
||||
gc.provide_context(ctx_chunk, ctx_byte_start);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
|
|
Loading…
Reference in New Issue
Block a user