1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #include <precomp.h> 29*cdf0e10cSrcweir #include <cosv/streamstr.hxx> 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir // NOT FULLY DECLARED SERVICES 32*cdf0e10cSrcweir #include <string.h> 33*cdf0e10cSrcweir #include <stdio.h> 34*cdf0e10cSrcweir #include <stdarg.h> // both are needed to satisfy all compilers 35*cdf0e10cSrcweir #include <cstdarg> // std::va_list and friends 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir #include <cosv/comfunc.hxx> 38*cdf0e10cSrcweir #include <cosv/tpl/swelist.hxx> 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir namespace csv 43*cdf0e10cSrcweir { 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir // Maximal sizes of resulting integers in text form: 47*cdf0e10cSrcweir const uintt C_short_max_size = sizeof(short) * 3; 48*cdf0e10cSrcweir const uintt C_int_max_size = sizeof(int) * 3; 49*cdf0e10cSrcweir const uintt C_long_max_size = sizeof(long) * 3; 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir inline void 53*cdf0e10cSrcweir StreamStr::Advance(size_type i_nAddedSize) 54*cdf0e10cSrcweir { pCur += i_nAddedSize; } 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir StreamStr::StreamStr( size_type i_nCapacity ) 59*cdf0e10cSrcweir : bostream(), 60*cdf0e10cSrcweir nCapacity1( i_nCapacity + 1 ), 61*cdf0e10cSrcweir dpData( new char [i_nCapacity + 1] ), 62*cdf0e10cSrcweir pEnd(dpData), 63*cdf0e10cSrcweir pCur(dpData), 64*cdf0e10cSrcweir eMode(str::overwrite) 65*cdf0e10cSrcweir { 66*cdf0e10cSrcweir *pEnd = '\0'; 67*cdf0e10cSrcweir } 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir StreamStr::StreamStr( const char * i_sInitStr, 70*cdf0e10cSrcweir size_type i_nCapacity ) 71*cdf0e10cSrcweir : bostream(), 72*cdf0e10cSrcweir nCapacity1(0), 73*cdf0e10cSrcweir dpData(0), 74*cdf0e10cSrcweir pEnd(0), 75*cdf0e10cSrcweir pCur(0), 76*cdf0e10cSrcweir eMode(str::overwrite) 77*cdf0e10cSrcweir { 78*cdf0e10cSrcweir size_type nLength = strlen(i_sInitStr); 79*cdf0e10cSrcweir nCapacity1 = csv::max(nLength, i_nCapacity) + 1; 80*cdf0e10cSrcweir dpData = new char [nCapacity1]; 81*cdf0e10cSrcweir strcpy(dpData, i_sInitStr); // SAFE STRCPY (#100211# - checked) 82*cdf0e10cSrcweir pCur = dpData + nLength; 83*cdf0e10cSrcweir pEnd = pCur; 84*cdf0e10cSrcweir } 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir StreamStr::StreamStr( size_type i_nGuessedCapacity, 87*cdf0e10cSrcweir const char * str1, 88*cdf0e10cSrcweir const char * str2, 89*cdf0e10cSrcweir ... ) 90*cdf0e10cSrcweir : bostream(), 91*cdf0e10cSrcweir nCapacity1( i_nGuessedCapacity + 1 ), 92*cdf0e10cSrcweir dpData( new char [i_nGuessedCapacity + 1] ), 93*cdf0e10cSrcweir pEnd(dpData), 94*cdf0e10cSrcweir pCur(dpData), 95*cdf0e10cSrcweir eMode(str::overwrite) 96*cdf0e10cSrcweir { 97*cdf0e10cSrcweir *pEnd = '\0'; 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir operator<<(str1); 100*cdf0e10cSrcweir operator<<(str2); 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir ::va_list ap; 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir va_start(ap, str2); 105*cdf0e10cSrcweir for ( const char * strAdd = va_arg(ap,const char*); 106*cdf0e10cSrcweir strAdd != 0; 107*cdf0e10cSrcweir strAdd = va_arg(ap,const char*) ) 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir size_type nLen = strlen(strAdd); 110*cdf0e10cSrcweir ProvideAddingSize( nLen ); 111*cdf0e10cSrcweir memcpy(pCur, strAdd, nLen); 112*cdf0e10cSrcweir Advance(nLen); 113*cdf0e10cSrcweir } // end for 114*cdf0e10cSrcweir va_end(ap); 115*cdf0e10cSrcweir } 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir StreamStr::StreamStr( const self & i_rOther ) 118*cdf0e10cSrcweir : bostream(), 119*cdf0e10cSrcweir nCapacity1( i_rOther.nCapacity1 ), 120*cdf0e10cSrcweir dpData( new char [i_rOther.nCapacity1] ), 121*cdf0e10cSrcweir pEnd( dpData + strlen(i_rOther.dpData) ), 122*cdf0e10cSrcweir pCur( dpData + i_rOther.tellp() ), 123*cdf0e10cSrcweir eMode(i_rOther.eMode) 124*cdf0e10cSrcweir { 125*cdf0e10cSrcweir strcpy( dpData, i_rOther.dpData ); // SAFE STRCPY (#100211# - checked) 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir StreamStr::StreamStr(csv::bstream & i_source) 129*cdf0e10cSrcweir : bostream(), 130*cdf0e10cSrcweir nCapacity1(0), 131*cdf0e10cSrcweir dpData(0), 132*cdf0e10cSrcweir pEnd(0), 133*cdf0e10cSrcweir pCur(0), 134*cdf0e10cSrcweir eMode(str::overwrite) 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir i_source.seek(0, csv::end); 137*cdf0e10cSrcweir nCapacity1 = static_cast<size_type>(i_source.position()) + 1; 138*cdf0e10cSrcweir i_source.seek(0); 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir dpData = new char[nCapacity1]; 141*cdf0e10cSrcweir i_source.read(dpData, nCapacity1 - 1); 142*cdf0e10cSrcweir pCur = dpData + nCapacity1 - 1; 143*cdf0e10cSrcweir pEnd = pCur; 144*cdf0e10cSrcweir *pCur = '\0'; 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir StreamStr::~StreamStr() 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir delete [] dpData; 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir StreamStr & 154*cdf0e10cSrcweir StreamStr::operator=( const self & i_rOther ) 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir delete [] dpData; 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir nCapacity1 = i_rOther.nCapacity1; 159*cdf0e10cSrcweir dpData = new char [i_rOther.nCapacity1]; 160*cdf0e10cSrcweir pEnd = dpData + strlen(i_rOther.dpData); 161*cdf0e10cSrcweir strcpy( dpData, i_rOther.dpData ); // SAFE STRCPY (#100211# - checked) 162*cdf0e10cSrcweir pCur = dpData + i_rOther.tellp(); 163*cdf0e10cSrcweir eMode = i_rOther.eMode; 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir return *this; 166*cdf0e10cSrcweir } 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir StreamStr & 169*cdf0e10cSrcweir StreamStr::operator<<( const char * i_s ) 170*cdf0e10cSrcweir { 171*cdf0e10cSrcweir size_type nLength = strlen(i_s); 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir ProvideAddingSize( nLength ); 174*cdf0e10cSrcweir memcpy( pCur, i_s, nLength ); 175*cdf0e10cSrcweir Advance(nLength); 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir return *this; 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir StreamStr & 181*cdf0e10cSrcweir StreamStr::operator<<( const String & i_s ) 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir size_type nLength = i_s.length(); 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir ProvideAddingSize( nLength ); 186*cdf0e10cSrcweir memcpy( pCur, i_s.c_str(), nLength ); 187*cdf0e10cSrcweir Advance(nLength); 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir return *this; 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir StreamStr & 193*cdf0e10cSrcweir StreamStr::operator<<( char i_c ) 194*cdf0e10cSrcweir { 195*cdf0e10cSrcweir ProvideAddingSize( 1 ); 196*cdf0e10cSrcweir *pCur = i_c; 197*cdf0e10cSrcweir Advance(1); 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir return *this; 200*cdf0e10cSrcweir } 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir StreamStr & 203*cdf0e10cSrcweir StreamStr::operator<<( unsigned char i_c ) 204*cdf0e10cSrcweir { 205*cdf0e10cSrcweir return operator<<( char(i_c) ); 206*cdf0e10cSrcweir } 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir StreamStr & 209*cdf0e10cSrcweir StreamStr::operator<<( signed char i_c ) 210*cdf0e10cSrcweir { 211*cdf0e10cSrcweir return operator<<( char(i_c) ); 212*cdf0e10cSrcweir } 213*cdf0e10cSrcweir 214*cdf0e10cSrcweir StreamStr & 215*cdf0e10cSrcweir StreamStr::operator<<( short i_n ) 216*cdf0e10cSrcweir { 217*cdf0e10cSrcweir char buf[C_short_max_size] = ""; 218*cdf0e10cSrcweir sprintf( buf, "%hi", i_n ); // SAFE SPRINTF (#100211# - checked) 219*cdf0e10cSrcweir 220*cdf0e10cSrcweir size_type nLength = strlen(buf); 221*cdf0e10cSrcweir ProvideAddingSize( nLength ); 222*cdf0e10cSrcweir memcpy( pCur, buf, nLength ); 223*cdf0e10cSrcweir Advance( nLength ); 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir return *this; 226*cdf0e10cSrcweir } 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir StreamStr & 229*cdf0e10cSrcweir StreamStr::operator<<( unsigned short i_n ) 230*cdf0e10cSrcweir { 231*cdf0e10cSrcweir char buf[C_short_max_size] = ""; 232*cdf0e10cSrcweir sprintf( buf, "%hu", i_n ); // SAFE SPRINTF (#100211# - checked) 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir size_type nLength = strlen(buf); 235*cdf0e10cSrcweir ProvideAddingSize( nLength ); 236*cdf0e10cSrcweir memcpy( pCur, buf, nLength ); 237*cdf0e10cSrcweir Advance( nLength ); 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir return *this; 240*cdf0e10cSrcweir } 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir StreamStr & 243*cdf0e10cSrcweir StreamStr::operator<<( int i_n ) 244*cdf0e10cSrcweir { 245*cdf0e10cSrcweir char buf[C_int_max_size] = ""; 246*cdf0e10cSrcweir sprintf( buf, "%i", i_n ); // SAFE SPRINTF (#100211# - checked) 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir size_type nLength = strlen(buf); 249*cdf0e10cSrcweir ProvideAddingSize( nLength ); 250*cdf0e10cSrcweir memcpy( pCur, buf, nLength ); 251*cdf0e10cSrcweir Advance( nLength ); 252*cdf0e10cSrcweir 253*cdf0e10cSrcweir return *this; 254*cdf0e10cSrcweir } 255*cdf0e10cSrcweir 256*cdf0e10cSrcweir StreamStr & 257*cdf0e10cSrcweir StreamStr::operator<<( unsigned int i_n ) 258*cdf0e10cSrcweir { 259*cdf0e10cSrcweir char buf[C_int_max_size] = ""; 260*cdf0e10cSrcweir sprintf( buf, "%u", i_n ); // SAFE SPRINTF (#100211# - checked) 261*cdf0e10cSrcweir 262*cdf0e10cSrcweir size_type nLength = strlen(buf); 263*cdf0e10cSrcweir ProvideAddingSize( nLength ); 264*cdf0e10cSrcweir memcpy( pCur, buf, nLength ); 265*cdf0e10cSrcweir Advance( nLength ); 266*cdf0e10cSrcweir 267*cdf0e10cSrcweir return *this; 268*cdf0e10cSrcweir } 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir StreamStr & 271*cdf0e10cSrcweir StreamStr::operator<<( long i_n ) 272*cdf0e10cSrcweir { 273*cdf0e10cSrcweir char buf[C_long_max_size] = ""; 274*cdf0e10cSrcweir sprintf( buf, "%li", i_n ); // SAFE SPRINTF (#100211# - checked) 275*cdf0e10cSrcweir 276*cdf0e10cSrcweir size_type nLength = strlen(buf); 277*cdf0e10cSrcweir ProvideAddingSize( nLength ); 278*cdf0e10cSrcweir memcpy( pCur, buf, nLength ); 279*cdf0e10cSrcweir Advance( nLength ); 280*cdf0e10cSrcweir 281*cdf0e10cSrcweir return *this; 282*cdf0e10cSrcweir } 283*cdf0e10cSrcweir 284*cdf0e10cSrcweir StreamStr & 285*cdf0e10cSrcweir StreamStr::operator<<( unsigned long i_n ) 286*cdf0e10cSrcweir { 287*cdf0e10cSrcweir char buf[C_long_max_size] = ""; 288*cdf0e10cSrcweir sprintf( buf, "%lu", i_n ); // SAFE SPRINTF (#100211# - checked) 289*cdf0e10cSrcweir 290*cdf0e10cSrcweir size_type nLength = strlen(buf); 291*cdf0e10cSrcweir ProvideAddingSize( nLength ); 292*cdf0e10cSrcweir memcpy( pCur, buf, nLength ); 293*cdf0e10cSrcweir Advance( nLength ); 294*cdf0e10cSrcweir 295*cdf0e10cSrcweir return *this; 296*cdf0e10cSrcweir } 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir StreamStr & 299*cdf0e10cSrcweir StreamStr::operator<<( float i_n ) 300*cdf0e10cSrcweir { 301*cdf0e10cSrcweir const int C_float_max_size = 20; 302*cdf0e10cSrcweir char buf[C_float_max_size] = ""; 303*cdf0e10cSrcweir sprintf( buf, "%.*g", C_float_max_size-8, i_n ); // SAFE SPRINTF (#100211# - checked) 304*cdf0e10cSrcweir 305*cdf0e10cSrcweir size_type nLength = strlen(buf); 306*cdf0e10cSrcweir ProvideAddingSize( nLength ); 307*cdf0e10cSrcweir memcpy( pCur, buf, nLength ); 308*cdf0e10cSrcweir Advance( nLength ); 309*cdf0e10cSrcweir 310*cdf0e10cSrcweir return *this; 311*cdf0e10cSrcweir } 312*cdf0e10cSrcweir 313*cdf0e10cSrcweir StreamStr & 314*cdf0e10cSrcweir StreamStr::operator<<( double i_n ) 315*cdf0e10cSrcweir { 316*cdf0e10cSrcweir const int C_double_max_size = 30; 317*cdf0e10cSrcweir char buf[C_double_max_size] = ""; 318*cdf0e10cSrcweir sprintf( buf, "%.*lg", C_double_max_size-8, i_n ); // SAFE SPRINTF (#100211# - checked) 319*cdf0e10cSrcweir 320*cdf0e10cSrcweir size_type nLength = strlen(buf); 321*cdf0e10cSrcweir ProvideAddingSize( nLength ); 322*cdf0e10cSrcweir memcpy( pCur, buf, nLength ); 323*cdf0e10cSrcweir Advance( nLength ); 324*cdf0e10cSrcweir 325*cdf0e10cSrcweir return *this; 326*cdf0e10cSrcweir } 327*cdf0e10cSrcweir 328*cdf0e10cSrcweir const char & 329*cdf0e10cSrcweir StreamStr::operator[]( position_type i_nPosition ) const 330*cdf0e10cSrcweir { 331*cdf0e10cSrcweir static const char aNull_ = '\0'; 332*cdf0e10cSrcweir 333*cdf0e10cSrcweir if ( position_type(pEnd - dpData) > i_nPosition ) 334*cdf0e10cSrcweir return dpData[i_nPosition]; 335*cdf0e10cSrcweir return aNull_; 336*cdf0e10cSrcweir } 337*cdf0e10cSrcweir 338*cdf0e10cSrcweir char & 339*cdf0e10cSrcweir StreamStr::operator[]( position_type i_nPosition ) 340*cdf0e10cSrcweir { 341*cdf0e10cSrcweir static char aDummy_ = '\0'; 342*cdf0e10cSrcweir 343*cdf0e10cSrcweir if ( position_type(pEnd - dpData) > i_nPosition ) 344*cdf0e10cSrcweir return dpData[i_nPosition]; 345*cdf0e10cSrcweir return aDummy_; 346*cdf0e10cSrcweir } 347*cdf0e10cSrcweir 348*cdf0e10cSrcweir void 349*cdf0e10cSrcweir StreamStr::resize( size_type i_nMinimumCapacity ) 350*cdf0e10cSrcweir { 351*cdf0e10cSrcweir if ( i_nMinimumCapacity <= capacity() ) 352*cdf0e10cSrcweir return; 353*cdf0e10cSrcweir 354*cdf0e10cSrcweir Resize(i_nMinimumCapacity); 355*cdf0e10cSrcweir } 356*cdf0e10cSrcweir 357*cdf0e10cSrcweir void 358*cdf0e10cSrcweir StreamStr::swap( StreamStr & io_swap ) 359*cdf0e10cSrcweir { 360*cdf0e10cSrcweir size_type 361*cdf0e10cSrcweir n = io_swap.nCapacity1; 362*cdf0e10cSrcweir io_swap.nCapacity1 = nCapacity1; 363*cdf0e10cSrcweir nCapacity1 = n; 364*cdf0e10cSrcweir 365*cdf0e10cSrcweir char * 366*cdf0e10cSrcweir p = io_swap.dpData; 367*cdf0e10cSrcweir io_swap.dpData = dpData; 368*cdf0e10cSrcweir dpData = p; 369*cdf0e10cSrcweir 370*cdf0e10cSrcweir p = io_swap.pEnd; 371*cdf0e10cSrcweir io_swap.pEnd = pEnd; 372*cdf0e10cSrcweir pEnd = p; 373*cdf0e10cSrcweir 374*cdf0e10cSrcweir p = io_swap.pCur; 375*cdf0e10cSrcweir io_swap.pCur = pCur; 376*cdf0e10cSrcweir pCur = p; 377*cdf0e10cSrcweir 378*cdf0e10cSrcweir insert_mode 379*cdf0e10cSrcweir m = io_swap.eMode; 380*cdf0e10cSrcweir io_swap.eMode = eMode; 381*cdf0e10cSrcweir eMode = m; 382*cdf0e10cSrcweir } 383*cdf0e10cSrcweir 384*cdf0e10cSrcweir StreamStr & 385*cdf0e10cSrcweir StreamStr::seekp( seek_type i_nCount, 386*cdf0e10cSrcweir seek_dir i_eDirection ) 387*cdf0e10cSrcweir { 388*cdf0e10cSrcweir seek_type nLength = seek_type( length() ); 389*cdf0e10cSrcweir seek_type nNewPos = tellp(); 390*cdf0e10cSrcweir 391*cdf0e10cSrcweir switch ( i_eDirection ) 392*cdf0e10cSrcweir { 393*cdf0e10cSrcweir case ::csv::beg: nNewPos = i_nCount; 394*cdf0e10cSrcweir break; 395*cdf0e10cSrcweir case ::csv::cur: nNewPos += i_nCount; 396*cdf0e10cSrcweir break; 397*cdf0e10cSrcweir case ::csv::end: nNewPos = nLength + i_nCount; 398*cdf0e10cSrcweir break; 399*cdf0e10cSrcweir } 400*cdf0e10cSrcweir 401*cdf0e10cSrcweir if ( in_range<seek_type>(0, nNewPos, nLength + 1) ) 402*cdf0e10cSrcweir { 403*cdf0e10cSrcweir pCur = dpData + nNewPos; 404*cdf0e10cSrcweir if (eMode == str::overwrite) 405*cdf0e10cSrcweir { 406*cdf0e10cSrcweir pEnd = pCur; 407*cdf0e10cSrcweir *pEnd = '\0'; 408*cdf0e10cSrcweir } 409*cdf0e10cSrcweir } 410*cdf0e10cSrcweir 411*cdf0e10cSrcweir return *this; 412*cdf0e10cSrcweir } 413*cdf0e10cSrcweir 414*cdf0e10cSrcweir StreamStr & 415*cdf0e10cSrcweir StreamStr::set_insert_mode( insert_mode i_eMode ) 416*cdf0e10cSrcweir { 417*cdf0e10cSrcweir eMode = i_eMode; 418*cdf0e10cSrcweir return *this; 419*cdf0e10cSrcweir } 420*cdf0e10cSrcweir 421*cdf0e10cSrcweir void 422*cdf0e10cSrcweir StreamStr::push_front( const char * i_str ) 423*cdf0e10cSrcweir { 424*cdf0e10cSrcweir insert_mode eOriginalMode = eMode; 425*cdf0e10cSrcweir char * pOriginalCur = pCur; 426*cdf0e10cSrcweir eMode = str::insert; 427*cdf0e10cSrcweir pCur = dpData; 428*cdf0e10cSrcweir 429*cdf0e10cSrcweir operator<<(i_str); 430*cdf0e10cSrcweir 431*cdf0e10cSrcweir eMode = eOriginalMode; 432*cdf0e10cSrcweir pCur = pOriginalCur + strlen(i_str); 433*cdf0e10cSrcweir } 434*cdf0e10cSrcweir 435*cdf0e10cSrcweir void 436*cdf0e10cSrcweir StreamStr::push_front( char i_c ) 437*cdf0e10cSrcweir { 438*cdf0e10cSrcweir insert_mode eOriginalMode = eMode; 439*cdf0e10cSrcweir char * pOriginalCur = pCur; 440*cdf0e10cSrcweir eMode = str::insert; 441*cdf0e10cSrcweir pCur = dpData; 442*cdf0e10cSrcweir 443*cdf0e10cSrcweir operator<<(i_c); 444*cdf0e10cSrcweir 445*cdf0e10cSrcweir eMode = eOriginalMode; 446*cdf0e10cSrcweir pCur = pOriginalCur + 1; 447*cdf0e10cSrcweir } 448*cdf0e10cSrcweir 449*cdf0e10cSrcweir void 450*cdf0e10cSrcweir StreamStr::push_back( const char * i_str ) 451*cdf0e10cSrcweir { 452*cdf0e10cSrcweir insert_mode eOriginalMode = eMode; 453*cdf0e10cSrcweir eMode = str::overwrite; 454*cdf0e10cSrcweir 455*cdf0e10cSrcweir operator<<(i_str); 456*cdf0e10cSrcweir 457*cdf0e10cSrcweir eMode = eOriginalMode; 458*cdf0e10cSrcweir } 459*cdf0e10cSrcweir 460*cdf0e10cSrcweir void 461*cdf0e10cSrcweir StreamStr::push_back( char i_c ) 462*cdf0e10cSrcweir { 463*cdf0e10cSrcweir insert_mode eOriginalMode = eMode; 464*cdf0e10cSrcweir eMode = str::overwrite; 465*cdf0e10cSrcweir 466*cdf0e10cSrcweir operator<<(i_c); 467*cdf0e10cSrcweir 468*cdf0e10cSrcweir eMode = eOriginalMode; 469*cdf0e10cSrcweir } 470*cdf0e10cSrcweir 471*cdf0e10cSrcweir void 472*cdf0e10cSrcweir StreamStr::pop_front( size_type i_nCount ) 473*cdf0e10cSrcweir { 474*cdf0e10cSrcweir size_type nCount = min(i_nCount, length()); 475*cdf0e10cSrcweir 476*cdf0e10cSrcweir MoveData( dpData + nCount, pEnd, -(seek_type(nCount)) ); 477*cdf0e10cSrcweir 478*cdf0e10cSrcweir pCur -= nCount; 479*cdf0e10cSrcweir pEnd -= nCount; 480*cdf0e10cSrcweir *pEnd = '\0'; 481*cdf0e10cSrcweir } 482*cdf0e10cSrcweir 483*cdf0e10cSrcweir void 484*cdf0e10cSrcweir StreamStr::pop_back( size_type i_nCount ) 485*cdf0e10cSrcweir { 486*cdf0e10cSrcweir size_type nCount = min(i_nCount, length()); 487*cdf0e10cSrcweir pEnd -= nCount; 488*cdf0e10cSrcweir if (pCur > pEnd) 489*cdf0e10cSrcweir pCur = pEnd; 490*cdf0e10cSrcweir *pEnd = '\0'; 491*cdf0e10cSrcweir } 492*cdf0e10cSrcweir 493*cdf0e10cSrcweir StreamStr & 494*cdf0e10cSrcweir StreamStr::operator_join( std::vector<String>::const_iterator i_rBegin, 495*cdf0e10cSrcweir std::vector<String>::const_iterator i_rEnd, 496*cdf0e10cSrcweir const char * i_sLink ) 497*cdf0e10cSrcweir { 498*cdf0e10cSrcweir std::vector<String>::const_iterator it = i_rBegin; 499*cdf0e10cSrcweir if ( it != i_rEnd ) 500*cdf0e10cSrcweir { 501*cdf0e10cSrcweir operator<<(*it); 502*cdf0e10cSrcweir for ( ++it; it != i_rEnd; ++it ) 503*cdf0e10cSrcweir { 504*cdf0e10cSrcweir operator<<(i_sLink); 505*cdf0e10cSrcweir operator<<(*it); 506*cdf0e10cSrcweir } 507*cdf0e10cSrcweir } 508*cdf0e10cSrcweir return *this; 509*cdf0e10cSrcweir } 510*cdf0e10cSrcweir 511*cdf0e10cSrcweir StreamStr & 512*cdf0e10cSrcweir StreamStr::operator_add_substr( const char * i_sText, 513*cdf0e10cSrcweir size_type i_nLength ) 514*cdf0e10cSrcweir { 515*cdf0e10cSrcweir size_type nLength = csv::min<size_type>(i_nLength, strlen(i_sText)); 516*cdf0e10cSrcweir 517*cdf0e10cSrcweir ProvideAddingSize( nLength ); 518*cdf0e10cSrcweir memcpy( pCur, i_sText, nLength ); 519*cdf0e10cSrcweir Advance(nLength); 520*cdf0e10cSrcweir 521*cdf0e10cSrcweir return *this; 522*cdf0e10cSrcweir } 523*cdf0e10cSrcweir 524*cdf0e10cSrcweir StreamStr & 525*cdf0e10cSrcweir StreamStr::operator_add_token( const char * i_sText, 526*cdf0e10cSrcweir char i_cDelimiter ) 527*cdf0e10cSrcweir { 528*cdf0e10cSrcweir const char * pTokenEnd = strchr(i_sText, i_cDelimiter); 529*cdf0e10cSrcweir if (pTokenEnd == 0) 530*cdf0e10cSrcweir operator<<(i_sText); 531*cdf0e10cSrcweir else 532*cdf0e10cSrcweir operator_add_substr(i_sText, pTokenEnd-i_sText); 533*cdf0e10cSrcweir return *this; 534*cdf0e10cSrcweir } 535*cdf0e10cSrcweir 536*cdf0e10cSrcweir StreamStr & 537*cdf0e10cSrcweir StreamStr::operator_read_line( bstream & i_src ) 538*cdf0e10cSrcweir { 539*cdf0e10cSrcweir char c = 0; 540*cdf0e10cSrcweir intt nCount = 0; 541*cdf0e10cSrcweir for ( nCount = i_src.read(&c, 1); 542*cdf0e10cSrcweir nCount == 1 AND c != 13 AND c != 10; 543*cdf0e10cSrcweir nCount = i_src.read(&c, 1) ) 544*cdf0e10cSrcweir { 545*cdf0e10cSrcweir operator<<(c); 546*cdf0e10cSrcweir } 547*cdf0e10cSrcweir 548*cdf0e10cSrcweir bool bEndOfStream = nCount == 0; 549*cdf0e10cSrcweir // Check for line-end: 550*cdf0e10cSrcweir if ( NOT bEndOfStream AND c != 0 ) 551*cdf0e10cSrcweir { 552*cdf0e10cSrcweir char oldc = c; 553*cdf0e10cSrcweir if (i_src.read(&c, 1) == 1) 554*cdf0e10cSrcweir { 555*cdf0e10cSrcweir if ( (c != 13 AND c != 10) OR c == oldc) 556*cdf0e10cSrcweir i_src.seek(-1,::csv::cur); 557*cdf0e10cSrcweir } 558*cdf0e10cSrcweir } 559*cdf0e10cSrcweir return *this; 560*cdf0e10cSrcweir } 561*cdf0e10cSrcweir 562*cdf0e10cSrcweir void 563*cdf0e10cSrcweir StreamStr::strip_front(char i_cToRemove) 564*cdf0e10cSrcweir { 565*cdf0e10cSrcweir const_iterator it = begin(); 566*cdf0e10cSrcweir for ( ; 567*cdf0e10cSrcweir it != end() ? *it == i_cToRemove : false; 568*cdf0e10cSrcweir ++it ) ; 569*cdf0e10cSrcweir pop_front(it - begin()); 570*cdf0e10cSrcweir } 571*cdf0e10cSrcweir 572*cdf0e10cSrcweir void 573*cdf0e10cSrcweir StreamStr::strip_back(char i_cToRemove) 574*cdf0e10cSrcweir { 575*cdf0e10cSrcweir const_iterator it = end(); 576*cdf0e10cSrcweir for ( ; 577*cdf0e10cSrcweir it != begin() ? *(it-1) == i_cToRemove : false; 578*cdf0e10cSrcweir --it ) ; 579*cdf0e10cSrcweir pop_back(end() - it); 580*cdf0e10cSrcweir } 581*cdf0e10cSrcweir 582*cdf0e10cSrcweir void 583*cdf0e10cSrcweir StreamStr::strip_frontback(char i_cToRemove) 584*cdf0e10cSrcweir { 585*cdf0e10cSrcweir strip_front(i_cToRemove); 586*cdf0e10cSrcweir strip_back(i_cToRemove); 587*cdf0e10cSrcweir } 588*cdf0e10cSrcweir 589*cdf0e10cSrcweir void 590*cdf0e10cSrcweir StreamStr::strip_front_whitespace() 591*cdf0e10cSrcweir { 592*cdf0e10cSrcweir const_iterator it = begin(); 593*cdf0e10cSrcweir for ( ; 594*cdf0e10cSrcweir it != end() ? *it < 33 : false; 595*cdf0e10cSrcweir ++it ) ; 596*cdf0e10cSrcweir pop_front(it - begin()); 597*cdf0e10cSrcweir } 598*cdf0e10cSrcweir 599*cdf0e10cSrcweir void 600*cdf0e10cSrcweir StreamStr::strip_back_whitespace() 601*cdf0e10cSrcweir { 602*cdf0e10cSrcweir const_iterator it = end(); 603*cdf0e10cSrcweir for ( ; 604*cdf0e10cSrcweir it != begin() ? *(it-1) < 33 : false; 605*cdf0e10cSrcweir --it ) ; 606*cdf0e10cSrcweir pop_back(end() - it); 607*cdf0e10cSrcweir } 608*cdf0e10cSrcweir 609*cdf0e10cSrcweir void 610*cdf0e10cSrcweir StreamStr::strip_frontback_whitespace() 611*cdf0e10cSrcweir { 612*cdf0e10cSrcweir strip_front_whitespace(); 613*cdf0e10cSrcweir strip_back_whitespace(); 614*cdf0e10cSrcweir } 615*cdf0e10cSrcweir 616*cdf0e10cSrcweir void 617*cdf0e10cSrcweir StreamStr::remove( iterator i_begin, 618*cdf0e10cSrcweir iterator i_end ) 619*cdf0e10cSrcweir { 620*cdf0e10cSrcweir csv_assert(i_begin >= dpData AND i_begin <= pEnd); 621*cdf0e10cSrcweir csv_assert(i_end >= dpData AND i_end <= pEnd); 622*cdf0e10cSrcweir csv_assert(i_end >= i_begin); 623*cdf0e10cSrcweir MoveData(i_end, pEnd, i_begin - i_end); 624*cdf0e10cSrcweir pCur = pEnd; 625*cdf0e10cSrcweir } 626*cdf0e10cSrcweir 627*cdf0e10cSrcweir void 628*cdf0e10cSrcweir StreamStr::replace( position_type i_nStart, 629*cdf0e10cSrcweir size_type i_nSize, 630*cdf0e10cSrcweir Area i_aReplacement ) 631*cdf0e10cSrcweir { 632*cdf0e10cSrcweir if (i_nStart >= length() OR i_nSize < 1) 633*cdf0e10cSrcweir return; 634*cdf0e10cSrcweir 635*cdf0e10cSrcweir insert_mode eOldMode = eMode; 636*cdf0e10cSrcweir eMode = str::insert; 637*cdf0e10cSrcweir pCur = dpData + i_nStart; 638*cdf0e10cSrcweir 639*cdf0e10cSrcweir size_type anz = min( length() - i_nStart, i_nSize ); 640*cdf0e10cSrcweir 641*cdf0e10cSrcweir if ( anz < i_aReplacement.nLength ) 642*cdf0e10cSrcweir { 643*cdf0e10cSrcweir ProvideAddingSize( i_aReplacement.nLength - anz ); 644*cdf0e10cSrcweir } 645*cdf0e10cSrcweir else if ( anz > i_aReplacement.nLength ) 646*cdf0e10cSrcweir { 647*cdf0e10cSrcweir seek_type nMove = seek_type(anz - i_aReplacement.nLength); 648*cdf0e10cSrcweir 649*cdf0e10cSrcweir MoveData( dpData + i_nStart + anz, 650*cdf0e10cSrcweir pEnd, 651*cdf0e10cSrcweir -nMove ); 652*cdf0e10cSrcweir pEnd -= nMove; 653*cdf0e10cSrcweir *pEnd = '\0'; 654*cdf0e10cSrcweir } 655*cdf0e10cSrcweir 656*cdf0e10cSrcweir if (i_aReplacement.nLength > 0) 657*cdf0e10cSrcweir { 658*cdf0e10cSrcweir memcpy( dpData + i_nStart, i_aReplacement.sStr, i_aReplacement.nLength ); 659*cdf0e10cSrcweir Advance(i_aReplacement.nLength); 660*cdf0e10cSrcweir } 661*cdf0e10cSrcweir 662*cdf0e10cSrcweir eMode = eOldMode; 663*cdf0e10cSrcweir pCur = pEnd; 664*cdf0e10cSrcweir } 665*cdf0e10cSrcweir 666*cdf0e10cSrcweir void 667*cdf0e10cSrcweir StreamStr::replace_all( char i_cCarToSearch, 668*cdf0e10cSrcweir char i_cReplacement ) 669*cdf0e10cSrcweir { 670*cdf0e10cSrcweir for ( char * p = dpData; p != pEnd; ++p ) 671*cdf0e10cSrcweir { 672*cdf0e10cSrcweir if (*p == i_cCarToSearch) 673*cdf0e10cSrcweir *p = i_cReplacement; 674*cdf0e10cSrcweir } 675*cdf0e10cSrcweir } 676*cdf0e10cSrcweir 677*cdf0e10cSrcweir void 678*cdf0e10cSrcweir StreamStr::replace_all( Area i_aStrToSearch, 679*cdf0e10cSrcweir Area i_aReplacement ) 680*cdf0e10cSrcweir { 681*cdf0e10cSrcweir position_type p = 0; 682*cdf0e10cSrcweir const char * pSearch = i_aStrToSearch.sStr; 683*cdf0e10cSrcweir size_type nSearch = i_aStrToSearch.nLength; 684*cdf0e10cSrcweir 685*cdf0e10cSrcweir while ( p <= length() - nSearch ) 686*cdf0e10cSrcweir { 687*cdf0e10cSrcweir if ( strncmp(dpData+p, pSearch, nSearch) == 0 ) 688*cdf0e10cSrcweir { 689*cdf0e10cSrcweir replace( p, nSearch, i_aReplacement ); 690*cdf0e10cSrcweir p += i_aReplacement.nLength; 691*cdf0e10cSrcweir } 692*cdf0e10cSrcweir else 693*cdf0e10cSrcweir { 694*cdf0e10cSrcweir ++p; 695*cdf0e10cSrcweir } 696*cdf0e10cSrcweir } // end while 697*cdf0e10cSrcweir } 698*cdf0e10cSrcweir 699*cdf0e10cSrcweir StreamStr & 700*cdf0e10cSrcweir StreamStr::to_lower( position_type i_nStart, 701*cdf0e10cSrcweir size_type i_nLength ) 702*cdf0e10cSrcweir { 703*cdf0e10cSrcweir static char cLower[128] = 704*cdf0e10cSrcweir { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 705*cdf0e10cSrcweir 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 706*cdf0e10cSrcweir 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 707*cdf0e10cSrcweir 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 708*cdf0e10cSrcweir 64, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111, 709*cdf0e10cSrcweir 112,113,114,115,116,117,118,119,120,121,122, 91, 92, 93, 94, 95, 710*cdf0e10cSrcweir 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111, 711*cdf0e10cSrcweir 112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127 }; 712*cdf0e10cSrcweir 713*cdf0e10cSrcweir if ( i_nStart < length() ) 714*cdf0e10cSrcweir { 715*cdf0e10cSrcweir char * pStop = i_nStart + i_nLength < length() 716*cdf0e10cSrcweir ? dpData + i_nStart + i_nLength 717*cdf0e10cSrcweir : pEnd; 718*cdf0e10cSrcweir for ( char * pChange = dpData + i_nStart; 719*cdf0e10cSrcweir pChange != pStop; 720*cdf0e10cSrcweir ++pChange ) 721*cdf0e10cSrcweir { 722*cdf0e10cSrcweir *pChange = (static_cast< unsigned char >(*pChange) & 0x80) == 0 723*cdf0e10cSrcweir ? cLower[ UINT8(*pChange) ] 724*cdf0e10cSrcweir : *pChange; 725*cdf0e10cSrcweir } 726*cdf0e10cSrcweir } 727*cdf0e10cSrcweir return *this; 728*cdf0e10cSrcweir } 729*cdf0e10cSrcweir 730*cdf0e10cSrcweir StreamStr & 731*cdf0e10cSrcweir StreamStr::to_upper( position_type i_nStart, 732*cdf0e10cSrcweir size_type i_nLength ) 733*cdf0e10cSrcweir { 734*cdf0e10cSrcweir static char cUpper[128] = 735*cdf0e10cSrcweir { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 736*cdf0e10cSrcweir 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 737*cdf0e10cSrcweir 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 738*cdf0e10cSrcweir 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 739*cdf0e10cSrcweir 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 740*cdf0e10cSrcweir 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 741*cdf0e10cSrcweir 96, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 742*cdf0e10cSrcweir 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 123,124,125,126,127 }; 743*cdf0e10cSrcweir 744*cdf0e10cSrcweir if ( i_nStart < length() ) 745*cdf0e10cSrcweir { 746*cdf0e10cSrcweir char * pStop = i_nStart + i_nLength < length() 747*cdf0e10cSrcweir ? dpData + i_nStart + i_nLength 748*cdf0e10cSrcweir : pEnd; 749*cdf0e10cSrcweir for ( char * pChange = dpData + i_nStart; 750*cdf0e10cSrcweir pChange != pStop; 751*cdf0e10cSrcweir ++pChange ) 752*cdf0e10cSrcweir { 753*cdf0e10cSrcweir *pChange = (static_cast< unsigned char >(*pChange) & 0x80) == 0 754*cdf0e10cSrcweir ? cUpper[ UINT8(*pChange) ] 755*cdf0e10cSrcweir : *pChange; 756*cdf0e10cSrcweir } 757*cdf0e10cSrcweir } 758*cdf0e10cSrcweir return *this; 759*cdf0e10cSrcweir } 760*cdf0e10cSrcweir 761*cdf0e10cSrcweir 762*cdf0e10cSrcweir StreamStr::size_type 763*cdf0e10cSrcweir StreamStr::token_count( char i_cSplit ) const 764*cdf0e10cSrcweir { 765*cdf0e10cSrcweir return count_chars(dpData, i_cSplit) + 1; 766*cdf0e10cSrcweir } 767*cdf0e10cSrcweir 768*cdf0e10cSrcweir String 769*cdf0e10cSrcweir StreamStr::token( position_type i_nNr, 770*cdf0e10cSrcweir char i_cSplit ) const 771*cdf0e10cSrcweir { 772*cdf0e10cSrcweir // Find begin: 773*cdf0e10cSrcweir const char * pTokenBegin = dpData; 774*cdf0e10cSrcweir for ( position_type nNr = i_nNr; 775*cdf0e10cSrcweir nNr > 0; 776*cdf0e10cSrcweir --nNr ) 777*cdf0e10cSrcweir { 778*cdf0e10cSrcweir pTokenBegin = strchr(pTokenBegin,i_cSplit); 779*cdf0e10cSrcweir if (pTokenBegin == 0) 780*cdf0e10cSrcweir return String(""); 781*cdf0e10cSrcweir ++pTokenBegin; 782*cdf0e10cSrcweir } 783*cdf0e10cSrcweir 784*cdf0e10cSrcweir // Find end: 785*cdf0e10cSrcweir const char * pTokenEnd = strchr(pTokenBegin, i_cSplit); 786*cdf0e10cSrcweir if (pTokenEnd == 0) 787*cdf0e10cSrcweir pTokenEnd = pEnd; 788*cdf0e10cSrcweir 789*cdf0e10cSrcweir return String(pTokenBegin, size_type(pTokenEnd-pTokenBegin) ); 790*cdf0e10cSrcweir } 791*cdf0e10cSrcweir 792*cdf0e10cSrcweir class StreamStrPool 793*cdf0e10cSrcweir { 794*cdf0e10cSrcweir public: 795*cdf0e10cSrcweir StreamStrPool(); 796*cdf0e10cSrcweir ~StreamStrPool(); 797*cdf0e10cSrcweir private: 798*cdf0e10cSrcweir // Non-copyable 799*cdf0e10cSrcweir StreamStrPool(StreamStrPool &); // not defined 800*cdf0e10cSrcweir void operator =(StreamStrPool &); // not defined 801*cdf0e10cSrcweir 802*cdf0e10cSrcweir // Interface to: 803*cdf0e10cSrcweir friend class StreamStrLock; 804*cdf0e10cSrcweir static StreamStr & AcquireFromPool_( 805*cdf0e10cSrcweir uintt i_nMinimalSize ); 806*cdf0e10cSrcweir static void ReleaseToPool_( 807*cdf0e10cSrcweir DYN StreamStr * let_dpUsedStr ); 808*cdf0e10cSrcweir 809*cdf0e10cSrcweir // DATA 810*cdf0e10cSrcweir SweList< DYN StreamStr* > 811*cdf0e10cSrcweir aPool; 812*cdf0e10cSrcweir }; 813*cdf0e10cSrcweir 814*cdf0e10cSrcweir StreamStrPool::StreamStrPool() 815*cdf0e10cSrcweir { 816*cdf0e10cSrcweir } 817*cdf0e10cSrcweir 818*cdf0e10cSrcweir StreamStrPool::~StreamStrPool() 819*cdf0e10cSrcweir { 820*cdf0e10cSrcweir for ( SweList< DYN StreamStr* >::iterator it = aPool.begin(); 821*cdf0e10cSrcweir it != aPool.end(); 822*cdf0e10cSrcweir ++it ) 823*cdf0e10cSrcweir { 824*cdf0e10cSrcweir delete (*it); 825*cdf0e10cSrcweir } 826*cdf0e10cSrcweir } 827*cdf0e10cSrcweir 828*cdf0e10cSrcweir namespace 829*cdf0e10cSrcweir { 830*cdf0e10cSrcweir static StreamStrPool aPool_; 831*cdf0e10cSrcweir } 832*cdf0e10cSrcweir 833*cdf0e10cSrcweir 834*cdf0e10cSrcweir StreamStr & 835*cdf0e10cSrcweir StreamStrPool::AcquireFromPool_( uintt i_nMinimalSize ) 836*cdf0e10cSrcweir { 837*cdf0e10cSrcweir if ( aPool_.aPool.empty() ) 838*cdf0e10cSrcweir { 839*cdf0e10cSrcweir return *new StreamStr(i_nMinimalSize); 840*cdf0e10cSrcweir } 841*cdf0e10cSrcweir 842*cdf0e10cSrcweir StreamStr & ret = *aPool_.aPool.front(); 843*cdf0e10cSrcweir aPool_.aPool.pop_front(); 844*cdf0e10cSrcweir ret.resize(i_nMinimalSize); 845*cdf0e10cSrcweir ret.seekp(0); 846*cdf0e10cSrcweir ret.set_insert_mode(str::overwrite); 847*cdf0e10cSrcweir return ret; 848*cdf0e10cSrcweir } 849*cdf0e10cSrcweir 850*cdf0e10cSrcweir void 851*cdf0e10cSrcweir StreamStrPool::ReleaseToPool_( DYN StreamStr * let_dpUsedStr ) 852*cdf0e10cSrcweir { 853*cdf0e10cSrcweir aPool_.aPool.push_back( let_dpUsedStr ); 854*cdf0e10cSrcweir } 855*cdf0e10cSrcweir 856*cdf0e10cSrcweir StreamStrLock::StreamStrLock( uintt i_nMinimalSize ) 857*cdf0e10cSrcweir : pStr( &StreamStrPool::AcquireFromPool_(i_nMinimalSize) ) 858*cdf0e10cSrcweir { 859*cdf0e10cSrcweir } 860*cdf0e10cSrcweir 861*cdf0e10cSrcweir StreamStrLock::~StreamStrLock() 862*cdf0e10cSrcweir { 863*cdf0e10cSrcweir StreamStrPool::ReleaseToPool_(pStr); 864*cdf0e10cSrcweir } 865*cdf0e10cSrcweir 866*cdf0e10cSrcweir 867*cdf0e10cSrcweir UINT32 868*cdf0e10cSrcweir StreamStr::do_write( const void * i_pSrc, 869*cdf0e10cSrcweir UINT32 i_nNrofBytes ) 870*cdf0e10cSrcweir { 871*cdf0e10cSrcweir ProvideAddingSize( i_nNrofBytes ); 872*cdf0e10cSrcweir memcpy( pCur, i_pSrc, i_nNrofBytes ); 873*cdf0e10cSrcweir Advance(i_nNrofBytes); 874*cdf0e10cSrcweir 875*cdf0e10cSrcweir return i_nNrofBytes; 876*cdf0e10cSrcweir } 877*cdf0e10cSrcweir 878*cdf0e10cSrcweir void 879*cdf0e10cSrcweir StreamStr::ProvideAddingSize( size_type i_nSize2Add ) 880*cdf0e10cSrcweir { 881*cdf0e10cSrcweir size_type nLength = length(); 882*cdf0e10cSrcweir if ( capacity() - nLength < i_nSize2Add ) 883*cdf0e10cSrcweir Resize( nLength + i_nSize2Add ); 884*cdf0e10cSrcweir 885*cdf0e10cSrcweir pEnd += i_nSize2Add; 886*cdf0e10cSrcweir *pEnd = '\0'; 887*cdf0e10cSrcweir 888*cdf0e10cSrcweir if (eMode == str::insert AND pCur != pEnd) 889*cdf0e10cSrcweir { 890*cdf0e10cSrcweir MoveData( pCur, pCur + i_nSize2Add, seek_type(i_nSize2Add) ); 891*cdf0e10cSrcweir } 892*cdf0e10cSrcweir } 893*cdf0e10cSrcweir 894*cdf0e10cSrcweir void 895*cdf0e10cSrcweir StreamStr::Resize( size_type i_nMinimumCapacity ) 896*cdf0e10cSrcweir { 897*cdf0e10cSrcweir size_type nNewSize = nCapacity1 < 128 898*cdf0e10cSrcweir ? nCapacity1 << 1 899*cdf0e10cSrcweir : (nCapacity1 << 1) - (nCapacity1 >> 1); 900*cdf0e10cSrcweir nCapacity1 = csv::max( nNewSize, size_type(i_nMinimumCapacity + 1) ); 901*cdf0e10cSrcweir 902*cdf0e10cSrcweir char * pNew = new char[nCapacity1]; 903*cdf0e10cSrcweir strcpy ( pNew, dpData ); // SAFE STRCPY (#100211# - checked) 904*cdf0e10cSrcweir pEnd = pNew + (pEnd - dpData); 905*cdf0e10cSrcweir pCur = pNew + (pCur - dpData); 906*cdf0e10cSrcweir 907*cdf0e10cSrcweir delete [] dpData; 908*cdf0e10cSrcweir dpData = pNew; 909*cdf0e10cSrcweir } 910*cdf0e10cSrcweir 911*cdf0e10cSrcweir void 912*cdf0e10cSrcweir StreamStr::MoveData( char * i_pStart, 913*cdf0e10cSrcweir char * i_pEnd, 914*cdf0e10cSrcweir seek_type i_nDiff ) 915*cdf0e10cSrcweir { 916*cdf0e10cSrcweir if (i_nDiff > 0) 917*cdf0e10cSrcweir { 918*cdf0e10cSrcweir register const char * pSrc = i_pEnd; 919*cdf0e10cSrcweir register char * pDest = i_pEnd + i_nDiff; 920*cdf0e10cSrcweir for ( ; pSrc != i_pStart; --pSrc, --pDest ) 921*cdf0e10cSrcweir { 922*cdf0e10cSrcweir *pDest = *pSrc; 923*cdf0e10cSrcweir } 924*cdf0e10cSrcweir *pDest = *pSrc; 925*cdf0e10cSrcweir } 926*cdf0e10cSrcweir else if (i_nDiff < 0) 927*cdf0e10cSrcweir { 928*cdf0e10cSrcweir const char * pSrc = i_pStart; 929*cdf0e10cSrcweir char * pDest = i_pStart + i_nDiff; 930*cdf0e10cSrcweir for ( ; pSrc != i_pEnd; ++pSrc, ++pDest ) 931*cdf0e10cSrcweir { 932*cdf0e10cSrcweir *pDest = *pSrc; 933*cdf0e10cSrcweir } 934*cdf0e10cSrcweir } 935*cdf0e10cSrcweir } 936*cdf0e10cSrcweir 937*cdf0e10cSrcweir // Does nothing, only the name of this function is needed. 938*cdf0e10cSrcweir void 939*cdf0e10cSrcweir c_str() 940*cdf0e10cSrcweir { 941*cdf0e10cSrcweir // Does nothing. 942*cdf0e10cSrcweir } 943*cdf0e10cSrcweir 944*cdf0e10cSrcweir 945*cdf0e10cSrcweir 946*cdf0e10cSrcweir void 947*cdf0e10cSrcweir Split( std::vector<String> & o_list, 948*cdf0e10cSrcweir const char * i_text ) 949*cdf0e10cSrcweir { 950*cdf0e10cSrcweir const char * 951*cdf0e10cSrcweir pCurrentToken = 0; 952*cdf0e10cSrcweir bool 953*cdf0e10cSrcweir white = false; 954*cdf0e10cSrcweir for (const char * p = i_text; *p != '\0'; ++p) 955*cdf0e10cSrcweir { 956*cdf0e10cSrcweir white = UINT8(*p) > 32; 957*cdf0e10cSrcweir if (pCurrentToken != 0) 958*cdf0e10cSrcweir { 959*cdf0e10cSrcweir if (white) 960*cdf0e10cSrcweir { 961*cdf0e10cSrcweir o_list.push_back(String(pCurrentToken, p)); 962*cdf0e10cSrcweir pCurrentToken = 0; 963*cdf0e10cSrcweir } 964*cdf0e10cSrcweir } 965*cdf0e10cSrcweir else 966*cdf0e10cSrcweir { 967*cdf0e10cSrcweir if ( NOT white) 968*cdf0e10cSrcweir pCurrentToken = p; 969*cdf0e10cSrcweir } // endif (bInToken) else 970*cdf0e10cSrcweir } // end for 971*cdf0e10cSrcweir 972*cdf0e10cSrcweir if (pCurrentToken != 0) 973*cdf0e10cSrcweir { 974*cdf0e10cSrcweir o_list.push_back(String(pCurrentToken)); 975*cdf0e10cSrcweir } 976*cdf0e10cSrcweir } 977*cdf0e10cSrcweir 978*cdf0e10cSrcweir 979*cdf0e10cSrcweir 980*cdf0e10cSrcweir 981*cdf0e10cSrcweir } // namespace csv 982