// // Copyright (c) 2012 Artyom Beilis (Tonkikh) // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_NOWIDE_DETAILS_WIDESTR_H_INCLUDED #define BOOST_NOWIDE_DETAILS_WIDESTR_H_INCLUDED #include #include #include namespace boost { namespace nowide { /// /// \brief A class that allows to create a temporary wide or narrow UTF strings from /// wide or narrow UTF source. /// /// It uses on stack buffer of the string is short enough /// and allocated a buffer on the heap if the size of the buffer is too small /// template class basic_stackstring { public: static const size_t buffer_size = BufferSize; typedef CharOut output_char; typedef CharIn input_char; basic_stackstring(basic_stackstring const &other) : mem_buffer_(0) { clear(); if(other.mem_buffer_) { size_t len = 0; while(other.mem_buffer_[len]) len ++; mem_buffer_ = new output_char[len + 1]; memcpy(mem_buffer_,other.mem_buffer_,sizeof(output_char) * (len+1)); } else { memcpy(buffer_,other.buffer_,buffer_size * sizeof(output_char)); } } void swap(basic_stackstring &other) { std::swap(mem_buffer_,other.mem_buffer_); for(size_t i=0;i wstackstring; /// /// Convinience typedef /// typedef basic_stackstring stackstring; /// /// Convinience typedef /// typedef basic_stackstring wshort_stackstring; /// /// Convinience typedef /// typedef basic_stackstring short_stackstring; } // nowide } // namespace boost #endif /// // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4