Given that we have two separate number "parsers" (one that keeps the result and one that throws it away), we might as well extract number parsing to a local lambda like you did with the other ones.
<details>
<summary>Diff</summary>
diff --git a/src/util/string.h b/src/util/string.h
--- a/src/util/string.h (revision ecc5cb9a89c6b001df839675b23d8fc1f7ac69ba)
+++ b/src/util/string.h (date 1731267170701)
@@ -45,14 +45,16 @@
continue;
}
+ auto parse_number = [&] {
+ unsigned num{0};
+ for (; '0' <= *it && *it <= '9'; ++it) {
+ num = num * 10 + (*it - '0');
+ }
+ return num;
+ };
+
auto add_arg = [&] {
- unsigned maybe_num{0};
- while ('0' <= *it && *it <= '9') {
- maybe_num *= 10;
- maybe_num += *it - '0';
- ++it;
- }
-
+ unsigned maybe_num = parse_number();
if (*it == '$') {
++it;
// Positional specifier, like %8$s
@@ -75,7 +77,7 @@
++it;
add_arg();
} else {
- while ('0' <= *it && *it <= '9') ++it;
+ parse_number();
}
};
</details>