This library is a C++11 compatible implementation of <charconv>. The full documentation can be found here: https://www.boost.org/doc/libs/master/libs/charconv/doc/html/charconv.html
| Master | Develop | |
|---|---|---|
| Github Actions | ||
| Drone | ||
| Codecov | ||
| Fuzzing |
git clone https://github.com/boostorg/boost
cd boost
git submodule update --init
cd ..
./bootstrap
./b2 cxxstd=11
This sets up a complete boost development and allows the tests to be run. To install the development environment run:
sudo ./b2 install cxxstd=11
Charconv is a collection of parsing functions that are locale-independent, non-allocating, and non-throwing.
namespace boost { namespace charconv {
enum class chars_format : unsigned
{
scientific = 1 << 0,
fixed = 1 << 1,
hex = 1 << 2,
general = fixed | scientific
};
struct from_chars_result
{
const char* ptr;
std::errc ec;
friend constexpr bool operator==(const from_chars_result& lhs, const from_chars_result& rhs) noexcept;
friend constexpr bool operator!=(const from_chars_result& lhs, const from_chars_result& rhs) noexcept;
constexpr explicit operator bool() const noexcept;
};
template <typename Integral>
BOOST_CXX14_CONSTEXPR from_chars_result from_chars(const char* first, const char* last, Integral& value, int base = 10) noexcept;
template <>
BOOST_CXX14_CONSTEXPR from_chars_result from_chars<bool>(const char* first, const char* last, bool& value, int base) noexcept = delete;
template <typename Real>
from_chars_result from_chars(const char* first, const char* last, Real& value, chars_format fmt = chars_format::general) noexcept;
template <typename Real>
from_chars_result from_chars_erange(const char* first, const char* last, Real& value, chars_format fmt = chars_format::general) noexcept;
struct to_chars_result
{
char* ptr;
std::errc ec;
friend constexpr bool operator==(const to_chars_result& lhs, const to_chars_result& rhs) noexcept;
friend constexpr bool operator!=(const to_chars_result& lhs, const to_chars_result& rhs) noexcept;
constexpr explicit operator bool() const noexcept;
};
template <typename Integral>
BOOST_CHARCONV_CONSTEXPR to_chars_result to_chars(char* first, char* last, Integral value, int base = 10) noexcept;
template <>
BOOST_CHARCONV_CONSTEXPR to_chars_result to_chars<bool>(char* first, char* last, bool value, int base) noexcept = delete;
template <typename Real>
to_chars_result to_chars(char* first, char* last, Real value, chars_format fmt = chars_format::general, int precision) noexcept;
}} // Namespace boost::charconv
BOOST_CXX14_CONSTEXPR is defined as constexpr when compiling with C++14 or newer.
BOOST_CHARCONV_CONSTEXPR is defined as constexpr when compiling with C++14 or newer, and the compiler has __builtin_is_constant_evaluated
For explanation of from_chars_erange see docs under heading: Usage notes for from_chars for floating point types
from_charsconst char* buffer = "42";
int v = 0;
from_chars_result r = boost::charconv::from_chars(buffer, buffer + std::strlen(buffer), v);
assert(r.ec == std::errc());
assert(r); // Equivalent to the above
assert(v == 42);
const char* buffer = "1.2345";
double v = 0;
auto r = boost::charconv::from_chars(buffer, buffer + std::strlen(buffer), v);
assert(r.ec == std::errc());
assert(v == 1.2345);
const char* buffer = "2a";
unsigned v = 0;
auto r = boost::charconv::from_chars(buffer, buffer + std::strlen(buffer), v, 16);
assert(r); // from_chars_result has operator bool()
assert(v == 42);
const char* buffer = "1.3a2bp-10";
double v = 0;
auto r = boost::charconv::from_chars(buffer, buffer + std::strlen(buffer), v, boost::charconv::chars_format::hex);
assert(r);
assert(v == 8.0427e-18);
to_charschar buffer[64] {};
int v = 42;
to_chars_result r = boost::charconv::to_chars(buffer, buffer + sizeof(buffer), v);
assert(r.ec == std::errc());
assert(!strcmp(buffer, "42")); // strcmp returns 0 on match
char buffer[64] {};
double v = 1e300;
to_chars_result r = boost::charconv::to_chars(buffer, buffer + sizeof(buffer), v);
assert(r.ec == std::errc());
assert(!strcmp(buffer, "1e+300"));
char buffer[64] {};
int v = 42;
to_chars_result r = boost::charconv::to_chars(buffer, buffer + sizeof(buffer), v, 16);
assert(r); // to_chars_result has operator bool()
assert(!strcmp(buffer, "2a")); // strcmp returns 0 on match
<h1>CharConv</h1> <p>This library is a C++11 compatible implementation of <code><charconv></code>. The full documentation can be found here: https://www.boost.org/doc/libs/master/libs/charconv/doc/html/charconv.html</p> <h1>Build Status</h1> <table> <thead> <tr> <th align="left"></th> <th align="left">Master</th> <th align="left">Develop</th> </tr> </thead> <tbody> <tr> <td align="left">Github Actions</td> <td align="left"><a href="https://github.com/boostorg/charconv/actions/workflows/ci.yml"><img src="https://github.com/boostorg/charconv/actions/workflows/ci.yml/badge.svg?branch=master" alt="CI" /></a></td> <td align="left"><a href="https://github.com/boostorg/charconv/actions/workflows/ci.yml"><img src="https://github.com/boostorg/charconv/workflows/CI/badge.svg?branch=develop" alt="Build Status" /></a></td> </tr> <tr> <td align="left">Drone</td> <td align="left"><a href="https://drone.cpp.al/boostorg/charconv"><img src="https://drone.cpp.al/api/badges/boostorg/charconv/status.svg?ref=refs/heads/master" alt="Build Status" /></a></td> <td align="left"><a href="https://drone.cpp.al/boostorg/charconv"><img src="https://drone.cpp.al/api/badges/boostorg/charconv/status.svg?ref=refs/heads/develop" alt="Build Status" /></a></td> </tr> <tr> <td align="left">Codecov</td> <td align="left"><a href="https://codecov.io/gh/boostorg/charconv/branch/master"><img src="https://codecov.io/gh/boostorg/charconv/branch/master/graph/badge.svg" alt="codecov" /></a></td> <td align="left"><a href="https://codecov.io/gh/boostorg/charconv/branch/develop"><img src="https://codecov.io/gh/boostorg/charconv/branch/develop/graph/badge.svg" alt="codecov" /></a></td> </tr> <tr> <td align="left">Fuzzing</td> <td align="left"><a href="https://github.com/boostorg/charconv/actions/workflows/fuzz.yml"><img src="https://github.com/boostorg/charconv/actions/workflows/fuzz.yml/badge.svg?branch=master" alt="Fuzz" /></a></td> <td align="left"><a href="https://github.com/boostorg/charconv/actions/workflows/fuzz.yml"><img src="https://github.com/boostorg/charconv/actions/workflows/fuzz.yml/badge.svg" alt="Fuzz" /></a></td> </tr> </tbody> </table> <h1>How to build the library</h1> <h2>B2</h2> <pre class="highlightjs highlight"><code class="language- hljs">git clone https://github.com/boostorg/boost cd boost git submodule update --init cd .. ./bootstrap ./b2 cxxstd=11 </code></pre> <p>This sets up a complete boost development and allows the tests to be run. To install the development environment run:</p> <pre class="highlightjs highlight"><code class="language- hljs">sudo ./b2 install cxxstd=11 </code></pre> <h1>Synopsis</h1> <p>Charconv is a collection of parsing functions that are locale-independent, non-allocating, and non-throwing.</p> <pre class="highlightjs highlight"><code class="language-cpp hljs">namespace boost { namespace charconv { enum class chars_format : unsigned { scientific = 1 << 0, fixed = 1 << 1, hex = 1 << 2, general = fixed | scientific }; struct from_chars_result { const char* ptr; std::errc ec; friend constexpr bool operator==(const from_chars_result& lhs, const from_chars_result& rhs) noexcept; friend constexpr bool operator!=(const from_chars_result& lhs, const from_chars_result& rhs) noexcept; constexpr explicit operator bool() const noexcept; }; template <typename Integral> BOOST_CXX14_CONSTEXPR from_chars_result from_chars(const char* first, const char* last, Integral& value, int base = 10) noexcept; template <> BOOST_CXX14_CONSTEXPR from_chars_result from_chars<bool>(const char* first, const char* last, bool& value, int base) noexcept = delete; template <typename Real> from_chars_result from_chars(const char* first, const char* last, Real& value, chars_format fmt = chars_format::general) noexcept; template <typename Real> from_chars_result from_chars_erange(const char* first, const char* last, Real& value, chars_format fmt = chars_format::general) noexcept; struct to_chars_result { char* ptr; std::errc ec; friend constexpr bool operator==(const to_chars_result& lhs, const to_chars_result& rhs) noexcept; friend constexpr bool operator!=(const to_chars_result& lhs, const to_chars_result& rhs) noexcept; constexpr explicit operator bool() const noexcept; }; template <typename Integral> BOOST_CHARCONV_CONSTEXPR to_chars_result to_chars(char* first, char* last, Integral value, int base = 10) noexcept; template <> BOOST_CHARCONV_CONSTEXPR to_chars_result to_chars<bool>(char* first, char* last, bool value, int base) noexcept = delete; template <typename Real> to_chars_result to_chars(char* first, char* last, Real value, chars_format fmt = chars_format::general, int precision) noexcept; }} // Namespace boost::charconv </code></pre> <h2>Notes</h2> <ul> <li> <p><code>BOOST_CXX14_CONSTEXPR</code> is defined as <code>constexpr</code> when compiling with C++14 or newer.</p> </li> <li> <p><code>BOOST_CHARCONV_CONSTEXPR</code> is defined as <code>constexpr</code> when compiling with C++14 or newer, and the compiler has <code>__builtin_is_constant_evaluated</code></p> </li> <li> <p>For explanation of <code>from_chars_erange</code> see docs under heading: <em>Usage notes for from_chars for floating point types</em></p> </li> </ul> <h1>Examples</h1> <h2><code>from_chars</code></h2> <pre class="highlightjs highlight"><code class="language-cpp hljs">const char* buffer = "42"; int v = 0; from_chars_result r = boost::charconv::from_chars(buffer, buffer + std::strlen(buffer), v); assert(r.ec == std::errc()); assert(r); // Equivalent to the above assert(v == 42); const char* buffer = "1.2345"; double v = 0; auto r = boost::charconv::from_chars(buffer, buffer + std::strlen(buffer), v); assert(r.ec == std::errc()); assert(v == 1.2345); const char* buffer = "2a"; unsigned v = 0; auto r = boost::charconv::from_chars(buffer, buffer + std::strlen(buffer), v, 16); assert(r); // from_chars_result has operator bool() assert(v == 42); const char* buffer = "1.3a2bp-10"; double v = 0; auto r = boost::charconv::from_chars(buffer, buffer + std::strlen(buffer), v, boost::charconv::chars_format::hex); assert(r); assert(v == 8.0427e-18); </code></pre> <h2><code>to_chars</code></h2> <pre class="highlightjs highlight"><code class="language-cpp hljs">char buffer[64] {}; int v = 42; to_chars_result r = boost::charconv::to_chars(buffer, buffer + sizeof(buffer), v); assert(r.ec == std::errc()); assert(!strcmp(buffer, "42")); // strcmp returns 0 on match char buffer[64] {}; double v = 1e300; to_chars_result r = boost::charconv::to_chars(buffer, buffer + sizeof(buffer), v); assert(r.ec == std::errc()); assert(!strcmp(buffer, "1e+300")); char buffer[64] {}; int v = 42; to_chars_result r = boost::charconv::to_chars(buffer, buffer + sizeof(buffer), v, 16); assert(r); // to_chars_result has operator bool() assert(!strcmp(buffer, "2a")); // strcmp returns 0 on match </code></pre>
<h1>CharConv</h1> <p>This library is a C++11 compatible implementation of <code><charconv></code>. The full documentation can be found here: https://www.boost.org/doc/libs/master/libs/charconv/doc/html/charconv.html</p> <h1>Build Status</h1> <table> <thead> <tr> <th align="left"></th> <th align="left">Master</th> <th align="left">Develop</th> </tr> </thead> <tbody> <tr> <td align="left">Github Actions</td> <td align="left"><a href="https://github.com/boostorg/charconv/actions/workflows/ci.yml"><img src="https://github.com/boostorg/charconv/actions/workflows/ci.yml/badge.svg?branch=master" alt="CI" /></a></td> <td align="left"><a href="https://github.com/boostorg/charconv/actions/workflows/ci.yml"><img src="https://github.com/boostorg/charconv/workflows/CI/badge.svg?branch=develop" alt="Build Status" /></a></td> </tr> <tr> <td align="left">Drone</td> <td align="left"><a href="https://drone.cpp.al/boostorg/charconv"><img src="https://drone.cpp.al/api/badges/boostorg/charconv/status.svg?ref=refs/heads/master" alt="Build Status" /></a></td> <td align="left"><a href="https://drone.cpp.al/boostorg/charconv"><img src="https://drone.cpp.al/api/badges/boostorg/charconv/status.svg?ref=refs/heads/develop" alt="Build Status" /></a></td> </tr> <tr> <td align="left">Codecov</td> <td align="left"><a href="https://codecov.io/gh/boostorg/charconv/branch/master"><img src="https://codecov.io/gh/boostorg/charconv/branch/master/graph/badge.svg" alt="codecov" /></a></td> <td align="left"><a href="https://codecov.io/gh/boostorg/charconv/branch/develop"><img src="https://codecov.io/gh/boostorg/charconv/branch/develop/graph/badge.svg" alt="codecov" /></a></td> </tr> <tr> <td align="left">Fuzzing</td> <td align="left"><a href="https://github.com/boostorg/charconv/actions/workflows/fuzz.yml"><img src="https://github.com/boostorg/charconv/actions/workflows/fuzz.yml/badge.svg?branch=master" alt="Fuzz" /></a></td> <td align="left"><a href="https://github.com/boostorg/charconv/actions/workflows/fuzz.yml"><img src="https://github.com/boostorg/charconv/actions/workflows/fuzz.yml/badge.svg" alt="Fuzz" /></a></td> </tr> </tbody> </table> <h1>How to build the library</h1> <h2>B2</h2> <pre class="highlightjs highlight"><code class="language- hljs">git clone https://github.com/boostorg/boost cd boost git submodule update --init cd .. ./bootstrap ./b2 cxxstd=11 </code></pre> <p>This sets up a complete boost development and allows the tests to be run. To install the development environment run:</p> <pre class="highlightjs highlight"><code class="language- hljs">sudo ./b2 install cxxstd=11 </code></pre> <h1>Synopsis</h1> <p>Charconv is a collection of parsing functions that are locale-independent, non-allocating, and non-throwing.</p> <pre class="highlightjs highlight"><code class="language-cpp hljs">namespace boost { namespace charconv { enum class chars_format : unsigned { scientific = 1 << 0, fixed = 1 << 1, hex = 1 << 2, general = fixed | scientific }; struct from_chars_result { const char* ptr; std::errc ec; friend constexpr bool operator==(const from_chars_result& lhs, const from_chars_result& rhs) noexcept; friend constexpr bool operator!=(const from_chars_result& lhs, const from_chars_result& rhs) noexcept; constexpr explicit operator bool() const noexcept; }; template <typename Integral> BOOST_CXX14_CONSTEXPR from_chars_result from_chars(const char* first, const char* last, Integral& value, int base = 10) noexcept; template <> BOOST_CXX14_CONSTEXPR from_chars_result from_chars<bool>(const char* first, const char* last, bool& value, int base) noexcept = delete; template <typename Real> from_chars_result from_chars(const char* first, const char* last, Real& value, chars_format fmt = chars_format::general) noexcept; template <typename Real> from_chars_result from_chars_erange(const char* first, const char* last, Real& value, chars_format fmt = chars_format::general) noexcept; struct to_chars_result { char* ptr; std::errc ec; friend constexpr bool operator==(const to_chars_result& lhs, const to_chars_result& rhs) noexcept; friend constexpr bool operator!=(const to_chars_result& lhs, const to_chars_result& rhs) noexcept; constexpr explicit operator bool() const noexcept; }; template <typename Integral> BOOST_CHARCONV_CONSTEXPR to_chars_result to_chars(char* first, char* last, Integral value, int base = 10) noexcept; template <> BOOST_CHARCONV_CONSTEXPR to_chars_result to_chars<bool>(char* first, char* last, bool value, int base) noexcept = delete; template <typename Real> to_chars_result to_chars(char* first, char* last, Real value, chars_format fmt = chars_format::general, int precision) noexcept; }} // Namespace boost::charconv </code></pre> <h2>Notes</h2> <ul> <li> <p><code>BOOST_CXX14_CONSTEXPR</code> is defined as <code>constexpr</code> when compiling with C++14 or newer.</p> </li> <li> <p><code>BOOST_CHARCONV_CONSTEXPR</code> is defined as <code>constexpr</code> when compiling with C++14 or newer, and the compiler has <code>__builtin_is_constant_evaluated</code></p> </li> <li> <p>For explanation of <code>from_chars_erange</code> see docs under heading: <em>Usage notes for from_chars for floating point types</em></p> </li> </ul> <h1>Examples</h1> <h2><code>from_chars</code></h2> <pre class="highlightjs highlight"><code class="language-cpp hljs">const char* buffer = "42"; int v = 0; from_chars_result r = boost::charconv::from_chars(buffer, buffer + std::strlen(buffer), v); assert(r.ec == std::errc()); assert(r); // Equivalent to the above assert(v == 42); const char* buffer = "1.2345"; double v = 0; auto r = boost::charconv::from_chars(buffer, buffer + std::strlen(buffer), v); assert(r.ec == std::errc()); assert(v == 1.2345); const char* buffer = "2a"; unsigned v = 0; auto r = boost::charconv::from_chars(buffer, buffer + std::strlen(buffer), v, 16); assert(r); // from_chars_result has operator bool() assert(v == 42); const char* buffer = "1.3a2bp-10"; double v = 0; auto r = boost::charconv::from_chars(buffer, buffer + std::strlen(buffer), v, boost::charconv::chars_format::hex); assert(r); assert(v == 8.0427e-18); </code></pre> <h2><code>to_chars</code></h2> <pre class="highlightjs highlight"><code class="language-cpp hljs">char buffer[64] {}; int v = 42; to_chars_result r = boost::charconv::to_chars(buffer, buffer + sizeof(buffer), v); assert(r.ec == std::errc()); assert(!strcmp(buffer, "42")); // strcmp returns 0 on match char buffer[64] {}; double v = 1e300; to_chars_result r = boost::charconv::to_chars(buffer, buffer + sizeof(buffer), v); assert(r.ec == std::errc()); assert(!strcmp(buffer, "1e+300")); char buffer[64] {}; int v = 42; to_chars_result r = boost::charconv::to_chars(buffer, buffer + sizeof(buffer), v, 16); assert(r); // to_chars_result has operator bool() assert(!strcmp(buffer, "2a")); // strcmp returns 0 on match </code></pre>