diff --git a/CMakeLists.txt b/CMakeLists.txt index 3d032a1..f6ceb25 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -620,6 +620,7 @@ set(ALL_TESTS session_interface_test secure_post_test mount_point_test + todec_test ) if(NOT DISABLE_TCPCACHE) @@ -701,6 +702,7 @@ install(DIRECTORY cppcms DESTINATION include set(CNF "${CMAKE_CURRENT_SOURCE_DIR}/tests") add_test(base64_test base64_test) +add_test(todec_test todec_test) add_test(encryptor_test encryptor_test "${CNF}") add_test(storage_test storage_test) add_test(json_test json_test) diff --git a/private/todec.h b/private/todec.h new file mode 100644 index 0000000..a30736c --- /dev/null +++ b/private/todec.h @@ -0,0 +1,112 @@ +/////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2008-2012 Artyom Beilis (Tonkikh) +// +// See accompanying file COPYING.TXT file for licensing details. +// +/////////////////////////////////////////////////////////////////////////////// +#ifndef CPPCMS_IMPL_TODEC_H +#define CPPCMS_IMPL_TODEC_H +#include +#include + +namespace cppcms { + namespace impl { + namespace details { + template + struct decimal_traits; + + template<> + struct decimal_traits { + template + static void conv(T v,char *&begin,char *&buf) + { + begin = buf; + while(v!=0) { + *buf++ = '0' + v % 10; + v/=10; + } + } + }; + + template<> + struct decimal_traits { + template + static void conv(T v,char *&begin,char *&buf) + { + if(v<0) { + *buf++ = '-'; + begin=buf; + while(v!=0) { + *buf++ = '0' - (v % 10); + v/=10; + } + } + else { + decimal_traits::conv(v,begin,buf); + } + } + }; + } + + + template + void todec(Integer v,char *buf) + { + typedef std::numeric_limits limits; + if(v == 0) { + *buf++ = '0'; + *buf++ = 0; + return; + } + char *begin=0; + + details::decimal_traits::conv(v,begin,buf); + + *buf-- = 0; + while(begin < buf) { + char tmp = *begin; + *begin = *buf; + *buf = tmp; + buf--; + begin++; + } + } + + template + std::string todec_string(I v) + { + char buf[std::numeric_limits::digits10 + 4]; + todec(v,buf); + std::string tmp = buf; + return tmp; + } + + namespace details { + template + struct write_int_to_stream { + write_int_to_stream(T vi = 0) : v(vi) {} + T v; + void operator()(std::ostream &out) const + { + char buf[std::numeric_limits::digits10 + 4]; + todec(v,buf); + out << buf; + } + }; + template + std::ostream &operator<<(std::ostream &out,write_int_to_stream const &v) + { + v(out); + return out; + } + } // details + + template + details::write_int_to_stream cint(T v) + { + return details::write_int_to_stream(v); + } + } +} +#endif diff --git a/src/base_view.cpp b/src/base_view.cpp index 0dd3e66..c66b559 100644 --- a/src/base_view.cpp +++ b/src/base_view.cpp @@ -11,13 +11,6 @@ #include #include -#include -#ifdef CPPCMS_USE_EXTERNAL_BOOST -# include -#else // Internal Boost -# include - namespace boost = cppcms_boost; -#endif namespace cppcms { diff --git a/src/form.cpp b/src/form.cpp index 075327d..f22b116 100644 --- a/src/form.cpp +++ b/src/form.cpp @@ -14,17 +14,14 @@ #include #include #include -#ifdef CPPCMS_USE_EXTERNAL_BOOST -# include -#else // Internal Boost -# include - namespace boost = cppcms_boost; -#endif - #include +#include "todec.h" + namespace cppcms { +using impl::cint; + struct form_context::_data {}; form_context::form_context() : @@ -421,7 +418,7 @@ void base_widget::generate(int position,form_context * /*context*/) if(is_generation_done_) return; if(name_.empty()) { - name_ = (boost::format("_%1%",std::locale::classic()) % position).str(); + name_ = "_" + impl::todec_string(position); } is_generation_done_ = 1; } @@ -671,10 +668,10 @@ void text::render_attributes(form_context &context) std::ostream &output = context.out(); if(size_ >= 0) - output << boost::format("size=\"%1%\" ",std::locale::classic()) % size_; + output << "size=\"" << cint(size_) <<"\" "; std::pair lm=limits(); if(lm.second >= 0 && validate_charset()) { - output << boost::format("maxlength=\"%1%\" ",std::locale::classic()) % lm.second; + output << "maxlength=\"" << cint(lm.second) << "\" "; } } @@ -728,11 +725,11 @@ void textarea::render_input(form_context &context) render_attributes(context); if(rows_ >= 0) { - output<= 0) { - output< 0) - out << boost::format(" size=\"%1%\" ",std::locale::classic()) % rows_; + out << " size=\"" << cint(rows_) << "\" "; render_attributes(context); } else { @@ -1127,13 +1124,13 @@ void select_base::add(locale::message const &str,std::string const &id) void select_base::add(std::string const &str) { - std::string id=(boost::format("%1%",std::locale::classic()) % elements_.size()).str(); + std::string id= impl::todec_string(elements_.size()); elements_.push_back(element(id,str)); } void select_base::add(locale::message const &str) { - std::string id=(boost::format("%1%",std::locale::classic()) % elements_.size()).str(); + std::string id= impl::todec_string(elements_.size()); elements_.push_back(element(id,str)); } diff --git a/src/forwarder.cpp b/src/forwarder.cpp index c5450f2..73357ae 100644 --- a/src/forwarder.cpp +++ b/src/forwarder.cpp @@ -24,16 +24,15 @@ #include #include +#include "todec.h" #ifdef CPPCMS_USE_EXTERNAL_BOOST # include -# include # if defined(CPPCMS_WIN32) && _WIN32_WINNT <= 0x0501 && !defined(BOOST_ASIO_DISABLE_IOCP) # define NO_CANCELIO # endif #else // Internal Boost # include -# include namespace boost = cppcms_boost; # if defined(CPPCMS_WIN32) && _WIN32_WINNT <= 0x0501 && !defined(CPPCMS_BOOST_ASIO_DISABLE_IOCP) # define NO_CANCELIO @@ -152,7 +151,8 @@ namespace cppcms { env_str.append(p->first.c_str(),p->first.size()+1); env_str.append(p->second.c_str(),p->second.size()+1); } - std::string header=(boost::format("%1%:",std::locale::classic()) % env_str.size()).str(); + std::string header=todec_string(env_str.size()); + header+=':'; header.reserve(header.size()+env_str.size()+addon_size); header+=env_str; header+=',';