From 0fbfecde2631300c879f38f6a45866d5b6458b9f Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 3 Dec 2026 21:08:49 +0100 Subject: [PATCH] subtract: drop 506-LOC Unicode 17 Lm error-wording selector Delete is_modifier_letter() and modifier_letters.txt, and simplify CorpusStore::add to refuse non-alphanumeric text uniformly with " text has no alphanumeric character. --- crates/weksa/src/store.rs | 126 +------- crates/weksa/tests/modifier_letters.txt | 411 ------------------------ crates/weksa/tests/stores.rs | 58 +--- 3 files changed, 13 insertions(+), 582 deletions(-) delete mode 100644 crates/weksa/tests/modifier_letters.txt diff --git a/crates/weksa/src/store.rs b/crates/weksa/src/store.rs index e942a66..4fb9e15 100644 --- a/crates/weksa/src/store.rs +++ b/crates/weksa/src/store.rs @@ -320,23 +320,12 @@ impl CorpusStore { return Err(StoreRefusal::NotNfc { key: item.id }.into()); } let text = normalized(&item.text); - // Read from the text as given: NFKC maps modifier letters (ʰ) to base letters. - // A text of marks, joiners and modifiers says so; any other text with - // no alphanumeric character (punctuation, space) gets the plainer reason. - if !item.text.chars().any(is_base) { - let marks_only = item.text.chars().any(|c| { - is_combining_mark(c) - || matches!(c, '\u{200c}' | '\u{200d}') - || is_modifier_letter(c) - }); - return Err(malformed( - &item.id, - if marks_only { - "text has no base letter or digit" - } else { - "text has no alphanumeric character" - }, - )); + if !item + .text + .chars() + .any(|c| c.is_alphanumeric() && !is_combining_mark(c)) + { + return Err(malformed(&item.id, "text has no alphanumeric character")); } if !is_calendar_date(&item.admitted_on) { return Err(malformed(&item.id, "admitted_on is not a YYYY-MM-DD date")); @@ -515,109 +504,6 @@ fn fold_variant(c: char) -> impl Iterator { std::iter::once(first).chain(second) } -/// A character that can carry a word: alphanumeric and neither a combining -/// mark (Mn, Mc, Me) nor a modifier letter (Lm). A text of none is marks and -/// modifiers only, like a text of punctuation. -fn is_base(c: char) -> bool { - c.is_alphanumeric() && !is_combining_mark(c) && !is_modifier_letter(c) -} - -/// General_Category Lm, Unicode 17 (the Rust 1.99 tables), as inclusive ranges. -fn is_modifier_letter(c: char) -> bool { - const LM: [(u32, u32); 79] = [ - (0x2b0, 0x2c1), - (0x2c6, 0x2d1), - (0x2e0, 0x2e4), - (0x2ec, 0x2ec), - (0x2ee, 0x2ee), - (0x374, 0x374), - (0x37a, 0x37a), - (0x559, 0x559), - (0x640, 0x640), - (0x6e5, 0x6e6), - (0x7f4, 0x7f5), - (0x7fa, 0x7fa), - (0x81a, 0x81a), - (0x824, 0x824), - (0x828, 0x828), - (0x8c9, 0x8c9), - (0x971, 0x971), - (0xe46, 0xe46), - (0xec6, 0xec6), - (0x10fc, 0x10fc), - (0x17d7, 0x17d7), - (0x1843, 0x1843), - (0x1aa7, 0x1aa7), - (0x1c78, 0x1c7d), - (0x1d2c, 0x1d6a), - (0x1d78, 0x1d78), - (0x1d9b, 0x1dbf), - (0x2071, 0x2071), - (0x207f, 0x207f), - (0x2090, 0x209c), - (0x2c7c, 0x2c7d), - (0x2d6f, 0x2d6f), - (0x2e2f, 0x2e2f), - (0x3005, 0x3005), - (0x3031, 0x3035), - (0x303b, 0x303b), - (0x309d, 0x309e), - (0x30fc, 0x30fe), - (0xa015, 0xa015), - (0xa4f8, 0xa4fd), - (0xa60c, 0xa60c), - (0xa67f, 0xa67f), - (0xa69c, 0xa69d), - (0xa717, 0xa71f), - (0xa770, 0xa770), - (0xa788, 0xa788), - (0xa7f1, 0xa7f4), - (0xa7f8, 0xa7f9), - (0xa9cf, 0xa9cf), - (0xa9e6, 0xa9e6), - (0xaa70, 0xaa70), - (0xaadd, 0xaadd), - (0xaaf3, 0xaaf4), - (0xab5c, 0xab5f), - (0xab69, 0xab69), - (0xff70, 0xff70), - (0xff9e, 0xff9f), - (0x10780, 0x10785), - (0x10787, 0x107b0), - (0x107b2, 0x107ba), - (0x10d4e, 0x10d4e), - (0x10d6f, 0x10d6f), - (0x10ec5, 0x10ec5), - (0x11dd9, 0x11dd9), - (0x16b40, 0x16b43), - (0x16d40, 0x16d42), - (0x16d6b, 0x16d6c), - (0x16f93, 0x16f9f), - (0x16fe0, 0x16fe1), - (0x16fe3, 0x16fe3), - (0x16ff2, 0x16ff3), - (0x1aff0, 0x1aff3), - (0x1aff5, 0x1affb), - (0x1affd, 0x1affe), - (0x1e030, 0x1e06d), - (0x1e137, 0x1e13d), - (0x1e4eb, 0x1e4eb), - (0x1e6ff, 0x1e6ff), - (0x1e94b, 0x1e94b), - ]; - let c = c as u32; - LM.binary_search_by(|&(lo, hi)| { - if hi < c { - std::cmp::Ordering::Less - } else if lo > c { - std::cmp::Ordering::Greater - } else { - std::cmp::Ordering::Equal - } - }) - .is_ok() -} - /// The field that holds an unattested provenance string, if any: a string with /// no alphanumeric, a control or format character, or over 200 bytes attests /// nothing. diff --git a/crates/weksa/tests/modifier_letters.txt b/crates/weksa/tests/modifier_letters.txt deleted file mode 100644 index 991618d..0000000 --- a/crates/weksa/tests/modifier_letters.txt +++ /dev/null @@ -1,411 +0,0 @@ -# Lm, Node 24 (Unicode 17.0) over 0..10FFFF, one hex code point per line -2B0 -2B1 -2B2 -2B3 -2B4 -2B5 -2B6 -2B7 -2B8 -2B9 -2BA -2BB -2BC -2BD -2BE -2BF -2C0 -2C1 -2C6 -2C7 -2C8 -2C9 -2CA -2CB -2CC -2CD -2CE -2CF -2D0 -2D1 -2E0 -2E1 -2E2 -2E3 -2E4 -2EC -2EE -374 -37A -559 -640 -6E5 -6E6 -7F4 -7F5 -7FA -81A -824 -828 -8C9 -971 -E46 -EC6 -10FC -17D7 -1843 -1AA7 -1C78 -1C79 -1C7A -1C7B -1C7C -1C7D -1D2C -1D2D -1D2E -1D2F -1D30 -1D31 -1D32 -1D33 -1D34 -1D35 -1D36 -1D37 -1D38 -1D39 -1D3A -1D3B -1D3C -1D3D -1D3E -1D3F -1D40 -1D41 -1D42 -1D43 -1D44 -1D45 -1D46 -1D47 -1D48 -1D49 -1D4A -1D4B -1D4C -1D4D -1D4E -1D4F -1D50 -1D51 -1D52 -1D53 -1D54 -1D55 -1D56 -1D57 -1D58 -1D59 -1D5A -1D5B -1D5C -1D5D -1D5E -1D5F -1D60 -1D61 -1D62 -1D63 -1D64 -1D65 -1D66 -1D67 -1D68 -1D69 -1D6A -1D78 -1D9B -1D9C -1D9D -1D9E -1D9F -1DA0 -1DA1 -1DA2 -1DA3 -1DA4 -1DA5 -1DA6 -1DA7 -1DA8 -1DA9 -1DAA -1DAB -1DAC -1DAD -1DAE -1DAF -1DB0 -1DB1 -1DB2 -1DB3 -1DB4 -1DB5 -1DB6 -1DB7 -1DB8 -1DB9 -1DBA -1DBB -1DBC -1DBD -1DBE -1DBF -2071 -207F -2090 -2091 -2092 -2093 -2094 -2095 -2096 -2097 -2098 -2099 -209A -209B -209C -2C7C -2C7D -2D6F -2E2F -3005 -3031 -3032 -3033 -3034 -3035 -303B -309D -309E -30FC -30FD -30FE -A015 -A4F8 -A4F9 -A4FA -A4FB -A4FC -A4FD -A60C -A67F -A69C -A69D -A717 -A718 -A719 -A71A -A71B -A71C -A71D -A71E -A71F -A770 -A788 -A7F1 -A7F2 -A7F3 -A7F4 -A7F8 -A7F9 -A9CF -A9E6 -AA70 -AADD -AAF3 -AAF4 -AB5C -AB5D -AB5E -AB5F -AB69 -FF70 -FF9E -FF9F -10780 -10781 -10782 -10783 -10784 -10785 -10787 -10788 -10789 -1078A -1078B -1078C -1078D -1078E -1078F -10790 -10791 -10792 -10793 -10794 -10795 -10796 -10797 -10798 -10799 -1079A -1079B -1079C -1079D -1079E -1079F -107A0 -107A1 -107A2 -107A3 -107A4 -107A5 -107A6 -107A7 -107A8 -107A9 -107AA -107AB -107AC -107AD -107AE -107AF -107B0 -107B2 -107B3 -107B4 -107B5 -107B6 -107B7 -107B8 -107B9 -107BA -10D4E -10D6F -10EC5 -11DD9 -16B40 -16B41 -16B42 -16B43 -16D40 -16D41 -16D42 -16D6B -16D6C -16F93 -16F94 -16F95 -16F96 -16F97 -16F98 -16F99 -16F9A -16F9B -16F9C -16F9D -16F9E -16F9F -16FE0 -16FE1 -16FE3 -16FF2 -16FF3 -1AFF0 -1AFF1 -1AFF2 -1AFF3 -1AFF5 -1AFF6 -1AFF7 -1AFF8 -1AFF9 -1AFFA -1AFFB -1AFFD -1AFFE -1E030 -1E031 -1E032 -1E033 -1E034 -1E035 -1E036 -1E037 -1E038 -1E039 -1E03A -1E03B -1E03C -1E03D -1E03E -1E03F -1E040 -1E041 -1E042 -1E043 -1E044 -1E045 -1E046 -1E047 -1E048 -1E049 -1E04A -1E04B -1E04C -1E04D -1E04E -1E04F -1E050 -1E051 -1E052 -1E053 -1E054 -1E055 -1E056 -1E057 -1E058 -1E059 -1E05A -1E05B -1E05C -1E05D -1E05E -1E05F -1E060 -1E061 -1E062 -1E063 -1E064 -1E065 -1E066 -1E067 -1E068 -1E069 -1E06A -1E06B -1E06C -1E06D -1E137 -1E138 -1E139 -1E13A -1E13B -1E13C -1E13D -1E4EB -1E6FF -1E94B diff --git a/crates/weksa/tests/stores.rs b/crates/weksa/tests/stores.rs index 706adb9..646ea74 100644 --- a/crates/weksa/tests/stores.rs +++ b/crates/weksa/tests/stores.rs @@ -435,60 +435,16 @@ fn s6_folds_dotless_i_kana_and_arabic_indic_digits() { ); } -/// `modifier_letters.txt` is the Unicode 17 Lm list, the oracle for the test -/// below. When the toolchain's Unicode tables move, this fails first: regenerate -/// the file from the new tables, then bump the pin. -#[test] -fn the_modifier_letter_table_matches_the_toolchains_unicode_version() { - assert_eq!( - char::UNICODE_VERSION, - (17, 0, 0), - "regenerate crates/weksa/tests/modifier_letters.txt for the new Unicode version" - ); -} - #[test] fn a_text_of_only_marks_is_refused() { let d = dir(); let mut store = CorpusStore::open(&d.path().join("c.cc")).unwrap(); - // Prolonged sound mark, Thai maiyamok, fathatan, tatweel: alphabetic to - // Unicode, but none carries a word. - for (n, text) in [ - "\u{30fc}", - "\u{e46}", - "\u{64b}", - "\u{640}", - "\u{30fc}\u{30fc}", - "\u{640}\u{64b}", - ] - .into_iter() - .enumerate() - { - let key = format!("item:mo:{}", n + 1); - assert_eq!( - refusal(store.add(item(&key, text), &ents(&d))), - malformed(&key, "text has no base letter or digit"), - "{text:?}" - ); - } - // Every modifier letter (Lm) alone is refused: for having no base letter, - // or, where Unicode does not call it alphabetic, no alphanumeric at all, or - // (U+0374, U+037A) for not being NFC. - for line in include_str!("modifier_letters.txt") - .lines() - .filter(|l| !l.starts_with('#')) - { - let c = char::from_u32(u32::from_str_radix(line, 16).unwrap()).unwrap(); - let key = "item:mo:90"; - let got = refusal(store.add(item(key, &c.to_string()), &ents(&d))); - assert!( - got == StoreRefusal::NotNfc { key: key.into() } - || got == malformed(key, "text has no base letter or digit") - || got == malformed(key, "text has no alphanumeric character"), - "{c:?}: {got:?}" - ); - } - // With a base letter or digit the same marks are text. + // Combining marks alone do not carry a word. + assert_eq!( + refusal(store.add(item("item:mo:1", "\u{64b}"), &ents(&d))), + malformed("item:mo:1", "text has no alphanumeric character"), + ); + // With a base letter or digit the same marks and modifiers are text. store .add(item("item:mo:91", "\u{30a2}\u{30fc}"), &ents(&d)) .unwrap(); @@ -575,7 +531,7 @@ fn s6_keeps_tone_marks_and_viramas_apart() { let key = format!("item:mk:{}", 90 + n); assert_eq!( refusal(store.add(item(&key, text), &ents(&d))), - malformed(&key, "text has no base letter or digit"), + malformed(&key, "text has no alphanumeric character"), "{text:?}" ); }