From 1d6d44f4e98acb164efc043cba5ef9b1209f520c Mon Sep 17 00:00:00 2001 From: memeplex Date: Mon, 23 Jul 2018 10:49:02 -0300 Subject: [PATCH] feat(token): Zero pad when min val starts with '0' (#1341) Closes #1332 --- include/drawtypes/label.hpp | 1 + src/drawtypes/label.cpp | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/include/drawtypes/label.hpp b/include/drawtypes/label.hpp index 3b88c40a..06f1158d 100644 --- a/include/drawtypes/label.hpp +++ b/include/drawtypes/label.hpp @@ -19,6 +19,7 @@ namespace drawtypes { size_t min{0_z}; size_t max{0_z}; string suffix{""s}; + bool zpad{false}; }; class label; diff --git a/src/drawtypes/label.cpp b/src/drawtypes/label.cpp index ca7740da..1ec4c776 100644 --- a/src/drawtypes/label.cpp +++ b/src/drawtypes/label.cpp @@ -52,7 +52,7 @@ namespace drawtypes { if (tok.max != 0_z && string_util::char_len(repl) > tok.max) { repl = string_util::utf8_truncate(std::move(repl), tok.max) + tok.suffix; } else if (tok.min != 0_z && repl.length() < tok.min) { - repl.insert(0_z, tok.min - repl.length(), ' '); + repl.insert(0_z, tok.min - repl.length(), tok.zpad ? '0' : ' '); } /* @@ -195,6 +195,8 @@ namespace drawtypes { try { token.min = std::stoul(&token_str[pos + 1], nullptr, 10); + // When the number starts with 0 the string is 0-padded + token.zpad = token_str[pos + 1] == '0'; } catch (const std::invalid_argument& err) { continue; }