diff options
Diffstat (limited to 'cxxformat.hpp')
| -rw-r--r-- | cxxformat.hpp | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/cxxformat.hpp b/cxxformat.hpp index 1dd919e..79f16e5 100644 --- a/cxxformat.hpp +++ b/cxxformat.hpp @@ -287,20 +287,24 @@ namespace detail checkFmtLength(); std::string specification{"%"}; - const auto flag = fmt[++i]; - if (flag == '%') // handle %% here + if (fmt[i + 1] == '%') // handle %% here { return std::string{fmt.substr(0, directiveStart + 1)} + format(fmt.substr(i + 1), argumentIndex, std::forward<Arg>(arg), std::forward<Args>(args)...); } - switch (flag) + while(i < fmtSize - 1) { - case '#': case '0': case '-': case ' ': case '+': - specification.push_back(flag); - checkFmtLength(); - break; - default: - --i; + switch (const auto flag = fmt[++i]) + { + case '#': case '0': case '-': case ' ': case '+': + specification.push_back(flag); + checkFmtLength(); + break; + default: + --i; + goto afterFlagLoop; + } } + afterFlagLoop: std::string tempNumber; // field width @@ -570,12 +574,12 @@ namespace detail else return format_s<fmt, i + 1, argumentIndex>(); } - template<auto fmt, size_t i> - constexpr std::pair<char, size_t> getFlag() + template<auto fmt, size_t i, size_t offset = 0> + constexpr size_t getFlagEnd() { - constexpr char next = get<i>(fmt); - if constexpr (next == '#' || next == '0' || next == '-' || next == ' ' || next == '+') return {next, i + 1}; - else return {0, i}; + constexpr char next = get<i + offset>(fmt); + if constexpr (next == '#' || next == '0' || next == '-' || next == ' ' || next == '+') return getFlagEnd<fmt, i, offset + 1>(); + else return i + offset; } template<auto fmt, size_t i> @@ -618,9 +622,7 @@ namespace detail { if constexpr (get<i + 1>(fmt) == '%') return substr<0, i, true>(fmt).s + format_s<substr<i + 2>(fmt), 0, argumentIndex>(std::forward<Arg>(arg), std::forward<Args>(args)...); - constexpr auto flagData = getFlag<fmt, i + 1>(); - constexpr char flag = flagData.first; - constexpr char iAfterFlag = flagData.second; + constexpr char iAfterFlag = getFlagEnd<fmt, i + 1>(); constexpr size_t iAfterFieldWidth = getNumberEnd<fmt, iAfterFlag>(); constexpr auto havePrecision = get<iAfterFieldWidth>(fmt) == '.'; |
