Formatting and typos

This commit is contained in:
Andras Schmelczer 2025-07-06 22:07:26 +01:00
parent 56e08588ef
commit 75835ac9a3
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
5 changed files with 23 additions and 22 deletions

View file

@ -34,7 +34,7 @@ console_error_panic_hook = [ "dep:console_error_panic_hook" ]
insta = "1.42.2"
pretty_assertions = "1.4.1"
serde = { version = "1.0.219", features = ["derive"] }
serde_yaml ="0.9.34"
serde_yaml = "0.9.34"
test-case = "3.3.1"
wasm-bindgen-test = "0.3.49"
@ -42,7 +42,7 @@ wasm-bindgen-test = "0.3.49"
codegen-units = 1
lto = true
opt-level = 3
strip="symbols"
strip = "symbols"
[package.metadata.wasm-pack.profile.release]
wasm-opt = ['-O4', '--enable-bulk-memory']

View file

@ -54,8 +54,8 @@
//! .map(|sentence| Token::new(
//! sentence.to_string(),
//! sentence.to_string(),
//! false, // don't allow joining token with the preceeding on
//! false // don't allow joining token with the following one
//! false, // don't allow joining token with the preceding one
//! false, // don't allow joining token with the following one
//! ))
//! .collect::<Vec<_>>()
//! };
@ -68,7 +68,7 @@
//! let result = reconcile(parent, &left.into(), &right.into(), &*BuiltinTokenizer::Word);
//! assert_eq!(result.apply().text(), "Hello beautiful world. This is a great test.");
//! ```
//! > By setting the joinability to `false`, longer runs of inserts with be
//! > By setting the joinability to `false`, longer runs of inserts will be
//! > interleaved like LRLRLR instead of LLLRRR.
//!
//! ## Cursors and selection ranges

View file

@ -3,9 +3,9 @@ use std::fmt::Debug;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
/// A token is a string that has been normalised in some way.
/// A token is a string that has been normalized in some way.
///
/// A token consists of the normalised form is used for comparison, and the
/// A token consists of the normalized form is used for comparison, and the
/// original form used for subsequently applying `Operation`-s to a text
/// document.
///
@ -16,8 +16,8 @@ pub struct Token<T>
where
T: PartialEq + Clone + Debug,
{
/// The normalised form of the token used deriving the diff.
normalised: T,
/// The normalized form of the token used deriving the diff.
normalized: T,
/// The original string, that should be inserted or deleted in the document.
original: String,
@ -29,7 +29,7 @@ where
pub is_right_joinable: bool,
}
/// Trivial implementation of Token when the normalised form is the same as the
/// Trivial implementation of Token when the normalized form is the same as the
/// original string.
impl From<&str> for Token<String> {
fn from(text: &str) -> Self { Token::new(text.to_owned(), text.to_owned(), true, true) }
@ -40,13 +40,13 @@ where
T: PartialEq + Clone + Debug,
{
pub fn new(
normalised: T,
normalized: T,
original: String,
is_left_joinable: bool,
is_right_joinable: bool,
) -> Self {
Token {
normalised,
normalized,
original,
is_left_joinable,
is_right_joinable,
@ -55,9 +55,9 @@ where
pub fn original(&self) -> &str { &self.original }
pub fn set_normalised(&mut self, normalised: T) { self.normalised = normalised; }
pub fn set_normalized(&mut self, normalized: T) { self.normalized = normalized; }
pub fn normalised(&self) -> &T { &self.normalised }
pub fn normalized(&self) -> &T { &self.normalized }
pub fn get_original_length(&self) -> usize { self.original.chars().count() }
}
@ -66,5 +66,5 @@ impl<T> PartialEq for Token<T>
where
T: PartialEq + Clone + Debug,
{
fn eq(&self, other: &Self) -> bool { self.normalised == other.normalised }
fn eq(&self, other: &Self) -> bool { self.normalized == other.normalized }
}

View file

@ -1,7 +1,7 @@
use super::token::Token;
/// Splits text on word boundaries creating tokens of alternating words and
/// whitespaces with the whitespaces getting unique IDs.
/// Splits text on word boundaries, creating tokens of alternating words and
/// whitespace with the whitespace getting unique IDs.
///
/// ## Example
///
@ -9,7 +9,7 @@ use super::token::Token;
/// "Hi there!" -> ["Hi", " ", "there!"]
/// ```
pub fn word_tokenizer(text: &str) -> Vec<Token<String>> {
let mut result: Vec<Token<String>> = Vec::new();
let mut result = Vec::new();
let mut previous_boundary_index = 0;
let mut previous_char_is_whitespace = text.chars().next().is_none_or(char::is_whitespace);
@ -32,10 +32,11 @@ pub fn word_tokenizer(text: &str) -> Vec<Token<String>> {
return result;
}
// normalize whitespace tokens by concatenating with the following token
for i in 0..result.len() - 1 {
if result[i].original().chars().all(char::is_whitespace) {
let normalised = result[i].normalised().to_owned() + result[i + 1].original();
result[i].set_normalised(normalised);
let normalized = result[i].normalized().to_owned() + result[i + 1].original();
result[i].set_normalized(normalized);
}
}

View file

@ -44,7 +44,7 @@ where
let max_d = (old.len() + new.len()).div_ceil(2) + 1;
let mut vb = V::new(max_d);
let mut vf = V::new(max_d);
let mut result: Vec<RawOperation<T>> = vec![];
let mut result = Vec::new();
conquer(
old,