Sha256: 62fe789e998541ab207d9c0120a8b113a9e1cba17a66ee42e253416719d2aeb9
Contents?: true
Size: 1.19 KB
Versions: 3
Compression:
Stored size: 1.19 KB
Contents
// -*- c++ -*- #include "rucy/string.h" #include <stdio.h> #include <stdarg.h> #include <boost/scoped_array.hpp> namespace Rucy { String stringf (const char* format, ...) { va_list args; va_start(args, format); String ret = stringf(format, args); va_end(args); return ret; } String stringf (const char* format, va_list args) { enum {BUFSIZE = 256}; char stack[BUFSIZE]; if (vsnprintf(&stack[0], BUFSIZE, format, args) <= BUFSIZE) return &stack[0]; int bufsize = BUFSIZE;// vscprintf(format, args); boost::scoped_array<char> heap; while (true) { bufsize *= 2; heap.reset(new char[bufsize]); if (vsnprintf(&heap[0], bufsize, format, args) <= bufsize) return &heap[0]; } return NULL; } template <> String to_s<int> (const int& val) { return stringf("%d", val); } template <> String to_s<float> (const float& val) { return stringf("%f", val); } template <> String to_s<double> (const double& val) { return stringf("%f", val); } typedef const char* const_char_p; template <> String to_s<const_char_p> (const const_char_p& val) { return val; } template <> String to_s<String> (const String& val) { return val; } }// Rucy
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
rucy-0.1.2 | src/string.cpp |
rucy-0.1.1 | src/string.cpp |
rucy-0.1.0 | src/string.cpp |