Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

format_to and format_to_n failes with option '=' on 'f' #756

Closed
ck3d opened this issue Jun 3, 2018 · 1 comment
Closed

format_to and format_to_n failes with option '=' on 'f' #756

ck3d opened this issue Jun 3, 2018 · 1 comment

Comments

@ck3d
Copy link

ck3d commented Jun 3, 2018

Following code example shows, that format_to and format_to_n fails to format floats while using option '='. (fmtlib version 5.0.0)

#include <fmt/format.h>
#include <array>
#include <cassert>
#include <string>

using namespace fmt;

int main() {
  std::array<char, 6> buffer;
  auto format = "{0:0=+6.2f}";

  // passing case
  assert(fmt::format(format, -3.8) == "-03.80");

  // failing cases
  assert(fmt::format_to(buffer.begin(), format, 3.21) == buffer.end()); // got buffer.end() -1
  assert(std::string(buffer.data(), buffer.size()) == "+03.21"); // got "03.21 "

  assert(fmt::format_to_n(buffer.begin(), buffer.size(), format, -1.23).size ==
         buffer.size()); // got 5 instead of 6

  assert(std::string(buffer.data(), buffer.size()) == "-01.23"); // got "01.23 "
}
@vitaut
Copy link
Contributor

vitaut commented Jun 7, 2018

Fixed in fc6e0fe & 1b8a7f8, thanks a lot for reporting!

@vitaut vitaut closed this as completed Jun 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants