From 9bd4b3f8789e3da23ecfb73553211aa2910f3e85 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 13 Jan 2024 17:59:40 -0800 Subject: [PATCH] Adopt count_newlines in additional places --- src/parse_util.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/parse_util.rs b/src/parse_util.rs index 4e93a1c54..6e0b9f34b 100644 --- a/src/parse_util.rs +++ b/src/parse_util.rs @@ -26,6 +26,7 @@ use crate::tokenizer::{ TOK_SHOW_COMMENTS, }; use crate::wchar::prelude::*; +use crate::wcstringutil::count_newlines; use crate::wcstringutil::truncate; use crate::wildcard::{ANY_CHAR, ANY_STRING, ANY_STRING_RECURSIVE}; use std::ops; @@ -498,7 +499,7 @@ pub fn parse_util_lineno(s: &wstr, offset: usize) -> usize { } let end = offset.min(s.len()); - s.chars().take(end).filter(|c| *c == '\n').count() + 1 + count_newlines(&s[..end]) + 1 } /// Calculate the line number of the specified cursor position. @@ -507,12 +508,7 @@ pub fn parse_util_get_line_from_offset(s: &wstr, pos: usize) -> isize { if pos > s.len() { return -1; } - s.chars() - .take(pos) - .filter(|c| *c == '\n') - .count() - .try_into() - .unwrap() + count_newlines(&s[..pos]).try_into().unwrap() } /// Get the offset of the first character on the specified line.