Commit 4642983d authored by Kirill Smelkov's avatar Kirill Smelkov

X move fmt -> pygolang (there was a bug in the implementation and it needed tests)

parent f61e2be3
......@@ -23,6 +23,7 @@
#include <golang/libgolang.h>
#include <golang/errors.h>
#include <golang/fmt.h>
using namespace golang;
#include <inttypes.h>
......@@ -158,57 +159,6 @@ error map_into(void *addr, size_t size, int prot, int flags, const os::File f, o
} // mm::
// fmt::
namespace fmt {
static
string _vsprintf(const char *format, va_list argp) {
// based on https://stackoverflow.com/a/26221725/9456786
va_list argp2;
va_copy(argp2, argp);
size_t size = vsnprintf(NULL, 0, format, argp2);
va_end(argp2);
std::unique_ptr<char[]> buf( new char[size] );
vsnprintf(buf.get(), size, format, argp);
return string(buf.get(), buf.get() + size - 1 ); // without trailing '\0'
}
string sprintf(const string &format, ...) {
va_list argp;
va_start(argp, format);
string str = fmt::_vsprintf(format.c_str(), argp);
va_end(argp);
return str;
}
string sprintf(const char *format, ...) {
va_list argp;
va_start(argp, format);
string str = fmt::_vsprintf(format, argp);
va_end(argp);
return str;
}
error errorf(const string &format, ...) {
va_list argp;
va_start(argp, format);
error err = errors::New(fmt::sprintf(format.c_str(), argp));
va_end(argp);
return err;
}
error errorf(const char *format, ...) {
va_list argp;
va_start(argp, format);
error err = errors::New(fmt::sprintf(format, argp));
va_end(argp);
return err;
}
} // fmt::
// strings::
namespace strings {
......
......@@ -127,22 +127,6 @@ namespace mm {
} // mm::
// fmt::
namespace fmt {
string sprintf(const string &format, ...);
error errorf (const string &format, ...);
// `const char *` overload just to catch format mistakes as
// __attribute__(format) does not work with std::string.
string sprintf(const char *format, ...)
__attribute__ ((format (printf, 1, 2)));
error errorf (const char *format, ...)
__attribute__ ((format (printf, 1, 2)));
} // fmt::
// strings::
namespace strings {
......
......@@ -29,6 +29,8 @@
#include <wendelin/bigfile/ram.h>
//#include <wendelin/bug.h>
#include <golang/fmt.h>
#include <algorithm>
#include <string>
#include <vector>
......
......@@ -21,6 +21,7 @@
#include "wcfs.h"
#include "wcfs_watchlink.h"
#include <golang/fmt.h>
#include <string.h>
_WatchLink::_WatchLink() {}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment