feat(token): Zero pad when min val starts with '0' (#1341)

Closes #1332
This commit is contained in:
memeplex 2018-07-23 10:49:02 -03:00 committed by Patrick Ziegler
parent 1808ca3c51
commit 1d6d44f4e9
2 changed files with 4 additions and 1 deletions

View File

@ -19,6 +19,7 @@ namespace drawtypes {
size_t min{0_z}; size_t min{0_z};
size_t max{0_z}; size_t max{0_z};
string suffix{""s}; string suffix{""s};
bool zpad{false};
}; };
class label; class label;

View File

@ -52,7 +52,7 @@ namespace drawtypes {
if (tok.max != 0_z && string_util::char_len(repl) > tok.max) { if (tok.max != 0_z && string_util::char_len(repl) > tok.max) {
repl = string_util::utf8_truncate(std::move(repl), tok.max) + tok.suffix; repl = string_util::utf8_truncate(std::move(repl), tok.max) + tok.suffix;
} else if (tok.min != 0_z && repl.length() < tok.min) { } 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 { try {
token.min = std::stoul(&token_str[pos + 1], nullptr, 10); 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) { } catch (const std::invalid_argument& err) {
continue; continue;
} }