diff --git a/crates/functions/src/text.rs b/crates/functions/src/text.rs index 1e789d0aa..8b344d0e6 100644 --- a/crates/functions/src/text.rs +++ b/crates/functions/src/text.rs @@ -111,12 +111,31 @@ fn len(a: &[Arg], _c: &mut dyn Ctx) -> R { num_val(text(a, 0)?.chars().count() as f64) } +fn lower_char(ch: char) -> char { + match ch.to_lowercase().next() { + Some(lower) => lower, + None => ch, + } +} + +fn upper_char(ch: char) -> char { + let mut uppercase = ch.to_uppercase(); + match uppercase.next() { + Some(upper) if uppercase.next().is_none() => upper, + _ => ch, + } +} + +fn proper_upper_char(ch: char) -> char { + if ch == '\u{130}' { 'I' } else { upper_char(ch) } +} + fn lower(a: &[Arg], _c: &mut dyn Ctx) -> R { - text_val(text(a, 0)?.to_lowercase()) + text_val(text(a, 0)?.chars().map(lower_char).collect::()) } fn upper(a: &[Arg], _c: &mut dyn Ctx) -> R { - text_val(text(a, 0)?.to_uppercase()) + text_val(text(a, 0)?.chars().map(upper_char).collect::()) } fn proper(a: &[Arg], _c: &mut dyn Ctx) -> R { @@ -126,9 +145,9 @@ fn proper(a: &[Arg], _c: &mut dyn Ctx) -> R { for ch in s.chars() { if ch.is_alphabetic() { if prev_letter { - out.extend(ch.to_lowercase()); + out.push(lower_char(ch)); } else { - out.extend(ch.to_uppercase()); + out.push(proper_upper_char(ch)); } prev_letter = true; } else { @@ -1127,6 +1146,20 @@ mod tests { fn case_and_cleanup() { is_text(ev("UPPER", vec![t("abc")]), "ABC"); is_text(ev("LOWER", vec![t("ABC")]), "abc"); + is_text(ev("UPPER", vec![t("Straße")]), "STRAßE"); + is_text(ev("LOWER", vec![t("İ")]), "i"); + is_text(ev("PROPER", vec![t("İSTANBUL")]), "Istanbul"); + is_text(ev("PROPER", vec![t("ß")]), "ß"); + is_text(ev("PROPER", vec![t("ÉCOLE")]), "École"); + let proper = ev("PROPER", vec![t("İSTANBUL Straße")]); + is_text(proper.clone(), "Istanbul Straße"); + assert_eq!( + match proper { + Value::Text(s) => s.chars().count(), + _ => 0, + }, + "Istanbul Straße".chars().count() + ); is_text(ev("PROPER", vec![t("this is a TITLE")]), "This Is A Title"); is_text(ev("PROPER", vec![t("2-way street's")]), "2-Way Street'S"); is_text(ev("TRIM", vec![t(" a b c ")]), "a b c"); diff --git a/docs/function-parity.md b/docs/function-parity.md index caab31fab..7d511c8e6 100644 --- a/docs/function-parity.md +++ b/docs/function-parity.md @@ -1,6 +1,6 @@ # Function parity: worksheet functions and formulas -> **Last reviewed:** 2026-10-31 · **Last updated:** 2026-10-31 · **Change:** minor (UNICHAR returns `#N/A` for Unicode noncharacters, as observed in Excel; earlier: BITLSHIFT and BITRSHIFT return zero for zero operands with shifts beyond 53 bits, as observed in Excel; earlier: ECMA.CEILING listed with USDOLLAR as not on Microsoft's list; IMSQRT reproduces Excel's stray real part for negative reals) · **Target:** Microsoft Excel (Microsoft 365), Excel for Mac 16.113.4 +> **Last reviewed:** 2026-10-31 · **Last updated:** 2026-10-31 · **Change:** minor (UPPER, LOWER and PROPER use single-character Unicode casing to match measured Excel results; locale check: Windows Excel 16.0 build 20527, LCID 1033; earlier: UNICHAR returns `#N/A` for Unicode noncharacters, as observed in Excel; earlier: ECMA.CEILING listed with USDOLLAR as not on Microsoft's list; IMSQRT reproduces the stray real part Excel gives for negative reals, and the other IM* differences from Excel are listed; the LAMBDA row lists the recursion limit and its `#NUM!`, and the error a defined name holding an error gives when called; number text with accounting parentheses coerces like Excel 365; INDEX with one index on a 2-D reference is #REF! as in Excel; SUBTOTAL and AGGREGATE cap the cells they visit, #2175) · **Target:** Microsoft Excel (Microsoft 365), Excel for Mac 16.113.4 Excel's worksheet functions, category by category, against GridCraft's function library. Part of [target-app-parity.md](target-app-parity.md); gaps feed [gaps.md](gaps.md). @@ -128,6 +128,7 @@ workbooks; results checked in as data, not Excel files) and fixing what it finds | 2026-10-31 | minor | DEC2BIN, DEC2HEX and DEC2OCT validate `places` before returning negative two's-complement output, and Boolean places return `#VALUE!`, matching Excel | | 2026-10-31 | minor | BITLSHIFT and BITRSHIFT return `0` for zero operands shifted beyond 53 bits in either direction; nonzero operands retain the `#NUM!` limit, matching Excel | | 2026-10-31 | minor | UNICHAR returns `#N/A` for U+FDD0–U+FDEF and U+FFFE/U+FFFF on every plane; adjacent valid characters and existing invalid-range/surrogate errors remain unchanged, matching Excel | +| 2026-10-31 | minor | UPPER, LOWER and PROPER use single-character casing: `UPPER("Straße")` keeps ß, `LOWER("İ")` returns i, and `PROPER("İSTANBUL")` returns Istanbul, matching Windows Excel 16.0 build 20527 in LCID 1033 | | 2026-10-27 | minor | ECMA.CEILING added to the functions that are in our library but not on Microsoft's list (with USDOLLAR), so the counts don't change | | 2026-10-26 | minor | IMSQRT uses Excel's polar route with its cosine reduction, so `IMSQRT("-4")` is `1.22514845490862E-16+2i` as in Excel (exact `2i` before); the rows list the IM* differences still open | | 2026-10-25 | minor | LAMBDA row: a LAMBDA that calls itself more than 140 times, and a formula nested past the depth limit, give `#NUM!` (#1809; nesting gave `#CALC!` before). `=Foo(1)` where the defined name Foo holds `#N/A` gives `#N/A`, not `#NAME?` |