summaryrefslogtreecommitdiff
path: root/library/src/compute
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-02-13 16:51:30 +0100
committerLaurenz <laurmaedje@gmail.com>2023-02-13 16:54:05 +0100
commit05c8c6045cd831a98776b418a7b176af8c6ec546 (patch)
treef0c59c273f98d83210c7ed2a01e6c1d81023287e /library/src/compute
parent8f68bc7a8ea619af12d95bec7025bd9f3a86625f (diff)
Configurable numbering for nested enums
Diffstat (limited to 'library/src/compute')
-rw-r--r--library/src/compute/utility.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/library/src/compute/utility.rs b/library/src/compute/utility.rs
index cb765577..2220c890 100644
--- a/library/src/compute/utility.rs
+++ b/library/src/compute/utility.rs
@@ -176,6 +176,24 @@ impl NumberingPattern {
fmt.push_str(&self.suffix);
fmt
}
+
+ /// Apply only the k-th segment of the pattern to a number.
+ pub fn apply_kth(&self, k: usize, number: NonZeroUsize) -> EcoString {
+ let mut fmt = EcoString::new();
+ if let Some((prefix, _, _)) = self.pieces.first() {
+ fmt.push_str(prefix);
+ }
+ if let Some((_, kind, case)) = self
+ .pieces
+ .iter()
+ .chain(self.pieces.last().into_iter().cycle())
+ .nth(k)
+ {
+ fmt.push_str(&kind.apply(number, *case));
+ }
+ fmt.push_str(&self.suffix);
+ fmt
+ }
}
impl FromStr for NumberingPattern {