feat(token): Zero pad when min val starts with '0' (#1341)
Closes #1332
This commit is contained in:
parent
1808ca3c51
commit
1d6d44f4e9
@ -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;
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user