1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef CSV_STREAMSTR_HXX
21 #define CSV_STREAMSTR_HXX
23 #include "sal/config.h"
25 #include "sal/types.h"
28 #include <cosv/bstream.hxx>
30 #include <cosv/str_types.hxx>
41 void c_str(); // Dummy needed for StreamStr::operator<<(StreamStr::F_CSTR);
44 /** A string buffer class for all kinds of string manipulation.
46 class StreamStr
: public bostream
49 typedef StreamStr self
;
51 typedef str::size size_type
;
52 typedef str::position position_type
;
53 typedef intt seek_type
;
54 typedef str::insert_mode insert_mode
;
56 typedef const char * const_iterator
;
57 typedef char * iterator
;
59 typedef void (*F_CSTR
)();
62 /** Represents an area within a string.
66 typedef str::size size_type
;
69 const char * i_str
= "",
70 size_type i_nLength
= str::maxsize
)
72 nLength( i_nLength
== str::maxsize
81 size_type i_nCapacity
);
82 /// Copies also insert_mode and current position.
84 const self
& i_rOther
);
88 /// Copies also insert_mode and current position.
90 const self
& i_rOther
);
106 unsigned short i_n
);
121 /** This operator is used to finish a sequence of streaming
122 oeprators by returning the c-string of the complete string.
124 @return The same as ->c_str().
127 csv::StreamStr s(100);
129 fullname = s << qualifier() << "::" << name() << csv::c_str;
131 const char * operator<<(
134 const char & operator[](
135 position_type i_nPosition
) const;
137 position_type i_nPosition
);
141 size_type i_nMinimumCapacity
);
145 /** Sets start point for the next operator<<() call.
146 if the intended position is not reachable, nothing happens.
150 seek_dir i_eDirection
= ::csv::beg
);
151 self
& reset() { return seekp(0); }
152 /** Sets the insertion mode of all and only the operator<<() calls.
154 Default is str::overwrite:
155 str::overwrite: seekp() always sets the cur end of the string.
156 operator<<() calls push the end of the string forward.
157 str::insert: seekp() only sets the insertion point.
158 operator<<() calls insert their text at the tellp()
159 position and keep the rest of the string. tellp() is
160 then after the inserted text, on the beginning of the
163 self
& set_insert_mode(
164 insert_mode i_eMode
);
167 size_type i_nCount
);
169 size_type i_nCount
);
171 /// Works like operator<<(). Does the same as Perl's join().
172 self
& operator_join(
173 std::vector
<String
>::const_iterator
175 std::vector
<String
>::const_iterator
177 const char * i_sLink
);
178 /// Works like operator<<()
179 self
& operator_add_substr(
180 const char * i_sText
,
181 size_type i_nLength
);
182 /// Works like operator<<()
183 self
& operator_add_token(
184 const char * i_sText
,
186 /// Works like operator<<()
187 self
& operator_read_line(
190 void strip_front_whitespace(); /// removes space, tab and crlf.
191 void strip_back_whitespace();
192 void strip_frontback_whitespace();
196 char i_cReplacement
);
199 const char * c_str() const;
200 const char * data() const;
203 size_type
size() const;
204 size_type
length() const;
206 size_type
capacity() const;
208 position_type
tellp() const;
210 const_iterator
begin() const;
211 const_iterator
cur() const;
212 const_iterator
end() const;
220 // Interface bostream
221 virtual UINT32
do_write(
223 UINT32 i_nNrofBytes
);
225 void ProvideAddingSize(
226 size_type i_nSize2Add
);
227 /// Resizes with the factor 2.0 (under 128), 1.5 or until i_nMinimumCapacity, whatever is bigger.
229 size_type i_nMinimumCapacity
= 0 );
231 size_type i_nAddedSize
);
237 size_type nCapacity1
; /// Capacity of characters to contain + 1 for terminating 0.
250 uintt i_nMinimalSize
);
253 StreamStr
& operator()() { return *pStr
; }
262 StreamStr::operator<<( SAL_UNUSED_PARAMETER F_CSTR
)
266 { pEnd
= pCur
= dpData
; *pEnd
= '\0'; }
268 StreamStr::c_str() const
271 StreamStr::data() const
274 StreamStr::empty() const
275 { return dpData
== pEnd
; }
276 inline StreamStr::size_type
277 StreamStr::size() const
278 { return pEnd
- dpData
; }
279 inline StreamStr::size_type
280 StreamStr::length() const
282 inline StreamStr::size_type
283 StreamStr::capacity() const
284 { return nCapacity1
-1; }
285 inline StreamStr::position_type
286 StreamStr::tellp() const
287 { return size_type(pCur
-dpData
); }
288 inline StreamStr::const_iterator
289 StreamStr::begin() const
291 inline StreamStr::const_iterator
292 StreamStr::cur() const
294 inline StreamStr::const_iterator
295 StreamStr::end() const
297 inline StreamStr::iterator
300 inline StreamStr::iterator
303 inline StreamStr::iterator
310 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */