51
51
using internal::ztd::c_str;
53
////////// String building /////////////////////////////////////////////////////
53
////////// String appending ///////////////////////////////////////////////////
56
* A %string_appender is used to optimize repeatedly appending characters to a
57
* string in a loop by gathering \em N characters and appending them in chunks
58
* so as to call the string's \c append() function less.
60
template<class StringType,int BufCapacity>
61
class string_appender {
63
typedef StringType value_type;
64
typedef typename value_type::value_type char_type;
65
typedef typename value_type::size_type size_type;
68
* Constructs an appender.
70
* @param s A pointer to the string to append to.
72
string_appender( value_type *s ) : s_( s ), buf_size_( 0 ) { }
75
* Destroys the appender and appends any unappended characters to the string.
82
* Appends a character.
84
* @param c The character to append.
85
* @return Returns \c *this.
87
string_appender& append( char_type c ) {
88
buf_[ buf_size_++ ] = c;
89
if ( buf_size_ == BufCapacity )
95
* Appends any unappended characters to the string.
98
s_->append( buf_, buf_size_ );
103
* Gets the string that is being appended to.
105
* @return Returns said string.
107
value_type& str() const {
112
* Appends a character.
114
* @param c The character to append.
115
* @return Returns \c *this.
117
string_appender& operator+=( char_type c ) {
122
char_type buf_[ BufCapacity ];
127
////////// String building ////////////////////////////////////////////////////
56
130
* A %string_builder is used to build (concatenate) strings on-the-fly and pass