work on styles
authorBen Pfaff <blp@cs.stanford.edu>
Thu, 27 Mar 2025 00:11:44 +0000 (17:11 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Thu, 27 Mar 2025 00:11:44 +0000 (17:11 -0700)
rust/pspp/src/format/mod.rs

index 5a345f7cfc15a1b69377fbee54338e63c598f26d..f49a2a5fa8cfebab456cf246158740a6b2f08e6a 100644 (file)
@@ -855,10 +855,15 @@ impl From<&Settings> for StyleParams {
 struct StyleSet(EnumMap<StyleParams, NumberStyle>);
 
 impl StyleSet {
-    fn new(f: impl Fn(StyleParams) -> NumberStyle) -> Self {
-        Self(EnumMap::from_fn(f))
+    const fn new(f: impl Fn(StyleParams) -> NumberStyle) -> Self {
+        f(StyleParams {
+            decimal: Decimal::Comma,
+            leading_zero: false,
+        });
+        todo!()
+        //Self(EnumMap::from_fn(f))
     }
-    const fn get(&self, settings: &Settings) -> &NumberStyle {
+    fn get(&self, settings: &Settings) -> &NumberStyle {
         &self.0[settings.into()]
     }
 }
@@ -987,10 +992,6 @@ impl NumberStyle {
         let prefix = Affix::new_static(prefix);
         let suffix = Affix::new_static(suffix);
         let neg_suffix = Affix::new_static("");
-        let extra_bytes = neg_prefix.extra_bytes()
-            + prefix.extra_bytes()
-            + suffix.extra_bytes()
-            + neg_suffix.extra_bytes();
 
         Self {
             neg_prefix,
@@ -1000,7 +1001,7 @@ impl NumberStyle {
             decimal,
             grouping,
             leading_zero,
-            extra_bytes,
+            extra_bytes: 0,
         }
     }
 
@@ -1029,14 +1030,14 @@ impl Affix {
         }
     }
 
-    fn new(s: String) -> Self {
+    pub fn new(s: String) -> Self {
         Self {
             width: s.width(),
             s: Cow::from(s),
         }
     }
 
-    const fn extra_bytes(&self) -> usize {
+    pub fn extra_bytes(&self) -> usize {
         self.s.len().checked_sub(self.width).unwrap()
     }
 }