diff --git a/src/lines.rs b/src/lines.rs index 830faed59..b595b2657 100644 --- a/src/lines.rs +++ b/src/lines.rs @@ -151,20 +151,6 @@ pub fn codepoint_len(s: &str) -> usize { s.chars().count() } -/// Slice `s` from `start` to `end` by codepoint. This is safer than -/// slicing by bytes, which panics if the byte isn't on a codepoint -/// boundary. -pub fn substring_by_codepoint(s: &str, start: usize, end: usize) -> &str { - assert!(end > start); - - let mut char_idx_iter = s.char_indices(); - let byte_start = char_idx_iter.nth(start).expect("Expected a codepoint index inside `s`.").0; - match char_idx_iter.nth(end - 1 - start) { - Some(byte_end) => &s[byte_start..byte_end.0], - None => &s[byte_start..], - } -} - pub trait MaxLine { fn max_line(&self) -> LineNumber; } diff --git a/src/style.rs b/src/style.rs index 2c9c9c5ef..1d87688df 100644 --- a/src/style.rs +++ b/src/style.rs @@ -1,7 +1,7 @@ //! Apply colours and styling to strings. use crate::{ - lines::{codepoint_len, substring_by_codepoint, LineNumber}, + lines::{codepoint_len, LineNumber}, positions::SingleLineSpan, syntax::{AtomKind, MatchKind, MatchedPos, TokenKind}, }; @@ -18,6 +18,20 @@ pub enum BackgroundColor { Light, } +/// Slice `s` from `start` to `end` by codepoint. This is safer than +/// slicing by bytes, which panics if the byte isn't on a codepoint +/// boundary. +fn substring_by_codepoint(s: &str, start: usize, end: usize) -> &str { + assert!(end > start); + + let mut char_idx_iter = s.char_indices(); + let byte_start = char_idx_iter.nth(start).expect("Expected a codepoint index inside `s`.").0; + match char_idx_iter.nth(end - 1 - start) { + Some(byte_end) => &s[byte_start..byte_end.0], + None => &s[byte_start..], + } +} + /// Split a string into equal length parts, padding the last part if /// necessary. ///