summaryrefslogtreecommitdiff
path: root/boost/convert/base.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/convert/base.hpp')
-rw-r--r--boost/convert/base.hpp56
1 files changed, 23 insertions, 33 deletions
diff --git a/boost/convert/base.hpp b/boost/convert/base.hpp
index 27931194cc..678d99cfc6 100644
--- a/boost/convert/base.hpp
+++ b/boost/convert/base.hpp
@@ -7,7 +7,6 @@
#include <boost/convert/parameters.hpp>
#include <boost/convert/detail/is_string.hpp>
-#include <cctype>
#include <cstring>
namespace boost { namespace cnv
@@ -106,19 +105,13 @@ struct boost::cnv::cnvbase
void
str_to_(string_type const& str, optional<out_type>& result_out) const
{
- using range_type = cnv::range<string_type const>;
- using char_type = typename range_type::value_type;
+ cnv::range<string_type const> range (str);
- range_type range (str);
- auto is_space = [](char_type ch)
- {
- return std::isspace(static_cast<unsigned char>(ch));
- };
if (skipws_)
- for (; !range.empty() && is_space(*range.begin()); ++range);
+ for (; !range.empty() && cnv::is_space(*range.begin()); ++range);
- if (range.empty()) return;
- if (is_space(*range.begin())) return;
+ if (range.empty()) return;
+ if (cnv::is_space(*range.begin())) return;
dncast().str_to(range, result_out);
}
@@ -126,35 +119,31 @@ struct boost::cnv::cnvbase
void
to_str_(in_type value_in, optional<string_type>& result_out) const
{
- using range_type = cnv::range<string_type>;
- using char_type = typename range_type::value_type;
+ using char_type = typename cnv::range<string_type>::value_type;
+ using range_type = cnv::range<char_type*>;
+ using buf_type = char_type[bufsize_];
- char_type buf[bufsize_];
- cnv::range<char_type*> range = dncast().to_str(value_in, buf);
- char_type* beg = range.begin();
- char_type* end = range.end();
+ buf_type buf;
+ range_type range = dncast().to_str(value_in, buf);
+ char_type* beg = range.begin();
+ char_type* end = range.end();
+ int str_size = end - beg;
- if (beg < end)
- format_(buf, beg, end), result_out = string_type(beg, end);
- }
+ if (str_size <= 0)
+ return;
- template<typename char_type>
- void
- format_(char_type* buf, char_type*& beg, char_type*& end) const
- {
if (uppercase_)
- for (char_type* p = beg; p < end; ++p) *p = std::toupper(*p);
+ for (char_type* p = beg; p < end; ++p) *p = cnv::to_upper(*p);
if (width_)
{
- int num_fillers = (std::max)(0, int(width_ - (end - beg)));
- int num_left = adjust_ == boost::cnv::adjust::left ? 0
- : adjust_ == boost::cnv::adjust::right ? num_fillers
- : (num_fillers / 2);
- int num_right = num_fillers - num_left;
- int str_size = end - beg;
- bool move = (beg < buf + num_left) // No room for left fillers
- || (buf + bufsize_ < end + num_right); // No room for right fillers
+ int num_fill = (std::max)(0, int(width_ - (end - beg)));
+ int num_left = adjust_ == cnv::adjust::left ? 0
+ : adjust_ == cnv::adjust::right ? num_fill
+ : (num_fill / 2);
+ int num_right = num_fill - num_left;
+ bool move = (beg < buf + num_left) // No room for left fillers
+ || (buf + bufsize_ < end + num_right); // No room for right fillers
if (move)
{
std::memmove(buf + num_left, beg, str_size * sizeof(char_type));
@@ -164,6 +153,7 @@ struct boost::cnv::cnvbase
for (int k = 0; k < num_left; *(--beg) = fill_, ++k);
for (int k = 0; k < num_right; *(end++) = fill_, ++k);
}
+ result_out = string_type(beg, end);
}
derived_type const& dncast () const { return *static_cast<derived_type const*>(this); }