1*89b56da7SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*89b56da7SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*89b56da7SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*89b56da7SAndrew Rist * distributed with this work for additional information 6*89b56da7SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*89b56da7SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*89b56da7SAndrew Rist * "License"); you may not use this file except in compliance 9*89b56da7SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*89b56da7SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*89b56da7SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*89b56da7SAndrew Rist * software distributed under the License is distributed on an 15*89b56da7SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*89b56da7SAndrew Rist * KIND, either express or implied. See the License for the 17*89b56da7SAndrew Rist * specific language governing permissions and limitations 18*89b56da7SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*89b56da7SAndrew Rist *************************************************************/ 21*89b56da7SAndrew Rist 22*89b56da7SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // no include "precompiled_tools.hxx" because this is included in other cxx files. 25cdf0e10cSrcweir 26cdf0e10cSrcweir // ======================================================================= 27cdf0e10cSrcweir 28cdf0e10cSrcweir static sal_Int32 ImplStringCompare( const STRCODE* pStr1, const STRCODE* pStr2 ) 29cdf0e10cSrcweir { 30cdf0e10cSrcweir sal_Int32 nRet; 31cdf0e10cSrcweir while ( ((nRet = ((sal_Int32)((STRCODEU)*pStr1))-((sal_Int32)((STRCODEU)*pStr2))) == 0) && 32cdf0e10cSrcweir *pStr2 ) 33cdf0e10cSrcweir { 34cdf0e10cSrcweir ++pStr1, 35cdf0e10cSrcweir ++pStr2; 36cdf0e10cSrcweir } 37cdf0e10cSrcweir 38cdf0e10cSrcweir return nRet; 39cdf0e10cSrcweir } 40cdf0e10cSrcweir 41cdf0e10cSrcweir // ----------------------------------------------------------------------- 42cdf0e10cSrcweir 43cdf0e10cSrcweir static sal_Int32 ImplStringCompare( const STRCODE* pStr1, const STRCODE* pStr2, 44cdf0e10cSrcweir xub_StrLen nCount ) 45cdf0e10cSrcweir { 46cdf0e10cSrcweir sal_Int32 nRet = 0; 47cdf0e10cSrcweir while ( nCount && 48cdf0e10cSrcweir ((nRet = ((sal_Int32)((STRCODEU)*pStr1))-((sal_Int32)((STRCODEU)*pStr2))) == 0) && 49cdf0e10cSrcweir *pStr2 ) 50cdf0e10cSrcweir { 51cdf0e10cSrcweir ++pStr1, 52cdf0e10cSrcweir ++pStr2, 53cdf0e10cSrcweir --nCount; 54cdf0e10cSrcweir } 55cdf0e10cSrcweir 56cdf0e10cSrcweir return nRet; 57cdf0e10cSrcweir } 58cdf0e10cSrcweir 59cdf0e10cSrcweir // ----------------------------------------------------------------------- 60cdf0e10cSrcweir 61cdf0e10cSrcweir static sal_Int32 ImplStringCompareWithoutZero( const STRCODE* pStr1, const STRCODE* pStr2, 62cdf0e10cSrcweir sal_Int32 nCount ) 63cdf0e10cSrcweir { 64cdf0e10cSrcweir sal_Int32 nRet = 0; 65cdf0e10cSrcweir while ( nCount && 66cdf0e10cSrcweir ((nRet = ((sal_Int32)((STRCODEU)*pStr1))-((sal_Int32)((STRCODEU)*pStr2))) == 0) ) 67cdf0e10cSrcweir { 68cdf0e10cSrcweir ++pStr1, 69cdf0e10cSrcweir ++pStr2, 70cdf0e10cSrcweir --nCount; 71cdf0e10cSrcweir } 72cdf0e10cSrcweir 73cdf0e10cSrcweir return nRet; 74cdf0e10cSrcweir } 75cdf0e10cSrcweir 76cdf0e10cSrcweir // ----------------------------------------------------------------------- 77cdf0e10cSrcweir 78cdf0e10cSrcweir static sal_Int32 ImplStringICompare( const STRCODE* pStr1, const STRCODE* pStr2 ) 79cdf0e10cSrcweir { 80cdf0e10cSrcweir sal_Int32 nRet; 81cdf0e10cSrcweir STRCODE c1; 82cdf0e10cSrcweir STRCODE c2; 83cdf0e10cSrcweir do 84cdf0e10cSrcweir { 85cdf0e10cSrcweir // Ist das Zeichen zwischen 'A' und 'Z' dann umwandeln 86cdf0e10cSrcweir c1 = *pStr1; 87cdf0e10cSrcweir c2 = *pStr2; 88cdf0e10cSrcweir if ( (c1 >= 65) && (c1 <= 90) ) 89cdf0e10cSrcweir c1 += 32; 90cdf0e10cSrcweir if ( (c2 >= 65) && (c2 <= 90) ) 91cdf0e10cSrcweir c2 += 32; 92cdf0e10cSrcweir nRet = ((sal_Int32)((STRCODEU)c1))-((sal_Int32)((STRCODEU)c2)); 93cdf0e10cSrcweir if ( nRet != 0 ) 94cdf0e10cSrcweir break; 95cdf0e10cSrcweir 96cdf0e10cSrcweir ++pStr1, 97cdf0e10cSrcweir ++pStr2; 98cdf0e10cSrcweir } 99cdf0e10cSrcweir while ( c2 ); 100cdf0e10cSrcweir 101cdf0e10cSrcweir return nRet; 102cdf0e10cSrcweir } 103cdf0e10cSrcweir 104cdf0e10cSrcweir // ----------------------------------------------------------------------- 105cdf0e10cSrcweir 106cdf0e10cSrcweir static sal_Int32 ImplStringICompare( const STRCODE* pStr1, const STRCODE* pStr2, 107cdf0e10cSrcweir xub_StrLen nCount ) 108cdf0e10cSrcweir { 109cdf0e10cSrcweir sal_Int32 nRet = 0; 110cdf0e10cSrcweir STRCODE c1; 111cdf0e10cSrcweir STRCODE c2; 112cdf0e10cSrcweir do 113cdf0e10cSrcweir { 114cdf0e10cSrcweir if ( !nCount ) 115cdf0e10cSrcweir break; 116cdf0e10cSrcweir 117cdf0e10cSrcweir // Ist das Zeichen zwischen 'A' und 'Z' dann umwandeln 118cdf0e10cSrcweir c1 = *pStr1; 119cdf0e10cSrcweir c2 = *pStr2; 120cdf0e10cSrcweir if ( (c1 >= 65) && (c1 <= 90) ) 121cdf0e10cSrcweir c1 += 32; 122cdf0e10cSrcweir if ( (c2 >= 65) && (c2 <= 90) ) 123cdf0e10cSrcweir c2 += 32; 124cdf0e10cSrcweir nRet = ((sal_Int32)((STRCODEU)c1))-((sal_Int32)((STRCODEU)c2)); 125cdf0e10cSrcweir if ( nRet != 0 ) 126cdf0e10cSrcweir break; 127cdf0e10cSrcweir 128cdf0e10cSrcweir ++pStr1, 129cdf0e10cSrcweir ++pStr2, 130cdf0e10cSrcweir --nCount; 131cdf0e10cSrcweir } 132cdf0e10cSrcweir while ( c2 ); 133cdf0e10cSrcweir 134cdf0e10cSrcweir return nRet; 135cdf0e10cSrcweir } 136cdf0e10cSrcweir 137cdf0e10cSrcweir // ----------------------------------------------------------------------- 138cdf0e10cSrcweir 139cdf0e10cSrcweir static sal_Int32 ImplStringICompareWithoutZero( const STRCODE* pStr1, const STRCODE* pStr2, 140cdf0e10cSrcweir sal_Int32 nCount ) 141cdf0e10cSrcweir { 142cdf0e10cSrcweir sal_Int32 nRet = 0; 143cdf0e10cSrcweir STRCODE c1; 144cdf0e10cSrcweir STRCODE c2; 145cdf0e10cSrcweir do 146cdf0e10cSrcweir { 147cdf0e10cSrcweir if ( !nCount ) 148cdf0e10cSrcweir break; 149cdf0e10cSrcweir 150cdf0e10cSrcweir // Ist das Zeichen zwischen 'A' und 'Z' dann umwandeln 151cdf0e10cSrcweir c1 = *pStr1; 152cdf0e10cSrcweir c2 = *pStr2; 153cdf0e10cSrcweir if ( (c1 >= 65) && (c1 <= 90) ) 154cdf0e10cSrcweir c1 += 32; 155cdf0e10cSrcweir if ( (c2 >= 65) && (c2 <= 90) ) 156cdf0e10cSrcweir c2 += 32; 157cdf0e10cSrcweir nRet = ((sal_Int32)((STRCODEU)c1))-((sal_Int32)((STRCODEU)c2)); 158cdf0e10cSrcweir 159cdf0e10cSrcweir ++pStr1, 160cdf0e10cSrcweir ++pStr2, 161cdf0e10cSrcweir --nCount; 162cdf0e10cSrcweir } 163cdf0e10cSrcweir while ( nRet == 0 ); 164cdf0e10cSrcweir 165cdf0e10cSrcweir return nRet; 166cdf0e10cSrcweir } 167cdf0e10cSrcweir 168cdf0e10cSrcweir // ======================================================================= 169cdf0e10cSrcweir 170cdf0e10cSrcweir #ifdef DBG_UTIL 171cdf0e10cSrcweir const char* DBGCHECKSTRING( const void* pString ) 172cdf0e10cSrcweir { 173cdf0e10cSrcweir STRING* p = (STRING*)pString; 174cdf0e10cSrcweir 175cdf0e10cSrcweir if ( p->GetBuffer()[p->Len()] != 0 ) 176cdf0e10cSrcweir return "String damaged: aStr[nLen] != 0"; 177cdf0e10cSrcweir 178cdf0e10cSrcweir return NULL; 179cdf0e10cSrcweir } 180cdf0e10cSrcweir #endif 181cdf0e10cSrcweir 182cdf0e10cSrcweir // ======================================================================= 183cdf0e10cSrcweir 184cdf0e10cSrcweir static STRINGDATA* ImplAllocData( sal_Int32 nLen ) 185cdf0e10cSrcweir { 186cdf0e10cSrcweir // Dann kopiere die Daten 187cdf0e10cSrcweir STRINGDATA* pData = (STRINGDATA*)rtl_allocateMemory( sizeof(STRINGDATA)+(nLen*sizeof( STRCODE )) ); 188cdf0e10cSrcweir pData->mnRefCount = 1; 189cdf0e10cSrcweir pData->mnLen = nLen; 190cdf0e10cSrcweir pData->maStr[nLen] = 0; 191cdf0e10cSrcweir return pData; 192cdf0e10cSrcweir } 193cdf0e10cSrcweir 194cdf0e10cSrcweir // ----------------------------------------------------------------------- 195cdf0e10cSrcweir 196cdf0e10cSrcweir static STRINGDATA* _ImplCopyData( STRINGDATA* pData ) 197cdf0e10cSrcweir { 198cdf0e10cSrcweir unsigned int nSize = sizeof(STRINGDATA)+(pData->mnLen*sizeof( STRCODE )); 199cdf0e10cSrcweir STRINGDATA* pNewData = (STRINGDATA*)rtl_allocateMemory( nSize ); 200cdf0e10cSrcweir memcpy( pNewData, pData, nSize ); 201cdf0e10cSrcweir pNewData->mnRefCount = 1; 202cdf0e10cSrcweir STRING_RELEASE((STRING_TYPE *)pData); 203cdf0e10cSrcweir return pNewData; 204cdf0e10cSrcweir } 205cdf0e10cSrcweir 206cdf0e10cSrcweir // ----------------------------------------------------------------------- 207cdf0e10cSrcweir 208cdf0e10cSrcweir inline void STRING::ImplCopyData() 209cdf0e10cSrcweir { 210cdf0e10cSrcweir DBG_ASSERT( (mpData->mnRefCount != 0), "String::ImplCopyData() - RefCount == 0" ); 211cdf0e10cSrcweir 212cdf0e10cSrcweir // ist es ein referenzierter String, dann die Daten abkoppeln 213cdf0e10cSrcweir if ( mpData->mnRefCount != 1 ) 214cdf0e10cSrcweir mpData = _ImplCopyData( mpData ); 215cdf0e10cSrcweir } 216cdf0e10cSrcweir 217cdf0e10cSrcweir // ----------------------------------------------------------------------- 218cdf0e10cSrcweir 219cdf0e10cSrcweir inline STRCODE* STRING::ImplCopyStringData( STRCODE* pStr ) 220cdf0e10cSrcweir { 221cdf0e10cSrcweir // Ist der Referenzzaehler groesser 0 222cdf0e10cSrcweir if ( mpData->mnRefCount != 1 ) { 223cdf0e10cSrcweir DBG_ASSERT( (pStr >= mpData->maStr) && 224cdf0e10cSrcweir ((pStr-mpData->maStr) < mpData->mnLen), 225cdf0e10cSrcweir "ImplCopyStringData - pStr from other String-Instanz" ); 226cdf0e10cSrcweir unsigned int nIndex = (unsigned int)(pStr-mpData->maStr); 227cdf0e10cSrcweir mpData = _ImplCopyData( mpData ); 228cdf0e10cSrcweir pStr = mpData->maStr + nIndex; 229cdf0e10cSrcweir } 230cdf0e10cSrcweir return pStr; 231cdf0e10cSrcweir } 232cdf0e10cSrcweir 233cdf0e10cSrcweir // ----------------------------------------------------------------------- 234cdf0e10cSrcweir 235cdf0e10cSrcweir inline sal_Int32 ImplGetCopyLen( sal_Int32 nStrLen, sal_Int32 nCopyLen ) 236cdf0e10cSrcweir { 237cdf0e10cSrcweir OSL_ASSERT(nStrLen <= STRING_MAXLEN && nCopyLen <= STRING_MAXLEN); 238cdf0e10cSrcweir if ( nCopyLen > STRING_MAXLEN-nStrLen ) 239cdf0e10cSrcweir nCopyLen = STRING_MAXLEN-nStrLen; 240cdf0e10cSrcweir return nCopyLen; 241cdf0e10cSrcweir } 242cdf0e10cSrcweir 243cdf0e10cSrcweir // ======================================================================= 244cdf0e10cSrcweir 245cdf0e10cSrcweir STRING::STRING() 246cdf0e10cSrcweir : mpData(NULL) 247cdf0e10cSrcweir { 248cdf0e10cSrcweir DBG_CTOR( STRING, DBGCHECKSTRING ); 249cdf0e10cSrcweir 250cdf0e10cSrcweir STRING_NEW((STRING_TYPE **)&mpData); 251cdf0e10cSrcweir } 252cdf0e10cSrcweir 253cdf0e10cSrcweir // ----------------------------------------------------------------------- 254cdf0e10cSrcweir 255cdf0e10cSrcweir STRING::STRING( const STRING& rStr ) 256cdf0e10cSrcweir { 257cdf0e10cSrcweir DBG_CTOR( STRING, DBGCHECKSTRING ); 258cdf0e10cSrcweir DBG_CHKOBJ( &rStr, STRING, DBGCHECKSTRING ); 259cdf0e10cSrcweir 260cdf0e10cSrcweir // Pointer auf die Daten des uebergebenen Strings setzen und 261cdf0e10cSrcweir // Referenzzaehler erhoehen 262cdf0e10cSrcweir STRING_ACQUIRE((STRING_TYPE *)rStr.mpData); 263cdf0e10cSrcweir mpData = rStr.mpData; 264cdf0e10cSrcweir } 265cdf0e10cSrcweir 266cdf0e10cSrcweir // ----------------------------------------------------------------------- 267cdf0e10cSrcweir 268cdf0e10cSrcweir STRING::STRING( const STRING& rStr, xub_StrLen nPos, xub_StrLen nLen ) 269cdf0e10cSrcweir : mpData( NULL ) 270cdf0e10cSrcweir { 271cdf0e10cSrcweir DBG_CTOR( STRING, DBGCHECKSTRING ); 272cdf0e10cSrcweir DBG_CHKOBJ( &rStr, STRING, DBGCHECKSTRING ); 273cdf0e10cSrcweir 274cdf0e10cSrcweir // Stringlaenge ermitteln 275cdf0e10cSrcweir if ( nPos > rStr.mpData->mnLen ) 276cdf0e10cSrcweir nLen = 0; 277cdf0e10cSrcweir else 278cdf0e10cSrcweir { 279cdf0e10cSrcweir // Laenge korrigieren, wenn noetig 280cdf0e10cSrcweir sal_Int32 nMaxLen = rStr.mpData->mnLen-nPos; 281cdf0e10cSrcweir if ( nLen > nMaxLen ) 282cdf0e10cSrcweir nLen = static_cast< xub_StrLen >(nMaxLen); 283cdf0e10cSrcweir } 284cdf0e10cSrcweir 285cdf0e10cSrcweir // Ist es kein leerer String 286cdf0e10cSrcweir if ( nLen ) 287cdf0e10cSrcweir { 288cdf0e10cSrcweir // Reicht ein einfaches erhoehen des Referenzcounters 289cdf0e10cSrcweir if ( (nPos == 0) && (nLen == rStr.mpData->mnLen) ) 290cdf0e10cSrcweir { 291cdf0e10cSrcweir STRING_ACQUIRE((STRING_TYPE *)rStr.mpData); 292cdf0e10cSrcweir mpData = rStr.mpData; 293cdf0e10cSrcweir } 294cdf0e10cSrcweir else 295cdf0e10cSrcweir { 296cdf0e10cSrcweir // Verwaltungsdaten anlegen und String kopieren 297cdf0e10cSrcweir mpData = ImplAllocData( nLen ); 298cdf0e10cSrcweir memcpy( mpData->maStr, rStr.mpData->maStr+nPos, nLen*sizeof( STRCODE ) ); 299cdf0e10cSrcweir } 300cdf0e10cSrcweir } 301cdf0e10cSrcweir else 302cdf0e10cSrcweir { 303cdf0e10cSrcweir STRING_NEW((STRING_TYPE **)&mpData); 304cdf0e10cSrcweir } 305cdf0e10cSrcweir } 306cdf0e10cSrcweir 307cdf0e10cSrcweir // ----------------------------------------------------------------------- 308cdf0e10cSrcweir 309cdf0e10cSrcweir STRING::STRING( const STRCODE* pCharStr ) 310cdf0e10cSrcweir : mpData(NULL) 311cdf0e10cSrcweir { 312cdf0e10cSrcweir DBG_CTOR( STRING, DBGCHECKSTRING ); 313cdf0e10cSrcweir 314cdf0e10cSrcweir // Stringlaenge ermitteln 315cdf0e10cSrcweir // Bei diesem Ctor darf NULL uebergeben werden 316cdf0e10cSrcweir xub_StrLen nLen; 317cdf0e10cSrcweir if ( pCharStr ) 318cdf0e10cSrcweir nLen = ImplStringLen( pCharStr ); 319cdf0e10cSrcweir else 320cdf0e10cSrcweir nLen = 0; 321cdf0e10cSrcweir 322cdf0e10cSrcweir // Ist es kein leerer String 323cdf0e10cSrcweir if ( nLen ) 324cdf0e10cSrcweir { 325cdf0e10cSrcweir // Verwaltungsdaten anlegen und String kopieren 326cdf0e10cSrcweir mpData = ImplAllocData( nLen ); 327cdf0e10cSrcweir memcpy( mpData->maStr, pCharStr, nLen*sizeof( STRCODE ) ); 328cdf0e10cSrcweir } 329cdf0e10cSrcweir else 330cdf0e10cSrcweir { 331cdf0e10cSrcweir STRING_NEW((STRING_TYPE **)&mpData); 332cdf0e10cSrcweir } 333cdf0e10cSrcweir } 334cdf0e10cSrcweir 335cdf0e10cSrcweir // ----------------------------------------------------------------------- 336cdf0e10cSrcweir 337cdf0e10cSrcweir STRING::STRING( const STRCODE* pCharStr, xub_StrLen nLen ) 338cdf0e10cSrcweir : mpData(NULL) 339cdf0e10cSrcweir { 340cdf0e10cSrcweir DBG_CTOR( STRING, DBGCHECKSTRING ); 341cdf0e10cSrcweir DBG_ASSERT( pCharStr, "String::String() - pCharStr is NULL" ); 342cdf0e10cSrcweir 343cdf0e10cSrcweir if ( nLen == STRING_LEN ) 344cdf0e10cSrcweir nLen = ImplStringLen( pCharStr ); 345cdf0e10cSrcweir 346cdf0e10cSrcweir #ifdef DBG_UTIL 347cdf0e10cSrcweir if ( DbgIsAssert() ) 348cdf0e10cSrcweir { 349cdf0e10cSrcweir for ( xub_StrLen i = 0; i < nLen; i++ ) 350cdf0e10cSrcweir { 351cdf0e10cSrcweir if ( !pCharStr[i] ) 352cdf0e10cSrcweir { 353cdf0e10cSrcweir DBG_ERROR( "String::String() : nLen is wrong" ); 354cdf0e10cSrcweir } 355cdf0e10cSrcweir } 356cdf0e10cSrcweir } 357cdf0e10cSrcweir #endif 358cdf0e10cSrcweir 359cdf0e10cSrcweir // Ist es kein leerer String 360cdf0e10cSrcweir if ( nLen ) 361cdf0e10cSrcweir { 362cdf0e10cSrcweir // Verwaltungsdaten anlegen und String kopieren 363cdf0e10cSrcweir mpData = ImplAllocData( nLen ); 364cdf0e10cSrcweir memcpy( mpData->maStr, pCharStr, nLen*sizeof( STRCODE ) ); 365cdf0e10cSrcweir } 366cdf0e10cSrcweir else 367cdf0e10cSrcweir { 368cdf0e10cSrcweir STRING_NEW((STRING_TYPE **)&mpData); 369cdf0e10cSrcweir } 370cdf0e10cSrcweir } 371cdf0e10cSrcweir 372cdf0e10cSrcweir // ----------------------------------------------------------------------- 373cdf0e10cSrcweir 374cdf0e10cSrcweir STRING::STRING( STRCODE c ) 375cdf0e10cSrcweir { 376cdf0e10cSrcweir DBG_CTOR( STRING, DBGCHECKSTRING ); 377cdf0e10cSrcweir DBG_ASSERT( c, "String::String() - c is 0" ); 378cdf0e10cSrcweir 379cdf0e10cSrcweir // Verwaltungsdaten anlegen und initialisieren 380cdf0e10cSrcweir mpData = ImplAllocData( 1 ); 381cdf0e10cSrcweir mpData->maStr[0] = c; 382cdf0e10cSrcweir } 383cdf0e10cSrcweir 384cdf0e10cSrcweir // ----------------------------------------------------------------------- 385cdf0e10cSrcweir 386cdf0e10cSrcweir STRING::~STRING() 387cdf0e10cSrcweir { 388cdf0e10cSrcweir DBG_DTOR( STRING, DBGCHECKSTRING ); 389cdf0e10cSrcweir 390cdf0e10cSrcweir // Daten loeschen 391cdf0e10cSrcweir STRING_RELEASE((STRING_TYPE *)mpData); 392cdf0e10cSrcweir } 393cdf0e10cSrcweir 394cdf0e10cSrcweir // ----------------------------------------------------------------------- 395cdf0e10cSrcweir 396cdf0e10cSrcweir STRING& STRING::Assign( const STRING& rStr ) 397cdf0e10cSrcweir { 398cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 399cdf0e10cSrcweir DBG_CHKOBJ( &rStr, STRING, DBGCHECKSTRING ); 400cdf0e10cSrcweir 401cdf0e10cSrcweir STRING_ACQUIRE((STRING_TYPE *)rStr.mpData); 402cdf0e10cSrcweir STRING_RELEASE((STRING_TYPE *)mpData); 403cdf0e10cSrcweir mpData = rStr.mpData; 404cdf0e10cSrcweir return *this; 405cdf0e10cSrcweir } 406cdf0e10cSrcweir 407cdf0e10cSrcweir // ----------------------------------------------------------------------- 408cdf0e10cSrcweir 409cdf0e10cSrcweir STRING& STRING::Assign( const STRCODE* pCharStr ) 410cdf0e10cSrcweir { 411cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 412cdf0e10cSrcweir DBG_ASSERT( pCharStr, "String::Assign() - pCharStr is NULL" ); 413cdf0e10cSrcweir 414cdf0e10cSrcweir // Stringlaenge ermitteln 415cdf0e10cSrcweir xub_StrLen nLen = ImplStringLen( pCharStr ); 416cdf0e10cSrcweir 417cdf0e10cSrcweir if ( !nLen ) 418cdf0e10cSrcweir { 419cdf0e10cSrcweir STRING_NEW((STRING_TYPE **)&mpData); 420cdf0e10cSrcweir } 421cdf0e10cSrcweir else 422cdf0e10cSrcweir { 423cdf0e10cSrcweir // Wenn String genauso lang ist, wie der String, dann direkt kopieren 424cdf0e10cSrcweir if ( (nLen == mpData->mnLen) && (mpData->mnRefCount == 1) ) 425cdf0e10cSrcweir memcpy( mpData->maStr, pCharStr, nLen*sizeof( STRCODE ) ); 426cdf0e10cSrcweir else 427cdf0e10cSrcweir { 428cdf0e10cSrcweir // Alte Daten loeschen 429cdf0e10cSrcweir STRING_RELEASE((STRING_TYPE *)mpData); 430cdf0e10cSrcweir 431cdf0e10cSrcweir // Daten initialisieren und String kopieren 432cdf0e10cSrcweir mpData = ImplAllocData( nLen ); 433cdf0e10cSrcweir memcpy( mpData->maStr, pCharStr, nLen*sizeof( STRCODE ) ); 434cdf0e10cSrcweir } 435cdf0e10cSrcweir } 436cdf0e10cSrcweir 437cdf0e10cSrcweir return *this; 438cdf0e10cSrcweir } 439cdf0e10cSrcweir 440cdf0e10cSrcweir // ----------------------------------------------------------------------- 441cdf0e10cSrcweir 442cdf0e10cSrcweir STRING& STRING::Assign( const STRCODE* pCharStr, xub_StrLen nLen ) 443cdf0e10cSrcweir { 444cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 445cdf0e10cSrcweir DBG_ASSERT( pCharStr, "String::Assign() - pCharStr is NULL" ); 446cdf0e10cSrcweir 447cdf0e10cSrcweir if ( nLen == STRING_LEN ) 448cdf0e10cSrcweir nLen = ImplStringLen( pCharStr ); 449cdf0e10cSrcweir 450cdf0e10cSrcweir #ifdef DBG_UTIL 451cdf0e10cSrcweir if ( DbgIsAssert() ) 452cdf0e10cSrcweir { 453cdf0e10cSrcweir for ( xub_StrLen i = 0; i < nLen; i++ ) 454cdf0e10cSrcweir { 455cdf0e10cSrcweir if ( !pCharStr[i] ) 456cdf0e10cSrcweir { 457cdf0e10cSrcweir DBG_ERROR( "String::Assign() : nLen is wrong" ); 458cdf0e10cSrcweir } 459cdf0e10cSrcweir } 460cdf0e10cSrcweir } 461cdf0e10cSrcweir #endif 462cdf0e10cSrcweir 463cdf0e10cSrcweir if ( !nLen ) 464cdf0e10cSrcweir { 465cdf0e10cSrcweir STRING_NEW((STRING_TYPE **)&mpData); 466cdf0e10cSrcweir } 467cdf0e10cSrcweir else 468cdf0e10cSrcweir { 469cdf0e10cSrcweir // Wenn String genauso lang ist, wie der String, dann direkt kopieren 470cdf0e10cSrcweir if ( (nLen == mpData->mnLen) && (mpData->mnRefCount == 1) ) 471cdf0e10cSrcweir memcpy( mpData->maStr, pCharStr, nLen*sizeof( STRCODE ) ); 472cdf0e10cSrcweir else 473cdf0e10cSrcweir { 474cdf0e10cSrcweir // Alte Daten loeschen 475cdf0e10cSrcweir STRING_RELEASE((STRING_TYPE *)mpData); 476cdf0e10cSrcweir 477cdf0e10cSrcweir // Daten initialisieren und String kopieren 478cdf0e10cSrcweir mpData = ImplAllocData( nLen ); 479cdf0e10cSrcweir memcpy( mpData->maStr, pCharStr, nLen*sizeof( STRCODE ) ); 480cdf0e10cSrcweir } 481cdf0e10cSrcweir } 482cdf0e10cSrcweir 483cdf0e10cSrcweir return *this; 484cdf0e10cSrcweir } 485cdf0e10cSrcweir 486cdf0e10cSrcweir // ----------------------------------------------------------------------- 487cdf0e10cSrcweir 488cdf0e10cSrcweir STRING& STRING::Assign( STRCODE c ) 489cdf0e10cSrcweir { 490cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 491cdf0e10cSrcweir DBG_ASSERT( c, "String::Assign() - c is 0" ); 492cdf0e10cSrcweir 493cdf0e10cSrcweir // Verwaltungsdaten anlegen und initialisieren 494cdf0e10cSrcweir STRING_RELEASE((STRING_TYPE *)mpData); 495cdf0e10cSrcweir mpData = ImplAllocData( 1 ); 496cdf0e10cSrcweir mpData->maStr[0] = c; 497cdf0e10cSrcweir return *this; 498cdf0e10cSrcweir } 499cdf0e10cSrcweir 500cdf0e10cSrcweir // ----------------------------------------------------------------------- 501cdf0e10cSrcweir 502cdf0e10cSrcweir STRING& STRING::Append( const STRING& rStr ) 503cdf0e10cSrcweir { 504cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 505cdf0e10cSrcweir DBG_CHKOBJ( &rStr, STRING, DBGCHECKSTRING ); 506cdf0e10cSrcweir 507cdf0e10cSrcweir // Wenn String leer, dann reicht eine Zuweisung 508cdf0e10cSrcweir sal_Int32 nLen = mpData->mnLen; 509cdf0e10cSrcweir if ( !nLen ) 510cdf0e10cSrcweir { 511cdf0e10cSrcweir STRING_ACQUIRE((STRING_TYPE *)rStr.mpData); 512cdf0e10cSrcweir STRING_RELEASE((STRING_TYPE *)mpData); 513cdf0e10cSrcweir mpData = rStr.mpData; 514cdf0e10cSrcweir } 515cdf0e10cSrcweir else 516cdf0e10cSrcweir { 517cdf0e10cSrcweir // Ueberlauf abfangen 518cdf0e10cSrcweir sal_Int32 nCopyLen = ImplGetCopyLen( nLen, rStr.mpData->mnLen ); 519cdf0e10cSrcweir 520cdf0e10cSrcweir // Ist der uebergebene String kein Leerstring 521cdf0e10cSrcweir if ( nCopyLen ) 522cdf0e10cSrcweir { 523cdf0e10cSrcweir // Neue Datenstruktur und neuen String erzeugen 524cdf0e10cSrcweir STRINGDATA* pNewData = ImplAllocData( nLen+nCopyLen ); 525cdf0e10cSrcweir 526cdf0e10cSrcweir // String kopieren 527cdf0e10cSrcweir memcpy( pNewData->maStr, mpData->maStr, nLen*sizeof( STRCODE ) ); 528cdf0e10cSrcweir memcpy( pNewData->maStr+nLen, rStr.mpData->maStr, nCopyLen*sizeof( STRCODE ) ); 529cdf0e10cSrcweir 530cdf0e10cSrcweir // Alte Daten loeschen und Neue zuweisen 531cdf0e10cSrcweir STRING_RELEASE((STRING_TYPE *)mpData); 532cdf0e10cSrcweir mpData = pNewData; 533cdf0e10cSrcweir } 534cdf0e10cSrcweir } 535cdf0e10cSrcweir 536cdf0e10cSrcweir return *this; 537cdf0e10cSrcweir } 538cdf0e10cSrcweir 539cdf0e10cSrcweir // ----------------------------------------------------------------------- 540cdf0e10cSrcweir 541cdf0e10cSrcweir STRING& STRING::Append( const STRCODE* pCharStr ) 542cdf0e10cSrcweir { 543cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 544cdf0e10cSrcweir DBG_ASSERT( pCharStr, "String::Append() - pCharStr is NULL" ); 545cdf0e10cSrcweir 546cdf0e10cSrcweir // Stringlaenge ermitteln 547cdf0e10cSrcweir sal_Int32 nLen = mpData->mnLen; 548cdf0e10cSrcweir sal_Int32 nCopyLen = ImplStringLen( pCharStr ); 549cdf0e10cSrcweir 550cdf0e10cSrcweir // Ueberlauf abfangen 551cdf0e10cSrcweir nCopyLen = ImplGetCopyLen( nLen, nCopyLen ); 552cdf0e10cSrcweir 553cdf0e10cSrcweir // Ist es kein leerer String 554cdf0e10cSrcweir if ( nCopyLen ) 555cdf0e10cSrcweir { 556cdf0e10cSrcweir // Neue Datenstruktur und neuen String erzeugen 557cdf0e10cSrcweir STRINGDATA* pNewData = ImplAllocData( nLen+nCopyLen ); 558cdf0e10cSrcweir 559cdf0e10cSrcweir // String kopieren 560cdf0e10cSrcweir memcpy( pNewData->maStr, mpData->maStr, nLen*sizeof( STRCODE ) ); 561cdf0e10cSrcweir memcpy( pNewData->maStr+nLen, pCharStr, nCopyLen*sizeof( STRCODE ) ); 562cdf0e10cSrcweir 563cdf0e10cSrcweir // Alte Daten loeschen und Neue zuweisen 564cdf0e10cSrcweir STRING_RELEASE((STRING_TYPE *)mpData); 565cdf0e10cSrcweir mpData = pNewData; 566cdf0e10cSrcweir } 567cdf0e10cSrcweir 568cdf0e10cSrcweir return *this; 569cdf0e10cSrcweir } 570cdf0e10cSrcweir 571cdf0e10cSrcweir // ----------------------------------------------------------------------- 572cdf0e10cSrcweir 573cdf0e10cSrcweir STRING& STRING::Append( const STRCODE* pCharStr, xub_StrLen nCharLen ) 574cdf0e10cSrcweir { 575cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 576cdf0e10cSrcweir DBG_ASSERT( pCharStr, "String::Append() - pCharStr is NULL" ); 577cdf0e10cSrcweir 578cdf0e10cSrcweir if ( nCharLen == STRING_LEN ) 579cdf0e10cSrcweir nCharLen = ImplStringLen( pCharStr ); 580cdf0e10cSrcweir 581cdf0e10cSrcweir #ifdef DBG_UTIL 582cdf0e10cSrcweir if ( DbgIsAssert() ) 583cdf0e10cSrcweir { 584cdf0e10cSrcweir for ( xub_StrLen i = 0; i < nCharLen; i++ ) 585cdf0e10cSrcweir { 586cdf0e10cSrcweir if ( !pCharStr[i] ) 587cdf0e10cSrcweir { 588cdf0e10cSrcweir DBG_ERROR( "String::Append() : nLen is wrong" ); 589cdf0e10cSrcweir } 590cdf0e10cSrcweir } 591cdf0e10cSrcweir } 592cdf0e10cSrcweir #endif 593cdf0e10cSrcweir 594cdf0e10cSrcweir // Ueberlauf abfangen 595cdf0e10cSrcweir sal_Int32 nLen = mpData->mnLen; 596cdf0e10cSrcweir sal_Int32 nCopyLen = ImplGetCopyLen( nLen, nCharLen ); 597cdf0e10cSrcweir 598cdf0e10cSrcweir // Ist es kein leerer String 599cdf0e10cSrcweir if ( nCopyLen ) 600cdf0e10cSrcweir { 601cdf0e10cSrcweir // Neue Datenstruktur und neuen String erzeugen 602cdf0e10cSrcweir STRINGDATA* pNewData = ImplAllocData( nLen+nCopyLen ); 603cdf0e10cSrcweir 604cdf0e10cSrcweir // String kopieren 605cdf0e10cSrcweir memcpy( pNewData->maStr, mpData->maStr, nLen*sizeof( STRCODE ) ); 606cdf0e10cSrcweir memcpy( pNewData->maStr+nLen, pCharStr, nCopyLen*sizeof( STRCODE ) ); 607cdf0e10cSrcweir 608cdf0e10cSrcweir // Alte Daten loeschen und Neue zuweisen 609cdf0e10cSrcweir STRING_RELEASE((STRING_TYPE *)mpData); 610cdf0e10cSrcweir mpData = pNewData; 611cdf0e10cSrcweir } 612cdf0e10cSrcweir 613cdf0e10cSrcweir return *this; 614cdf0e10cSrcweir } 615cdf0e10cSrcweir 616cdf0e10cSrcweir // ----------------------------------------------------------------------- 617cdf0e10cSrcweir 618cdf0e10cSrcweir STRING& STRING::Append( STRCODE c ) 619cdf0e10cSrcweir { 620cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 621cdf0e10cSrcweir 622cdf0e10cSrcweir // kein 0-Character und maximale Stringlaenge nicht ueberschreiten 623cdf0e10cSrcweir sal_Int32 nLen = mpData->mnLen; 624cdf0e10cSrcweir if ( c && (nLen < STRING_MAXLEN) ) 625cdf0e10cSrcweir { 626cdf0e10cSrcweir // Neue Datenstruktur und neuen String erzeugen 627cdf0e10cSrcweir STRINGDATA* pNewData = ImplAllocData( nLen+1 ); 628cdf0e10cSrcweir 629cdf0e10cSrcweir // String kopieren 630cdf0e10cSrcweir memcpy( pNewData->maStr, mpData->maStr, nLen*sizeof( STRCODE ) ); 631cdf0e10cSrcweir pNewData->maStr[nLen] = c; 632cdf0e10cSrcweir 633cdf0e10cSrcweir // Alte Daten loeschen und Neue zuweisen 634cdf0e10cSrcweir STRING_RELEASE((STRING_TYPE *)mpData); 635cdf0e10cSrcweir mpData = pNewData; 636cdf0e10cSrcweir } 637cdf0e10cSrcweir 638cdf0e10cSrcweir return *this; 639cdf0e10cSrcweir } 640cdf0e10cSrcweir 641cdf0e10cSrcweir // ----------------------------------------------------------------------- 642cdf0e10cSrcweir 643cdf0e10cSrcweir void STRING::SetChar( xub_StrLen nIndex, STRCODE c ) 644cdf0e10cSrcweir { 645cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 646cdf0e10cSrcweir DBG_ASSERT( nIndex < mpData->mnLen, "String::SetChar() - nIndex > String.Len()" ); 647cdf0e10cSrcweir 648cdf0e10cSrcweir // Daten kopieren, wenn noetig und Character zuweisen 649cdf0e10cSrcweir ImplCopyData(); 650cdf0e10cSrcweir mpData->maStr[nIndex] = c; 651cdf0e10cSrcweir } 652cdf0e10cSrcweir 653cdf0e10cSrcweir // ----------------------------------------------------------------------- 654cdf0e10cSrcweir 655cdf0e10cSrcweir STRING& STRING::Insert( const STRING& rStr, xub_StrLen nIndex ) 656cdf0e10cSrcweir { 657cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 658cdf0e10cSrcweir DBG_CHKOBJ( &rStr, STRING, DBGCHECKSTRING ); 659cdf0e10cSrcweir 660cdf0e10cSrcweir // Ueberlauf abfangen 661cdf0e10cSrcweir sal_Int32 nCopyLen = ImplGetCopyLen( mpData->mnLen, rStr.mpData->mnLen ); 662cdf0e10cSrcweir 663cdf0e10cSrcweir // Ist der einzufuegende String ein Leerstring 664cdf0e10cSrcweir if ( !nCopyLen ) 665cdf0e10cSrcweir return *this; 666cdf0e10cSrcweir 667cdf0e10cSrcweir // Index groesser als Laenge 668cdf0e10cSrcweir if ( nIndex > mpData->mnLen ) 669cdf0e10cSrcweir nIndex = static_cast< xub_StrLen >(mpData->mnLen); 670cdf0e10cSrcweir 671cdf0e10cSrcweir // Neue Laenge ermitteln und neuen String anlegen 672cdf0e10cSrcweir STRINGDATA* pNewData = ImplAllocData( mpData->mnLen+nCopyLen ); 673cdf0e10cSrcweir 674cdf0e10cSrcweir // String kopieren 675cdf0e10cSrcweir memcpy( pNewData->maStr, mpData->maStr, nIndex*sizeof( STRCODE ) ); 676cdf0e10cSrcweir memcpy( pNewData->maStr+nIndex, rStr.mpData->maStr, nCopyLen*sizeof( STRCODE ) ); 677cdf0e10cSrcweir memcpy( pNewData->maStr+nIndex+nCopyLen, mpData->maStr+nIndex, 678cdf0e10cSrcweir (mpData->mnLen-nIndex)*sizeof( STRCODE ) ); 679cdf0e10cSrcweir 680cdf0e10cSrcweir // Alte Daten loeschen und Neue zuweisen 681cdf0e10cSrcweir STRING_RELEASE((STRING_TYPE *)mpData); 682cdf0e10cSrcweir mpData = pNewData; 683cdf0e10cSrcweir 684cdf0e10cSrcweir return *this; 685cdf0e10cSrcweir } 686cdf0e10cSrcweir 687cdf0e10cSrcweir // ----------------------------------------------------------------------- 688cdf0e10cSrcweir 689cdf0e10cSrcweir STRING& STRING::Insert( const STRING& rStr, xub_StrLen nPos, xub_StrLen nLen, 690cdf0e10cSrcweir xub_StrLen nIndex ) 691cdf0e10cSrcweir { 692cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 693cdf0e10cSrcweir DBG_CHKOBJ( &rStr, STRING, DBGCHECKSTRING ); 694cdf0e10cSrcweir 695cdf0e10cSrcweir // Stringlaenge ermitteln 696cdf0e10cSrcweir if ( nPos > rStr.mpData->mnLen ) 697cdf0e10cSrcweir nLen = 0; 698cdf0e10cSrcweir else 699cdf0e10cSrcweir { 700cdf0e10cSrcweir // Laenge korrigieren, wenn noetig 701cdf0e10cSrcweir sal_Int32 nMaxLen = rStr.mpData->mnLen-nPos; 702cdf0e10cSrcweir if ( nLen > nMaxLen ) 703cdf0e10cSrcweir nLen = static_cast< xub_StrLen >(nMaxLen); 704cdf0e10cSrcweir } 705cdf0e10cSrcweir 706cdf0e10cSrcweir // Ueberlauf abfangen 707cdf0e10cSrcweir sal_Int32 nCopyLen = ImplGetCopyLen( mpData->mnLen, nLen ); 708cdf0e10cSrcweir 709cdf0e10cSrcweir // Ist der einzufuegende String ein Leerstring 710cdf0e10cSrcweir if ( !nCopyLen ) 711cdf0e10cSrcweir return *this; 712cdf0e10cSrcweir 713cdf0e10cSrcweir // Index groesser als Laenge 714cdf0e10cSrcweir if ( nIndex > mpData->mnLen ) 715cdf0e10cSrcweir nIndex = static_cast< xub_StrLen >(mpData->mnLen); 716cdf0e10cSrcweir 717cdf0e10cSrcweir // Neue Laenge ermitteln und neuen String anlegen 718cdf0e10cSrcweir STRINGDATA* pNewData = ImplAllocData( mpData->mnLen+nCopyLen ); 719cdf0e10cSrcweir 720cdf0e10cSrcweir // String kopieren 721cdf0e10cSrcweir memcpy( pNewData->maStr, mpData->maStr, nIndex*sizeof( STRCODE ) ); 722cdf0e10cSrcweir memcpy( pNewData->maStr+nIndex, rStr.mpData->maStr+nPos, nCopyLen*sizeof( STRCODE ) ); 723cdf0e10cSrcweir memcpy( pNewData->maStr+nIndex+nCopyLen, mpData->maStr+nIndex, 724cdf0e10cSrcweir (mpData->mnLen-nIndex)*sizeof( STRCODE ) ); 725cdf0e10cSrcweir 726cdf0e10cSrcweir // Alte Daten loeschen und Neue zuweisen 727cdf0e10cSrcweir STRING_RELEASE((STRING_TYPE *)mpData); 728cdf0e10cSrcweir mpData = pNewData; 729cdf0e10cSrcweir 730cdf0e10cSrcweir return *this; 731cdf0e10cSrcweir } 732cdf0e10cSrcweir 733cdf0e10cSrcweir // ----------------------------------------------------------------------- 734cdf0e10cSrcweir 735cdf0e10cSrcweir STRING& STRING::Insert( const STRCODE* pCharStr, xub_StrLen nIndex ) 736cdf0e10cSrcweir { 737cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 738cdf0e10cSrcweir DBG_ASSERT( pCharStr, "String::Insert() - pCharStr is NULL" ); 739cdf0e10cSrcweir 740cdf0e10cSrcweir // Stringlaenge ermitteln 741cdf0e10cSrcweir sal_Int32 nCopyLen = ImplStringLen( pCharStr ); 742cdf0e10cSrcweir 743cdf0e10cSrcweir // Ueberlauf abfangen 744cdf0e10cSrcweir nCopyLen = ImplGetCopyLen( mpData->mnLen, nCopyLen ); 745cdf0e10cSrcweir 746cdf0e10cSrcweir // Ist der einzufuegende String ein Leerstring 747cdf0e10cSrcweir if ( !nCopyLen ) 748cdf0e10cSrcweir return *this; 749cdf0e10cSrcweir 750cdf0e10cSrcweir // Index groesser als Laenge 751cdf0e10cSrcweir if ( nIndex > mpData->mnLen ) 752cdf0e10cSrcweir nIndex = static_cast< xub_StrLen >(mpData->mnLen); 753cdf0e10cSrcweir 754cdf0e10cSrcweir // Neue Laenge ermitteln und neuen String anlegen 755cdf0e10cSrcweir STRINGDATA* pNewData = ImplAllocData( mpData->mnLen+nCopyLen ); 756cdf0e10cSrcweir 757cdf0e10cSrcweir // String kopieren 758cdf0e10cSrcweir memcpy( pNewData->maStr, mpData->maStr, nIndex*sizeof( STRCODE ) ); 759cdf0e10cSrcweir memcpy( pNewData->maStr+nIndex, pCharStr, nCopyLen*sizeof( STRCODE ) ); 760cdf0e10cSrcweir memcpy( pNewData->maStr+nIndex+nCopyLen, mpData->maStr+nIndex, 761cdf0e10cSrcweir (mpData->mnLen-nIndex)*sizeof( STRCODE ) ); 762cdf0e10cSrcweir 763cdf0e10cSrcweir // Alte Daten loeschen und Neue zuweisen 764cdf0e10cSrcweir STRING_RELEASE((STRING_TYPE *)mpData); 765cdf0e10cSrcweir mpData = pNewData; 766cdf0e10cSrcweir 767cdf0e10cSrcweir return *this; 768cdf0e10cSrcweir } 769cdf0e10cSrcweir 770cdf0e10cSrcweir // ----------------------------------------------------------------------- 771cdf0e10cSrcweir 772cdf0e10cSrcweir STRING& STRING::Insert( STRCODE c, xub_StrLen nIndex ) 773cdf0e10cSrcweir { 774cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 775cdf0e10cSrcweir 776cdf0e10cSrcweir // Ist es kein 0-Character 777cdf0e10cSrcweir if ( !c || (mpData->mnLen == STRING_MAXLEN) ) 778cdf0e10cSrcweir return *this; 779cdf0e10cSrcweir 780cdf0e10cSrcweir // Index groesser als Laenge 781cdf0e10cSrcweir if ( nIndex > mpData->mnLen ) 782cdf0e10cSrcweir nIndex = static_cast< xub_StrLen >(mpData->mnLen); 783cdf0e10cSrcweir 784cdf0e10cSrcweir // Neue Laenge ermitteln und neuen String anlegen 785cdf0e10cSrcweir STRINGDATA* pNewData = ImplAllocData( mpData->mnLen+1 ); 786cdf0e10cSrcweir 787cdf0e10cSrcweir // String kopieren 788cdf0e10cSrcweir memcpy( pNewData->maStr, mpData->maStr, nIndex*sizeof( STRCODE ) ); 789cdf0e10cSrcweir pNewData->maStr[nIndex] = c; 790cdf0e10cSrcweir memcpy( pNewData->maStr+nIndex+1, mpData->maStr+nIndex, 791cdf0e10cSrcweir (mpData->mnLen-nIndex)*sizeof( STRCODE ) ); 792cdf0e10cSrcweir 793cdf0e10cSrcweir // Alte Daten loeschen und Neue zuweisen 794cdf0e10cSrcweir STRING_RELEASE((STRING_TYPE *)mpData); 795cdf0e10cSrcweir mpData = pNewData; 796cdf0e10cSrcweir 797cdf0e10cSrcweir return *this; 798cdf0e10cSrcweir } 799cdf0e10cSrcweir 800cdf0e10cSrcweir // ----------------------------------------------------------------------- 801cdf0e10cSrcweir 802cdf0e10cSrcweir STRING& STRING::Replace( xub_StrLen nIndex, xub_StrLen nCount, const STRING& rStr ) 803cdf0e10cSrcweir { 804cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 805cdf0e10cSrcweir DBG_CHKOBJ( &rStr, STRING, DBGCHECKSTRING ); 806cdf0e10cSrcweir 807cdf0e10cSrcweir // Wenn Index groessergleich Laenge ist, dann ist es ein Append 808cdf0e10cSrcweir if ( nIndex >= mpData->mnLen ) 809cdf0e10cSrcweir { 810cdf0e10cSrcweir Append( rStr ); 811cdf0e10cSrcweir return *this; 812cdf0e10cSrcweir } 813cdf0e10cSrcweir 814cdf0e10cSrcweir // Ist es eine Zuweisung 815cdf0e10cSrcweir if ( (nIndex == 0) && (nCount >= mpData->mnLen) ) 816cdf0e10cSrcweir { 817cdf0e10cSrcweir Assign( rStr ); 818cdf0e10cSrcweir return *this; 819cdf0e10cSrcweir } 820cdf0e10cSrcweir 821cdf0e10cSrcweir // Reicht ein Erase 822cdf0e10cSrcweir sal_Int32 nStrLen = rStr.mpData->mnLen; 823cdf0e10cSrcweir if ( !nStrLen ) 824cdf0e10cSrcweir return Erase( nIndex, nCount ); 825cdf0e10cSrcweir 826cdf0e10cSrcweir // nCount darf nicht ueber das Stringende hinnausgehen 827cdf0e10cSrcweir if ( nCount > mpData->mnLen - nIndex ) 828cdf0e10cSrcweir nCount = static_cast< xub_StrLen >(mpData->mnLen-nIndex); 829cdf0e10cSrcweir 830cdf0e10cSrcweir // Reicht ein Insert 831cdf0e10cSrcweir if ( !nCount ) 832cdf0e10cSrcweir return Insert( rStr, nIndex ); 833cdf0e10cSrcweir 834cdf0e10cSrcweir // Reicht eine zeichenweise Zuweisung 835cdf0e10cSrcweir if ( nCount == nStrLen ) 836cdf0e10cSrcweir { 837cdf0e10cSrcweir ImplCopyData(); 838cdf0e10cSrcweir memcpy( mpData->maStr+nIndex, rStr.mpData->maStr, nCount*sizeof( STRCODE ) ); 839cdf0e10cSrcweir return *this; 840cdf0e10cSrcweir } 841cdf0e10cSrcweir 842cdf0e10cSrcweir // Ueberlauf abfangen 843cdf0e10cSrcweir nStrLen = ImplGetCopyLen( mpData->mnLen-nCount, nStrLen ); 844cdf0e10cSrcweir 845cdf0e10cSrcweir // Neue Daten anlegen 846cdf0e10cSrcweir STRINGDATA* pNewData = ImplAllocData( mpData->mnLen-nCount+nStrLen ); 847cdf0e10cSrcweir 848cdf0e10cSrcweir // String kopieren 849cdf0e10cSrcweir memcpy( pNewData->maStr, mpData->maStr, nIndex*sizeof( STRCODE ) ); 850cdf0e10cSrcweir memcpy( pNewData->maStr+nIndex, rStr.mpData->maStr, nStrLen*sizeof( STRCODE ) ); 851cdf0e10cSrcweir memcpy( pNewData->maStr+nIndex+nStrLen, mpData->maStr+nIndex+nCount, 852cdf0e10cSrcweir (mpData->mnLen-nIndex-nCount+1)*sizeof( STRCODE ) ); 853cdf0e10cSrcweir 854cdf0e10cSrcweir // Alte Daten loeschen und Neue zuweisen 855cdf0e10cSrcweir STRING_RELEASE((STRING_TYPE *)mpData); 856cdf0e10cSrcweir mpData = pNewData; 857cdf0e10cSrcweir 858cdf0e10cSrcweir return *this; 859cdf0e10cSrcweir } 860cdf0e10cSrcweir 861cdf0e10cSrcweir // ----------------------------------------------------------------------- 862cdf0e10cSrcweir 863cdf0e10cSrcweir STRING& STRING::Erase( xub_StrLen nIndex, xub_StrLen nCount ) 864cdf0e10cSrcweir { 865cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 866cdf0e10cSrcweir 867cdf0e10cSrcweir // Ist der Index ausserhalb des Strings oder ist nCount == 0 868cdf0e10cSrcweir if ( (nIndex >= mpData->mnLen) || !nCount ) 869cdf0e10cSrcweir return *this; 870cdf0e10cSrcweir 871cdf0e10cSrcweir // nCount darf nicht ueber das Stringende hinnausgehen 872cdf0e10cSrcweir if ( nCount > mpData->mnLen - nIndex ) 873cdf0e10cSrcweir nCount = static_cast< xub_StrLen >(mpData->mnLen-nIndex); 874cdf0e10cSrcweir 875cdf0e10cSrcweir // Ist das Ergebnis kein Leerstring 876cdf0e10cSrcweir if ( mpData->mnLen - nCount ) 877cdf0e10cSrcweir { 878cdf0e10cSrcweir // Neue Daten anlegen 879cdf0e10cSrcweir STRINGDATA* pNewData = ImplAllocData( mpData->mnLen-nCount ); 880cdf0e10cSrcweir 881cdf0e10cSrcweir // String kopieren 882cdf0e10cSrcweir memcpy( pNewData->maStr, mpData->maStr, nIndex*sizeof( STRCODE ) ); 883cdf0e10cSrcweir memcpy( pNewData->maStr+nIndex, mpData->maStr+nIndex+nCount, 884cdf0e10cSrcweir (mpData->mnLen-nIndex-nCount+1)*sizeof( STRCODE ) ); 885cdf0e10cSrcweir 886cdf0e10cSrcweir // Alte Daten loeschen und Neue zuweisen 887cdf0e10cSrcweir STRING_RELEASE((STRING_TYPE *)mpData); 888cdf0e10cSrcweir mpData = pNewData; 889cdf0e10cSrcweir } 890cdf0e10cSrcweir else 891cdf0e10cSrcweir { 892cdf0e10cSrcweir STRING_NEW((STRING_TYPE **)&mpData); 893cdf0e10cSrcweir } 894cdf0e10cSrcweir 895cdf0e10cSrcweir return *this; 896cdf0e10cSrcweir } 897cdf0e10cSrcweir 898cdf0e10cSrcweir // ----------------------------------------------------------------------- 899cdf0e10cSrcweir 900cdf0e10cSrcweir STRING& STRING::Fill( xub_StrLen nCount, STRCODE cFillChar ) 901cdf0e10cSrcweir { 902cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 903cdf0e10cSrcweir 904cdf0e10cSrcweir if ( !nCount ) 905cdf0e10cSrcweir return *this; 906cdf0e10cSrcweir 907cdf0e10cSrcweir // Ist nCount groesser wie der jetzige String, dann verlaengern 908cdf0e10cSrcweir if ( nCount > mpData->mnLen ) 909cdf0e10cSrcweir { 910cdf0e10cSrcweir // dann neuen String mit der neuen Laenge anlegen 911cdf0e10cSrcweir STRINGDATA* pNewData = ImplAllocData( nCount ); 912cdf0e10cSrcweir STRING_RELEASE((STRING_TYPE *)mpData); 913cdf0e10cSrcweir mpData = pNewData; 914cdf0e10cSrcweir } 915cdf0e10cSrcweir else 916cdf0e10cSrcweir ImplCopyData(); 917cdf0e10cSrcweir 918cdf0e10cSrcweir STRCODE* pStr = mpData->maStr; 919cdf0e10cSrcweir do 920cdf0e10cSrcweir { 921cdf0e10cSrcweir *pStr = cFillChar; 922cdf0e10cSrcweir ++pStr, 923cdf0e10cSrcweir --nCount; 924cdf0e10cSrcweir } 925cdf0e10cSrcweir while ( nCount ); 926cdf0e10cSrcweir 927cdf0e10cSrcweir return *this; 928cdf0e10cSrcweir } 929cdf0e10cSrcweir 930cdf0e10cSrcweir // ----------------------------------------------------------------------- 931cdf0e10cSrcweir 932cdf0e10cSrcweir STRING& STRING::Expand( xub_StrLen nCount, STRCODE cExpandChar ) 933cdf0e10cSrcweir { 934cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 935cdf0e10cSrcweir 936cdf0e10cSrcweir // Muss der String erweitert werden 937cdf0e10cSrcweir sal_Int32 nLen = mpData->mnLen; 938cdf0e10cSrcweir if ( nCount <= nLen ) 939cdf0e10cSrcweir return *this; 940cdf0e10cSrcweir 941cdf0e10cSrcweir // Neuen String anlegen 942cdf0e10cSrcweir STRINGDATA* pNewData = ImplAllocData( nCount ); 943cdf0e10cSrcweir 944cdf0e10cSrcweir // Alten String kopieren 945cdf0e10cSrcweir memcpy( pNewData->maStr, mpData->maStr, nLen*sizeof( STRCODE ) ); 946cdf0e10cSrcweir 947cdf0e10cSrcweir // und initialisieren 948cdf0e10cSrcweir STRCODE* pStr = pNewData->maStr; 949cdf0e10cSrcweir pStr += nLen; 950cdf0e10cSrcweir for (sal_Int32 i = nCount - nLen; i > 0; --i) { 951cdf0e10cSrcweir *pStr++ = cExpandChar; 952cdf0e10cSrcweir } 953cdf0e10cSrcweir 954cdf0e10cSrcweir // Alte Daten loeschen und Neue zuweisen 955cdf0e10cSrcweir STRING_RELEASE((STRING_TYPE *)mpData); 956cdf0e10cSrcweir mpData = pNewData; 957cdf0e10cSrcweir 958cdf0e10cSrcweir return *this; 959cdf0e10cSrcweir } 960cdf0e10cSrcweir 961cdf0e10cSrcweir // ----------------------------------------------------------------------- 962cdf0e10cSrcweir 963cdf0e10cSrcweir STRING& STRING::EraseLeadingChars( STRCODE c ) 964cdf0e10cSrcweir { 965cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 966cdf0e10cSrcweir 967cdf0e10cSrcweir if ( mpData->maStr[0] != c ) 968cdf0e10cSrcweir return *this; 969cdf0e10cSrcweir 970cdf0e10cSrcweir xub_StrLen nStart = 0; 971cdf0e10cSrcweir while ( mpData->maStr[nStart] == c ) 972cdf0e10cSrcweir ++nStart; 973cdf0e10cSrcweir 974cdf0e10cSrcweir return Erase( 0, nStart ); 975cdf0e10cSrcweir } 976cdf0e10cSrcweir 977cdf0e10cSrcweir // ----------------------------------------------------------------------- 978cdf0e10cSrcweir 979cdf0e10cSrcweir STRING& STRING::EraseTrailingChars( STRCODE c ) 980cdf0e10cSrcweir { 981cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 982cdf0e10cSrcweir 983cdf0e10cSrcweir sal_Int32 nEnd = mpData->mnLen; 984cdf0e10cSrcweir while ( nEnd && (mpData->maStr[nEnd-1] == c) ) 985cdf0e10cSrcweir nEnd--; 986cdf0e10cSrcweir 987cdf0e10cSrcweir if ( nEnd != mpData->mnLen ) 988cdf0e10cSrcweir Erase( static_cast< xub_StrLen >(nEnd) ); 989cdf0e10cSrcweir 990cdf0e10cSrcweir return *this; 991cdf0e10cSrcweir } 992cdf0e10cSrcweir 993cdf0e10cSrcweir // ----------------------------------------------------------------------- 994cdf0e10cSrcweir 995cdf0e10cSrcweir STRING& STRING::EraseLeadingAndTrailingChars( STRCODE c ) 996cdf0e10cSrcweir { 997cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 998cdf0e10cSrcweir 999cdf0e10cSrcweir xub_StrLen nStart = 0; 1000cdf0e10cSrcweir while ( mpData->maStr[nStart] == c ) 1001cdf0e10cSrcweir ++nStart; 1002cdf0e10cSrcweir if ( nStart ) 1003cdf0e10cSrcweir Erase( 0, nStart ); 1004cdf0e10cSrcweir 1005cdf0e10cSrcweir sal_Int32 nEnd = mpData->mnLen; 1006cdf0e10cSrcweir while ( nEnd && (mpData->maStr[nEnd-1] == c) ) 1007cdf0e10cSrcweir nEnd--; 1008cdf0e10cSrcweir if ( nEnd != mpData->mnLen ) 1009cdf0e10cSrcweir Erase( static_cast< xub_StrLen >(nEnd) ); 1010cdf0e10cSrcweir 1011cdf0e10cSrcweir return *this; 1012cdf0e10cSrcweir } 1013cdf0e10cSrcweir 1014cdf0e10cSrcweir // ----------------------------------------------------------------------- 1015cdf0e10cSrcweir 1016cdf0e10cSrcweir STRING& STRING::EraseAllChars( STRCODE c ) 1017cdf0e10cSrcweir { 1018cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 1019cdf0e10cSrcweir 1020cdf0e10cSrcweir sal_Int32 nCount = 0; 1021cdf0e10cSrcweir for (sal_Int32 i = 0; i < mpData->mnLen; ++i) { 1022cdf0e10cSrcweir if ( mpData->maStr[i] == c ) 1023cdf0e10cSrcweir ++nCount; 1024cdf0e10cSrcweir } 1025cdf0e10cSrcweir 1026cdf0e10cSrcweir if ( nCount ) 1027cdf0e10cSrcweir { 1028cdf0e10cSrcweir if ( nCount == mpData->mnLen ) 1029cdf0e10cSrcweir { 1030cdf0e10cSrcweir STRING_NEW((STRING_TYPE **)&mpData); 1031cdf0e10cSrcweir } 1032cdf0e10cSrcweir else 1033cdf0e10cSrcweir { 1034cdf0e10cSrcweir // Neuen String anlegen 1035cdf0e10cSrcweir STRINGDATA* pNewData = ImplAllocData( mpData->mnLen-nCount ); 1036cdf0e10cSrcweir 1037cdf0e10cSrcweir // Alten String kopieren und initialisieren 1038cdf0e10cSrcweir nCount = 0; 1039cdf0e10cSrcweir for( xub_StrLen j = 0; j < mpData->mnLen; ++j ) 1040cdf0e10cSrcweir { 1041cdf0e10cSrcweir if ( mpData->maStr[j] != c ) 1042cdf0e10cSrcweir { 1043cdf0e10cSrcweir pNewData->maStr[nCount] = mpData->maStr[j]; 1044cdf0e10cSrcweir ++nCount; 1045cdf0e10cSrcweir } 1046cdf0e10cSrcweir } 1047cdf0e10cSrcweir 1048cdf0e10cSrcweir // Alte Daten loeschen und Neue zuweisen 1049cdf0e10cSrcweir STRING_RELEASE((STRING_TYPE *)mpData); 1050cdf0e10cSrcweir mpData = pNewData; 1051cdf0e10cSrcweir } 1052cdf0e10cSrcweir } 1053cdf0e10cSrcweir 1054cdf0e10cSrcweir return *this; 1055cdf0e10cSrcweir } 1056cdf0e10cSrcweir 1057cdf0e10cSrcweir // ----------------------------------------------------------------------- 1058cdf0e10cSrcweir 1059cdf0e10cSrcweir STRING& STRING::Reverse() 1060cdf0e10cSrcweir { 1061cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 1062cdf0e10cSrcweir 1063cdf0e10cSrcweir if ( !mpData->mnLen ) 1064cdf0e10cSrcweir return *this; 1065cdf0e10cSrcweir 1066cdf0e10cSrcweir // Daten kopieren, wenn noetig 1067cdf0e10cSrcweir ImplCopyData(); 1068cdf0e10cSrcweir 1069cdf0e10cSrcweir // Reverse 1070cdf0e10cSrcweir sal_Int32 nCount = mpData->mnLen / 2; 1071cdf0e10cSrcweir for ( sal_Int32 i = 0; i < nCount; ++i ) 1072cdf0e10cSrcweir { 1073cdf0e10cSrcweir STRCODE cTemp = mpData->maStr[i]; 1074cdf0e10cSrcweir mpData->maStr[i] = mpData->maStr[mpData->mnLen-i-1]; 1075cdf0e10cSrcweir mpData->maStr[mpData->mnLen-i-1] = cTemp; 1076cdf0e10cSrcweir } 1077cdf0e10cSrcweir 1078cdf0e10cSrcweir return *this; 1079cdf0e10cSrcweir } 1080cdf0e10cSrcweir 1081cdf0e10cSrcweir // ----------------------------------------------------------------------- 1082cdf0e10cSrcweir 1083cdf0e10cSrcweir STRING& STRING::ToLowerAscii() 1084cdf0e10cSrcweir { 1085cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 1086cdf0e10cSrcweir 1087cdf0e10cSrcweir sal_Int32 nIndex = 0; 1088cdf0e10cSrcweir sal_Int32 nLen = mpData->mnLen; 1089cdf0e10cSrcweir STRCODE* pStr = mpData->maStr; 1090cdf0e10cSrcweir while ( nIndex < nLen ) 1091cdf0e10cSrcweir { 1092cdf0e10cSrcweir // Ist das Zeichen zwischen 'A' und 'Z' dann umwandeln 1093cdf0e10cSrcweir if ( (*pStr >= 65) && (*pStr <= 90) ) 1094cdf0e10cSrcweir { 1095cdf0e10cSrcweir // Daten kopieren, wenn noetig 1096cdf0e10cSrcweir pStr = ImplCopyStringData( pStr ); 1097cdf0e10cSrcweir *pStr += 32; 1098cdf0e10cSrcweir } 1099cdf0e10cSrcweir 1100cdf0e10cSrcweir ++pStr, 1101cdf0e10cSrcweir ++nIndex; 1102cdf0e10cSrcweir } 1103cdf0e10cSrcweir 1104cdf0e10cSrcweir return *this; 1105cdf0e10cSrcweir } 1106cdf0e10cSrcweir 1107cdf0e10cSrcweir // ----------------------------------------------------------------------- 1108cdf0e10cSrcweir 1109cdf0e10cSrcweir STRING& STRING::ToUpperAscii() 1110cdf0e10cSrcweir { 1111cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 1112cdf0e10cSrcweir 1113cdf0e10cSrcweir sal_Int32 nIndex = 0; 1114cdf0e10cSrcweir sal_Int32 nLen = mpData->mnLen; 1115cdf0e10cSrcweir STRCODE* pStr = mpData->maStr; 1116cdf0e10cSrcweir while ( nIndex < nLen ) 1117cdf0e10cSrcweir { 1118cdf0e10cSrcweir // Ist das Zeichen zwischen 'a' und 'z' dann umwandeln 1119cdf0e10cSrcweir if ( (*pStr >= 97) && (*pStr <= 122) ) 1120cdf0e10cSrcweir { 1121cdf0e10cSrcweir // Daten kopieren, wenn noetig 1122cdf0e10cSrcweir pStr = ImplCopyStringData( pStr ); 1123cdf0e10cSrcweir *pStr -= 32; 1124cdf0e10cSrcweir } 1125cdf0e10cSrcweir 1126cdf0e10cSrcweir ++pStr, 1127cdf0e10cSrcweir ++nIndex; 1128cdf0e10cSrcweir } 1129cdf0e10cSrcweir 1130cdf0e10cSrcweir return *this; 1131cdf0e10cSrcweir } 1132cdf0e10cSrcweir 1133cdf0e10cSrcweir // ----------------------------------------------------------------------- 1134cdf0e10cSrcweir 1135cdf0e10cSrcweir STRING& STRING::ConvertLineEnd( LineEnd eLineEnd ) 1136cdf0e10cSrcweir { 1137cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 1138cdf0e10cSrcweir 1139cdf0e10cSrcweir // Zeilenumbrueche ermitteln und neue Laenge berechnen 1140cdf0e10cSrcweir sal_Bool bConvert = sal_False; // Muss konvertiert werden 1141cdf0e10cSrcweir const STRCODE* pStr = mpData->maStr; // damit es schneller geht 1142cdf0e10cSrcweir xub_StrLen nLineEndLen = (eLineEnd == LINEEND_CRLF) ? 2 : 1; 1143cdf0e10cSrcweir xub_StrLen nLen = 0; // Ziel-Laenge 1144cdf0e10cSrcweir xub_StrLen i = 0; // Source-Zaehler 1145cdf0e10cSrcweir 1146cdf0e10cSrcweir while ( i < mpData->mnLen ) 1147cdf0e10cSrcweir { 1148cdf0e10cSrcweir // Bei \r oder \n gibt es neuen Zeilenumbruch 1149cdf0e10cSrcweir if ( (pStr[i] == _CR) || (pStr[i] == _LF) ) 1150cdf0e10cSrcweir { 1151cdf0e10cSrcweir nLen = nLen + nLineEndLen; 1152cdf0e10cSrcweir 1153cdf0e10cSrcweir // Wenn schon gesetzt, dann brauchen wir keine aufwendige Abfrage 1154cdf0e10cSrcweir if ( !bConvert ) 1155cdf0e10cSrcweir { 1156cdf0e10cSrcweir // Muessen wir Konvertieren 1157cdf0e10cSrcweir if ( ((eLineEnd != LINEEND_LF) && (pStr[i] == _LF)) || 1158cdf0e10cSrcweir ((eLineEnd == LINEEND_CRLF) && (pStr[i+1] != _LF)) || 1159cdf0e10cSrcweir ((eLineEnd == LINEEND_LF) && 1160cdf0e10cSrcweir ((pStr[i] == _CR) || (pStr[i+1] == _CR))) || 1161cdf0e10cSrcweir ((eLineEnd == LINEEND_CR) && 1162cdf0e10cSrcweir ((pStr[i] == _LF) || (pStr[i+1] == _LF))) ) 1163cdf0e10cSrcweir bConvert = sal_True; 1164cdf0e10cSrcweir } 1165cdf0e10cSrcweir 1166cdf0e10cSrcweir // \r\n oder \n\r, dann Zeichen ueberspringen 1167cdf0e10cSrcweir if ( ((pStr[i+1] == _CR) || (pStr[i+1] == _LF)) && 1168cdf0e10cSrcweir (pStr[i] != pStr[i+1]) ) 1169cdf0e10cSrcweir ++i; 1170cdf0e10cSrcweir } 1171cdf0e10cSrcweir else 1172cdf0e10cSrcweir ++nLen; 1173cdf0e10cSrcweir ++i; 1174cdf0e10cSrcweir 1175cdf0e10cSrcweir // Wenn String zu lang, dann konvertieren wir nicht 1176cdf0e10cSrcweir if ( nLen >= STRING_MAXLEN ) 1177cdf0e10cSrcweir return *this; 1178cdf0e10cSrcweir } 1179cdf0e10cSrcweir 1180cdf0e10cSrcweir // Zeilenumbrueche konvertieren 1181cdf0e10cSrcweir if ( bConvert ) 1182cdf0e10cSrcweir { 1183cdf0e10cSrcweir // Neuen String anlegen 1184cdf0e10cSrcweir STRINGDATA* pNewData = ImplAllocData( nLen ); 1185cdf0e10cSrcweir xub_StrLen j = 0; 1186cdf0e10cSrcweir i = 0; 1187cdf0e10cSrcweir while ( i < mpData->mnLen ) 1188cdf0e10cSrcweir { 1189cdf0e10cSrcweir // Bei \r oder \n gibt es neuen Zeilenumbruch 1190cdf0e10cSrcweir if ( (pStr[i] == _CR) || (pStr[i] == _LF) ) 1191cdf0e10cSrcweir { 1192cdf0e10cSrcweir if ( eLineEnd == LINEEND_CRLF ) 1193cdf0e10cSrcweir { 1194cdf0e10cSrcweir pNewData->maStr[j] = _CR; 1195cdf0e10cSrcweir pNewData->maStr[j+1] = _LF; 1196cdf0e10cSrcweir j += 2; 1197cdf0e10cSrcweir } 1198cdf0e10cSrcweir else 1199cdf0e10cSrcweir { 1200cdf0e10cSrcweir if ( eLineEnd == LINEEND_CR ) 1201cdf0e10cSrcweir pNewData->maStr[j] = _CR; 1202cdf0e10cSrcweir else 1203cdf0e10cSrcweir pNewData->maStr[j] = _LF; 1204cdf0e10cSrcweir ++j; 1205cdf0e10cSrcweir } 1206cdf0e10cSrcweir 1207cdf0e10cSrcweir if ( ((pStr[i+1] == _CR) || (pStr[i+1] == _LF)) && 1208cdf0e10cSrcweir (pStr[i] != pStr[i+1]) ) 1209cdf0e10cSrcweir ++i; 1210cdf0e10cSrcweir } 1211cdf0e10cSrcweir else 1212cdf0e10cSrcweir { 1213cdf0e10cSrcweir pNewData->maStr[j] = mpData->maStr[i]; 1214cdf0e10cSrcweir ++j; 1215cdf0e10cSrcweir } 1216cdf0e10cSrcweir 1217cdf0e10cSrcweir ++i; 1218cdf0e10cSrcweir } 1219cdf0e10cSrcweir 1220cdf0e10cSrcweir // Alte Daten loeschen und Neue zuweisen 1221cdf0e10cSrcweir STRING_RELEASE((STRING_TYPE *)mpData); 1222cdf0e10cSrcweir mpData = pNewData; 1223cdf0e10cSrcweir } 1224cdf0e10cSrcweir 1225cdf0e10cSrcweir return *this; 1226cdf0e10cSrcweir } 1227cdf0e10cSrcweir 1228cdf0e10cSrcweir // ----------------------------------------------------------------------- 1229cdf0e10cSrcweir 1230cdf0e10cSrcweir StringCompare STRING::CompareTo( const STRING& rStr, xub_StrLen nLen ) const 1231cdf0e10cSrcweir { 1232cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 1233cdf0e10cSrcweir DBG_CHKOBJ( &rStr, STRING, DBGCHECKSTRING ); 1234cdf0e10cSrcweir 1235cdf0e10cSrcweir // Auf Gleichheit der Pointer testen 1236cdf0e10cSrcweir if ( mpData == rStr.mpData ) 1237cdf0e10cSrcweir return COMPARE_EQUAL; 1238cdf0e10cSrcweir 1239cdf0e10cSrcweir // Maximale Laenge ermitteln 1240cdf0e10cSrcweir if ( mpData->mnLen < nLen ) 1241cdf0e10cSrcweir nLen = static_cast< xub_StrLen >(mpData->mnLen+1); 1242cdf0e10cSrcweir if ( rStr.mpData->mnLen < nLen ) 1243cdf0e10cSrcweir nLen = static_cast< xub_StrLen >(rStr.mpData->mnLen+1); 1244cdf0e10cSrcweir 1245cdf0e10cSrcweir // String vergleichen 1246cdf0e10cSrcweir sal_Int32 nCompare = ImplStringCompareWithoutZero( mpData->maStr, rStr.mpData->maStr, nLen ); 1247cdf0e10cSrcweir 1248cdf0e10cSrcweir // Rueckgabewert anpassen 1249cdf0e10cSrcweir if ( nCompare == 0 ) 1250cdf0e10cSrcweir return COMPARE_EQUAL; 1251cdf0e10cSrcweir else if ( nCompare < 0 ) 1252cdf0e10cSrcweir return COMPARE_LESS; 1253cdf0e10cSrcweir else 1254cdf0e10cSrcweir return COMPARE_GREATER; 1255cdf0e10cSrcweir } 1256cdf0e10cSrcweir 1257cdf0e10cSrcweir // ----------------------------------------------------------------------- 1258cdf0e10cSrcweir 1259cdf0e10cSrcweir StringCompare STRING::CompareTo( const STRCODE* pCharStr, xub_StrLen nLen ) const 1260cdf0e10cSrcweir { 1261cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 1262cdf0e10cSrcweir 1263cdf0e10cSrcweir // String vergleichen 1264cdf0e10cSrcweir sal_Int32 nCompare = ImplStringCompare( mpData->maStr, pCharStr, nLen ); 1265cdf0e10cSrcweir 1266cdf0e10cSrcweir // Rueckgabewert anpassen 1267cdf0e10cSrcweir if ( nCompare == 0 ) 1268cdf0e10cSrcweir return COMPARE_EQUAL; 1269cdf0e10cSrcweir else if ( nCompare < 0 ) 1270cdf0e10cSrcweir return COMPARE_LESS; 1271cdf0e10cSrcweir else 1272cdf0e10cSrcweir return COMPARE_GREATER; 1273cdf0e10cSrcweir } 1274cdf0e10cSrcweir 1275cdf0e10cSrcweir // ----------------------------------------------------------------------- 1276cdf0e10cSrcweir 1277cdf0e10cSrcweir StringCompare STRING::CompareIgnoreCaseToAscii( const STRING& rStr, 1278cdf0e10cSrcweir xub_StrLen nLen ) const 1279cdf0e10cSrcweir { 1280cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 1281cdf0e10cSrcweir DBG_CHKOBJ( &rStr, STRING, DBGCHECKSTRING ); 1282cdf0e10cSrcweir 1283cdf0e10cSrcweir // Auf Gleichheit der Pointer testen 1284cdf0e10cSrcweir if ( mpData == rStr.mpData ) 1285cdf0e10cSrcweir return COMPARE_EQUAL; 1286cdf0e10cSrcweir 1287cdf0e10cSrcweir // Maximale Laenge ermitteln 1288cdf0e10cSrcweir if ( mpData->mnLen < nLen ) 1289cdf0e10cSrcweir nLen = static_cast< xub_StrLen >(mpData->mnLen+1); 1290cdf0e10cSrcweir if ( rStr.mpData->mnLen < nLen ) 1291cdf0e10cSrcweir nLen = static_cast< xub_StrLen >(rStr.mpData->mnLen+1); 1292cdf0e10cSrcweir 1293cdf0e10cSrcweir // String vergleichen 1294cdf0e10cSrcweir sal_Int32 nCompare = ImplStringICompareWithoutZero( mpData->maStr, rStr.mpData->maStr, nLen ); 1295cdf0e10cSrcweir 1296cdf0e10cSrcweir // Rueckgabewert anpassen 1297cdf0e10cSrcweir if ( nCompare == 0 ) 1298cdf0e10cSrcweir return COMPARE_EQUAL; 1299cdf0e10cSrcweir else if ( nCompare < 0 ) 1300cdf0e10cSrcweir return COMPARE_LESS; 1301cdf0e10cSrcweir else 1302cdf0e10cSrcweir return COMPARE_GREATER; 1303cdf0e10cSrcweir } 1304cdf0e10cSrcweir 1305cdf0e10cSrcweir // ----------------------------------------------------------------------- 1306cdf0e10cSrcweir 1307cdf0e10cSrcweir StringCompare STRING::CompareIgnoreCaseToAscii( const STRCODE* pCharStr, 1308cdf0e10cSrcweir xub_StrLen nLen ) const 1309cdf0e10cSrcweir { 1310cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 1311cdf0e10cSrcweir 1312cdf0e10cSrcweir // String vergleichen 1313cdf0e10cSrcweir sal_Int32 nCompare = ImplStringICompare( mpData->maStr, pCharStr, nLen ); 1314cdf0e10cSrcweir 1315cdf0e10cSrcweir // Rueckgabewert anpassen 1316cdf0e10cSrcweir if ( nCompare == 0 ) 1317cdf0e10cSrcweir return COMPARE_EQUAL; 1318cdf0e10cSrcweir else if ( nCompare < 0 ) 1319cdf0e10cSrcweir return COMPARE_LESS; 1320cdf0e10cSrcweir else 1321cdf0e10cSrcweir return COMPARE_GREATER; 1322cdf0e10cSrcweir } 1323cdf0e10cSrcweir 1324cdf0e10cSrcweir // ----------------------------------------------------------------------- 1325cdf0e10cSrcweir 1326cdf0e10cSrcweir sal_Bool STRING::Equals( const STRING& rStr ) const 1327cdf0e10cSrcweir { 1328cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 1329cdf0e10cSrcweir DBG_CHKOBJ( &rStr, STRING, DBGCHECKSTRING ); 1330cdf0e10cSrcweir 1331cdf0e10cSrcweir // Sind die Daten gleich 1332cdf0e10cSrcweir if ( mpData == rStr.mpData ) 1333cdf0e10cSrcweir return sal_True; 1334cdf0e10cSrcweir 1335cdf0e10cSrcweir // Gleiche Laenge 1336cdf0e10cSrcweir if ( mpData->mnLen != rStr.mpData->mnLen ) 1337cdf0e10cSrcweir return sal_False; 1338cdf0e10cSrcweir 1339cdf0e10cSrcweir // String vergleichen 1340cdf0e10cSrcweir return (ImplStringCompareWithoutZero( mpData->maStr, rStr.mpData->maStr, mpData->mnLen ) == 0); 1341cdf0e10cSrcweir } 1342cdf0e10cSrcweir 1343cdf0e10cSrcweir // ----------------------------------------------------------------------- 1344cdf0e10cSrcweir 1345cdf0e10cSrcweir sal_Bool STRING::Equals( const STRCODE* pCharStr ) const 1346cdf0e10cSrcweir { 1347cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 1348cdf0e10cSrcweir 1349cdf0e10cSrcweir return (ImplStringCompare( mpData->maStr, pCharStr ) == 0); 1350cdf0e10cSrcweir } 1351cdf0e10cSrcweir 1352cdf0e10cSrcweir // ----------------------------------------------------------------------- 1353cdf0e10cSrcweir 1354cdf0e10cSrcweir sal_Bool STRING::EqualsIgnoreCaseAscii( const STRING& rStr ) const 1355cdf0e10cSrcweir { 1356cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 1357cdf0e10cSrcweir DBG_CHKOBJ( &rStr, STRING, DBGCHECKSTRING ); 1358cdf0e10cSrcweir 1359cdf0e10cSrcweir // Sind die Daten gleich 1360cdf0e10cSrcweir if ( mpData == rStr.mpData ) 1361cdf0e10cSrcweir return sal_True; 1362cdf0e10cSrcweir 1363cdf0e10cSrcweir // Gleiche Laenge 1364cdf0e10cSrcweir if ( mpData->mnLen != rStr.mpData->mnLen ) 1365cdf0e10cSrcweir return sal_False; 1366cdf0e10cSrcweir 1367cdf0e10cSrcweir // String vergleichen 1368cdf0e10cSrcweir return (ImplStringICompareWithoutZero( mpData->maStr, rStr.mpData->maStr, mpData->mnLen ) == 0); 1369cdf0e10cSrcweir } 1370cdf0e10cSrcweir 1371cdf0e10cSrcweir // ----------------------------------------------------------------------- 1372cdf0e10cSrcweir 1373cdf0e10cSrcweir sal_Bool STRING::EqualsIgnoreCaseAscii( const STRCODE* pCharStr ) const 1374cdf0e10cSrcweir { 1375cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 1376cdf0e10cSrcweir 1377cdf0e10cSrcweir return (ImplStringICompare( mpData->maStr, pCharStr ) == 0); 1378cdf0e10cSrcweir } 1379cdf0e10cSrcweir 1380cdf0e10cSrcweir // ----------------------------------------------------------------------- 1381cdf0e10cSrcweir 1382cdf0e10cSrcweir sal_Bool STRING::Equals( const STRING& rStr, xub_StrLen nIndex, xub_StrLen nLen ) const 1383cdf0e10cSrcweir { 1384cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 1385cdf0e10cSrcweir DBG_CHKOBJ( &rStr, STRING, DBGCHECKSTRING ); 1386cdf0e10cSrcweir 1387cdf0e10cSrcweir // Are there enough codes for comparing? 1388cdf0e10cSrcweir if ( nIndex > mpData->mnLen ) 1389cdf0e10cSrcweir return (rStr.mpData->mnLen == 0); 1390cdf0e10cSrcweir sal_Int32 nMaxLen = mpData->mnLen-nIndex; 1391cdf0e10cSrcweir if ( nMaxLen < nLen ) 1392cdf0e10cSrcweir { 1393cdf0e10cSrcweir if ( rStr.mpData->mnLen != nMaxLen ) 1394cdf0e10cSrcweir return sal_False; 1395cdf0e10cSrcweir nLen = static_cast< xub_StrLen >(nMaxLen); 1396cdf0e10cSrcweir } 1397cdf0e10cSrcweir 1398cdf0e10cSrcweir // String vergleichen 1399cdf0e10cSrcweir return (ImplStringCompareWithoutZero( mpData->maStr+nIndex, rStr.mpData->maStr, nLen ) == 0); 1400cdf0e10cSrcweir } 1401cdf0e10cSrcweir 1402cdf0e10cSrcweir // ----------------------------------------------------------------------- 1403cdf0e10cSrcweir 1404cdf0e10cSrcweir sal_Bool STRING::Equals( const STRCODE* pCharStr, xub_StrLen nIndex, xub_StrLen nLen ) const 1405cdf0e10cSrcweir { 1406cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 1407cdf0e10cSrcweir 1408cdf0e10cSrcweir // Are there enough codes for comparing? 1409cdf0e10cSrcweir if ( nIndex > mpData->mnLen ) 1410cdf0e10cSrcweir return (*pCharStr == 0); 1411cdf0e10cSrcweir 1412cdf0e10cSrcweir return (ImplStringCompare( mpData->maStr+nIndex, pCharStr, nLen ) == 0); 1413cdf0e10cSrcweir } 1414cdf0e10cSrcweir 1415cdf0e10cSrcweir // ----------------------------------------------------------------------- 1416cdf0e10cSrcweir 1417cdf0e10cSrcweir sal_Bool STRING::EqualsIgnoreCaseAscii( const STRING& rStr, xub_StrLen nIndex, xub_StrLen nLen ) const 1418cdf0e10cSrcweir { 1419cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 1420cdf0e10cSrcweir DBG_CHKOBJ( &rStr, STRING, DBGCHECKSTRING ); 1421cdf0e10cSrcweir 1422cdf0e10cSrcweir // Are there enough codes for comparing? 1423cdf0e10cSrcweir if ( nIndex > mpData->mnLen ) 1424cdf0e10cSrcweir return (rStr.mpData->mnLen == 0); 1425cdf0e10cSrcweir sal_Int32 nMaxLen = mpData->mnLen-nIndex; 1426cdf0e10cSrcweir if ( nMaxLen < nLen ) 1427cdf0e10cSrcweir { 1428cdf0e10cSrcweir if ( rStr.mpData->mnLen != nMaxLen ) 1429cdf0e10cSrcweir return sal_False; 1430cdf0e10cSrcweir nLen = static_cast< xub_StrLen >(nMaxLen); 1431cdf0e10cSrcweir } 1432cdf0e10cSrcweir 1433cdf0e10cSrcweir // String vergleichen 1434cdf0e10cSrcweir return (ImplStringICompareWithoutZero( mpData->maStr+nIndex, rStr.mpData->maStr, nLen ) == 0); 1435cdf0e10cSrcweir } 1436cdf0e10cSrcweir 1437cdf0e10cSrcweir // ----------------------------------------------------------------------- 1438cdf0e10cSrcweir 1439cdf0e10cSrcweir sal_Bool STRING::EqualsIgnoreCaseAscii( const STRCODE* pCharStr, xub_StrLen nIndex, xub_StrLen nLen ) const 1440cdf0e10cSrcweir { 1441cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 1442cdf0e10cSrcweir 1443cdf0e10cSrcweir // Are there enough codes for comparing? 1444cdf0e10cSrcweir if ( nIndex > mpData->mnLen ) 1445cdf0e10cSrcweir return (*pCharStr == 0); 1446cdf0e10cSrcweir 1447cdf0e10cSrcweir return (ImplStringICompare( mpData->maStr+nIndex, pCharStr, nLen ) == 0); 1448cdf0e10cSrcweir } 1449cdf0e10cSrcweir 1450cdf0e10cSrcweir // ----------------------------------------------------------------------- 1451cdf0e10cSrcweir 1452cdf0e10cSrcweir xub_StrLen STRING::Match( const STRING& rStr ) const 1453cdf0e10cSrcweir { 1454cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 1455cdf0e10cSrcweir DBG_CHKOBJ( &rStr, STRING, DBGCHECKSTRING ); 1456cdf0e10cSrcweir 1457cdf0e10cSrcweir // Ist dieser String leer 1458cdf0e10cSrcweir if ( !mpData->mnLen ) 1459cdf0e10cSrcweir return STRING_MATCH; 1460cdf0e10cSrcweir 1461cdf0e10cSrcweir // Suche bis Stringende nach dem ersten nicht uebereinstimmenden Zeichen 1462cdf0e10cSrcweir const STRCODE* pStr1 = mpData->maStr; 1463cdf0e10cSrcweir const STRCODE* pStr2 = rStr.mpData->maStr; 1464cdf0e10cSrcweir xub_StrLen i = 0; 1465cdf0e10cSrcweir while ( i < mpData->mnLen ) 1466cdf0e10cSrcweir { 1467cdf0e10cSrcweir // Stimmt das Zeichen nicht ueberein, dann abbrechen 1468cdf0e10cSrcweir if ( *pStr1 != *pStr2 ) 1469cdf0e10cSrcweir return i; 1470cdf0e10cSrcweir ++pStr1, 1471cdf0e10cSrcweir ++pStr2, 1472cdf0e10cSrcweir ++i; 1473cdf0e10cSrcweir } 1474cdf0e10cSrcweir 1475cdf0e10cSrcweir return STRING_MATCH; 1476cdf0e10cSrcweir } 1477cdf0e10cSrcweir 1478cdf0e10cSrcweir // ----------------------------------------------------------------------- 1479cdf0e10cSrcweir 1480cdf0e10cSrcweir xub_StrLen STRING::Match( const STRCODE* pCharStr ) const 1481cdf0e10cSrcweir { 1482cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 1483cdf0e10cSrcweir 1484cdf0e10cSrcweir // Ist dieser String leer 1485cdf0e10cSrcweir if ( !mpData->mnLen ) 1486cdf0e10cSrcweir return STRING_MATCH; 1487cdf0e10cSrcweir 1488cdf0e10cSrcweir // Suche bis Stringende nach dem ersten nicht uebereinstimmenden Zeichen 1489cdf0e10cSrcweir const STRCODE* pStr = mpData->maStr; 1490cdf0e10cSrcweir xub_StrLen i = 0; 1491cdf0e10cSrcweir while ( i < mpData->mnLen ) 1492cdf0e10cSrcweir { 1493cdf0e10cSrcweir // Stimmt das Zeichen nicht ueberein, dann abbrechen 1494cdf0e10cSrcweir if ( *pStr != *pCharStr ) 1495cdf0e10cSrcweir return i; 1496cdf0e10cSrcweir ++pStr, 1497cdf0e10cSrcweir ++pCharStr, 1498cdf0e10cSrcweir ++i; 1499cdf0e10cSrcweir } 1500cdf0e10cSrcweir 1501cdf0e10cSrcweir return STRING_MATCH; 1502cdf0e10cSrcweir } 1503cdf0e10cSrcweir 1504cdf0e10cSrcweir // ----------------------------------------------------------------------- 1505cdf0e10cSrcweir 1506cdf0e10cSrcweir xub_StrLen STRING::Search( STRCODE c, xub_StrLen nIndex ) const 1507cdf0e10cSrcweir { 1508cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 1509cdf0e10cSrcweir 1510cdf0e10cSrcweir sal_Int32 nLen = mpData->mnLen; 1511cdf0e10cSrcweir const STRCODE* pStr = mpData->maStr; 1512cdf0e10cSrcweir pStr += nIndex; 1513cdf0e10cSrcweir while ( nIndex < nLen ) 1514cdf0e10cSrcweir { 1515cdf0e10cSrcweir if ( *pStr == c ) 1516cdf0e10cSrcweir return nIndex; 1517cdf0e10cSrcweir ++pStr, 1518cdf0e10cSrcweir ++nIndex; 1519cdf0e10cSrcweir } 1520cdf0e10cSrcweir 1521cdf0e10cSrcweir return STRING_NOTFOUND; 1522cdf0e10cSrcweir } 1523cdf0e10cSrcweir 1524cdf0e10cSrcweir // ----------------------------------------------------------------------- 1525cdf0e10cSrcweir 1526cdf0e10cSrcweir xub_StrLen STRING::Search( const STRING& rStr, xub_StrLen nIndex ) const 1527cdf0e10cSrcweir { 1528cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 1529cdf0e10cSrcweir DBG_CHKOBJ( &rStr, STRING, DBGCHECKSTRING ); 1530cdf0e10cSrcweir 1531cdf0e10cSrcweir sal_Int32 nLen = mpData->mnLen; 1532cdf0e10cSrcweir sal_Int32 nStrLen = rStr.mpData->mnLen; 1533cdf0e10cSrcweir 1534cdf0e10cSrcweir // Falls die Laenge des uebergebenen Strings 0 ist oder der Index 1535cdf0e10cSrcweir // hinter dem String liegt, dann wurde der String nicht gefunden 1536cdf0e10cSrcweir if ( !nStrLen || (nIndex >= nLen) ) 1537cdf0e10cSrcweir return STRING_NOTFOUND; 1538cdf0e10cSrcweir 1539cdf0e10cSrcweir const STRCODE* pStr1 = mpData->maStr; 1540cdf0e10cSrcweir pStr1 += nIndex; 1541cdf0e10cSrcweir 1542cdf0e10cSrcweir if ( nStrLen == 1 ) 1543cdf0e10cSrcweir { 1544cdf0e10cSrcweir STRCODE cSearch = rStr.mpData->maStr[0]; 1545cdf0e10cSrcweir while ( nIndex < nLen ) 1546cdf0e10cSrcweir { 1547cdf0e10cSrcweir if ( *pStr1 == cSearch ) 1548cdf0e10cSrcweir return nIndex; 1549cdf0e10cSrcweir ++pStr1, 1550cdf0e10cSrcweir ++nIndex; 1551cdf0e10cSrcweir } 1552cdf0e10cSrcweir } 1553cdf0e10cSrcweir else 1554cdf0e10cSrcweir { 1555cdf0e10cSrcweir const STRCODE* pStr2 = rStr.mpData->maStr; 1556cdf0e10cSrcweir 1557cdf0e10cSrcweir // Nur innerhalb des Strings suchen 1558cdf0e10cSrcweir while ( nLen - nIndex >= nStrLen ) 1559cdf0e10cSrcweir { 1560cdf0e10cSrcweir // Stimmt der String ueberein 1561cdf0e10cSrcweir if ( ImplStringCompareWithoutZero( pStr1, pStr2, nStrLen ) == 0 ) 1562cdf0e10cSrcweir return nIndex; 1563cdf0e10cSrcweir ++pStr1, 1564cdf0e10cSrcweir ++nIndex; 1565cdf0e10cSrcweir } 1566cdf0e10cSrcweir } 1567cdf0e10cSrcweir 1568cdf0e10cSrcweir return STRING_NOTFOUND; 1569cdf0e10cSrcweir } 1570cdf0e10cSrcweir 1571cdf0e10cSrcweir // ----------------------------------------------------------------------- 1572cdf0e10cSrcweir 1573cdf0e10cSrcweir xub_StrLen STRING::Search( const STRCODE* pCharStr, xub_StrLen nIndex ) const 1574cdf0e10cSrcweir { 1575cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 1576cdf0e10cSrcweir 1577cdf0e10cSrcweir sal_Int32 nLen = mpData->mnLen; 1578cdf0e10cSrcweir xub_StrLen nStrLen = ImplStringLen( pCharStr ); 1579cdf0e10cSrcweir 1580cdf0e10cSrcweir // Falls die Laenge des uebergebenen Strings 0 ist oder der Index 1581cdf0e10cSrcweir // hinter dem String liegt, dann wurde der String nicht gefunden 1582cdf0e10cSrcweir if ( !nStrLen || (nIndex >= nLen) ) 1583cdf0e10cSrcweir return STRING_NOTFOUND; 1584cdf0e10cSrcweir 1585cdf0e10cSrcweir const STRCODE* pStr = mpData->maStr; 1586cdf0e10cSrcweir pStr += nIndex; 1587cdf0e10cSrcweir 1588cdf0e10cSrcweir if ( nStrLen == 1 ) 1589cdf0e10cSrcweir { 1590cdf0e10cSrcweir STRCODE cSearch = *pCharStr; 1591cdf0e10cSrcweir while ( nIndex < nLen ) 1592cdf0e10cSrcweir { 1593cdf0e10cSrcweir if ( *pStr == cSearch ) 1594cdf0e10cSrcweir return nIndex; 1595cdf0e10cSrcweir ++pStr, 1596cdf0e10cSrcweir ++nIndex; 1597cdf0e10cSrcweir } 1598cdf0e10cSrcweir } 1599cdf0e10cSrcweir else 1600cdf0e10cSrcweir { 1601cdf0e10cSrcweir // Nur innerhalb des Strings suchen 1602cdf0e10cSrcweir while ( nLen - nIndex >= nStrLen ) 1603cdf0e10cSrcweir { 1604cdf0e10cSrcweir // Stimmt der String ueberein 1605cdf0e10cSrcweir if ( ImplStringCompareWithoutZero( pStr, pCharStr, nStrLen ) == 0 ) 1606cdf0e10cSrcweir return nIndex; 1607cdf0e10cSrcweir ++pStr, 1608cdf0e10cSrcweir ++nIndex; 1609cdf0e10cSrcweir } 1610cdf0e10cSrcweir } 1611cdf0e10cSrcweir 1612cdf0e10cSrcweir return STRING_NOTFOUND; 1613cdf0e10cSrcweir } 1614cdf0e10cSrcweir 1615cdf0e10cSrcweir // ----------------------------------------------------------------------- 1616cdf0e10cSrcweir 1617cdf0e10cSrcweir xub_StrLen STRING::SearchBackward( STRCODE c, xub_StrLen nIndex ) const 1618cdf0e10cSrcweir { 1619cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 1620cdf0e10cSrcweir 1621cdf0e10cSrcweir if ( nIndex > mpData->mnLen ) 1622cdf0e10cSrcweir nIndex = (xub_StrLen)mpData->mnLen; 1623cdf0e10cSrcweir 1624cdf0e10cSrcweir const STRCODE* pStr = mpData->maStr; 1625cdf0e10cSrcweir pStr += nIndex; 1626cdf0e10cSrcweir 1627cdf0e10cSrcweir while ( nIndex ) 1628cdf0e10cSrcweir { 1629cdf0e10cSrcweir nIndex--; 1630cdf0e10cSrcweir pStr--; 1631cdf0e10cSrcweir if ( *pStr == c ) 1632cdf0e10cSrcweir return nIndex; 1633cdf0e10cSrcweir } 1634cdf0e10cSrcweir 1635cdf0e10cSrcweir return STRING_NOTFOUND; 1636cdf0e10cSrcweir } 1637cdf0e10cSrcweir 1638cdf0e10cSrcweir // ----------------------------------------------------------------------- 1639cdf0e10cSrcweir 1640cdf0e10cSrcweir xub_StrLen STRING::SearchChar( const STRCODE* pChars, xub_StrLen nIndex ) const 1641cdf0e10cSrcweir { 1642cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 1643cdf0e10cSrcweir 1644cdf0e10cSrcweir sal_Int32 nLen = mpData->mnLen; 1645cdf0e10cSrcweir const STRCODE* pStr = mpData->maStr; 1646cdf0e10cSrcweir pStr += nIndex; 1647cdf0e10cSrcweir while ( nIndex < nLen ) 1648cdf0e10cSrcweir { 1649cdf0e10cSrcweir STRCODE c = *pStr; 1650cdf0e10cSrcweir const STRCODE* pCompStr = pChars; 1651cdf0e10cSrcweir while ( *pCompStr ) 1652cdf0e10cSrcweir { 1653cdf0e10cSrcweir if ( *pCompStr == c ) 1654cdf0e10cSrcweir return nIndex; 1655cdf0e10cSrcweir ++pCompStr; 1656cdf0e10cSrcweir } 1657cdf0e10cSrcweir ++pStr, 1658cdf0e10cSrcweir ++nIndex; 1659cdf0e10cSrcweir } 1660cdf0e10cSrcweir 1661cdf0e10cSrcweir return STRING_NOTFOUND; 1662cdf0e10cSrcweir } 1663cdf0e10cSrcweir 1664cdf0e10cSrcweir // ----------------------------------------------------------------------- 1665cdf0e10cSrcweir 1666cdf0e10cSrcweir xub_StrLen STRING::SearchCharBackward( const STRCODE* pChars, xub_StrLen nIndex ) const 1667cdf0e10cSrcweir { 1668cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 1669cdf0e10cSrcweir 1670cdf0e10cSrcweir if ( nIndex > mpData->mnLen ) 1671cdf0e10cSrcweir nIndex = (xub_StrLen)mpData->mnLen; 1672cdf0e10cSrcweir 1673cdf0e10cSrcweir const STRCODE* pStr = mpData->maStr; 1674cdf0e10cSrcweir pStr += nIndex; 1675cdf0e10cSrcweir 1676cdf0e10cSrcweir while ( nIndex ) 1677cdf0e10cSrcweir { 1678cdf0e10cSrcweir nIndex--; 1679cdf0e10cSrcweir pStr--; 1680cdf0e10cSrcweir 1681cdf0e10cSrcweir STRCODE c =*pStr; 1682cdf0e10cSrcweir const STRCODE* pCompStr = pChars; 1683cdf0e10cSrcweir while ( *pCompStr ) 1684cdf0e10cSrcweir { 1685cdf0e10cSrcweir if ( *pCompStr == c ) 1686cdf0e10cSrcweir return nIndex; 1687cdf0e10cSrcweir ++pCompStr; 1688cdf0e10cSrcweir } 1689cdf0e10cSrcweir } 1690cdf0e10cSrcweir 1691cdf0e10cSrcweir return STRING_NOTFOUND; 1692cdf0e10cSrcweir } 1693cdf0e10cSrcweir 1694cdf0e10cSrcweir // ----------------------------------------------------------------------- 1695cdf0e10cSrcweir 1696cdf0e10cSrcweir xub_StrLen STRING::SearchAndReplace( STRCODE c, STRCODE cRep, xub_StrLen nIndex ) 1697cdf0e10cSrcweir { 1698cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 1699cdf0e10cSrcweir 1700cdf0e10cSrcweir sal_Int32 nLen = mpData->mnLen; 1701cdf0e10cSrcweir const STRCODE* pStr = mpData->maStr; 1702cdf0e10cSrcweir pStr += nIndex; 1703cdf0e10cSrcweir while ( nIndex < nLen ) 1704cdf0e10cSrcweir { 1705cdf0e10cSrcweir if ( *pStr == c ) 1706cdf0e10cSrcweir { 1707cdf0e10cSrcweir ImplCopyData(); 1708cdf0e10cSrcweir mpData->maStr[nIndex] = cRep; 1709cdf0e10cSrcweir return nIndex; 1710cdf0e10cSrcweir } 1711cdf0e10cSrcweir ++pStr, 1712cdf0e10cSrcweir ++nIndex; 1713cdf0e10cSrcweir } 1714cdf0e10cSrcweir 1715cdf0e10cSrcweir return STRING_NOTFOUND; 1716cdf0e10cSrcweir } 1717cdf0e10cSrcweir 1718cdf0e10cSrcweir // ----------------------------------------------------------------------- 1719cdf0e10cSrcweir 1720cdf0e10cSrcweir xub_StrLen STRING::SearchAndReplace( const STRING& rStr, const STRING& rRepStr, 1721cdf0e10cSrcweir xub_StrLen nIndex ) 1722cdf0e10cSrcweir { 1723cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 1724cdf0e10cSrcweir DBG_CHKOBJ( &rStr, STRING, DBGCHECKSTRING ); 1725cdf0e10cSrcweir DBG_CHKOBJ( &rRepStr, STRING, DBGCHECKSTRING ); 1726cdf0e10cSrcweir 1727cdf0e10cSrcweir xub_StrLen nSPos = Search( rStr, nIndex ); 1728cdf0e10cSrcweir if ( nSPos != STRING_NOTFOUND ) 1729cdf0e10cSrcweir Replace( nSPos, rStr.Len(), rRepStr ); 1730cdf0e10cSrcweir 1731cdf0e10cSrcweir return nSPos; 1732cdf0e10cSrcweir } 1733cdf0e10cSrcweir 1734cdf0e10cSrcweir // ----------------------------------------------------------------------- 1735cdf0e10cSrcweir 1736cdf0e10cSrcweir xub_StrLen STRING::SearchAndReplace( const STRCODE* pCharStr, const STRING& rRepStr, 1737cdf0e10cSrcweir xub_StrLen nIndex ) 1738cdf0e10cSrcweir { 1739cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 1740cdf0e10cSrcweir DBG_CHKOBJ( &rRepStr, STRING, DBGCHECKSTRING ); 1741cdf0e10cSrcweir 1742cdf0e10cSrcweir xub_StrLen nSPos = Search( pCharStr, nIndex ); 1743cdf0e10cSrcweir if ( nSPos != STRING_NOTFOUND ) 1744cdf0e10cSrcweir Replace( nSPos, ImplStringLen( pCharStr ), rRepStr ); 1745cdf0e10cSrcweir 1746cdf0e10cSrcweir return nSPos; 1747cdf0e10cSrcweir } 1748cdf0e10cSrcweir 1749cdf0e10cSrcweir // ----------------------------------------------------------------------- 1750cdf0e10cSrcweir 1751cdf0e10cSrcweir void STRING::SearchAndReplaceAll( STRCODE c, STRCODE cRep ) 1752cdf0e10cSrcweir { 1753cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 1754cdf0e10cSrcweir 1755cdf0e10cSrcweir sal_Int32 nLen = mpData->mnLen; 1756cdf0e10cSrcweir const STRCODE* pStr = mpData->maStr; 1757cdf0e10cSrcweir sal_Int32 nIndex = 0; 1758cdf0e10cSrcweir while ( nIndex < nLen ) 1759cdf0e10cSrcweir { 1760cdf0e10cSrcweir if ( *pStr == c ) 1761cdf0e10cSrcweir { 1762cdf0e10cSrcweir ImplCopyData(); 1763cdf0e10cSrcweir mpData->maStr[nIndex] = cRep; 1764cdf0e10cSrcweir } 1765cdf0e10cSrcweir ++pStr, 1766cdf0e10cSrcweir ++nIndex; 1767cdf0e10cSrcweir } 1768cdf0e10cSrcweir } 1769cdf0e10cSrcweir 1770cdf0e10cSrcweir // ----------------------------------------------------------------------- 1771cdf0e10cSrcweir 1772cdf0e10cSrcweir void STRING::SearchAndReplaceAll( const STRCODE* pCharStr, const STRING& rRepStr ) 1773cdf0e10cSrcweir { 1774cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 1775cdf0e10cSrcweir DBG_CHKOBJ( &rRepStr, STRING, DBGCHECKSTRING ); 1776cdf0e10cSrcweir 1777cdf0e10cSrcweir xub_StrLen nCharLen = ImplStringLen( pCharStr ); 1778cdf0e10cSrcweir xub_StrLen nSPos = Search( pCharStr, 0 ); 1779cdf0e10cSrcweir while ( nSPos != STRING_NOTFOUND ) 1780cdf0e10cSrcweir { 1781cdf0e10cSrcweir Replace( nSPos, nCharLen, rRepStr ); 1782cdf0e10cSrcweir nSPos = nSPos + rRepStr.Len(); 1783cdf0e10cSrcweir nSPos = Search( pCharStr, nSPos ); 1784cdf0e10cSrcweir } 1785cdf0e10cSrcweir } 1786cdf0e10cSrcweir 1787cdf0e10cSrcweir // ----------------------------------------------------------------------- 1788cdf0e10cSrcweir 1789cdf0e10cSrcweir void STRING::SearchAndReplaceAll( const STRING& rStr, const STRING& rRepStr ) 1790cdf0e10cSrcweir { 1791cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 1792cdf0e10cSrcweir DBG_CHKOBJ( &rStr, STRING, DBGCHECKSTRING ); 1793cdf0e10cSrcweir DBG_CHKOBJ( &rRepStr, STRING, DBGCHECKSTRING ); 1794cdf0e10cSrcweir 1795cdf0e10cSrcweir xub_StrLen nSPos = Search( rStr, 0 ); 1796cdf0e10cSrcweir while ( nSPos != STRING_NOTFOUND ) 1797cdf0e10cSrcweir { 1798cdf0e10cSrcweir Replace( nSPos, rStr.Len(), rRepStr ); 1799cdf0e10cSrcweir nSPos = nSPos + rRepStr.Len(); 1800cdf0e10cSrcweir nSPos = Search( rStr, nSPos ); 1801cdf0e10cSrcweir } 1802cdf0e10cSrcweir } 1803cdf0e10cSrcweir 1804cdf0e10cSrcweir // ----------------------------------------------------------------------- 1805cdf0e10cSrcweir 1806cdf0e10cSrcweir xub_StrLen STRING::GetTokenCount( STRCODE cTok ) const 1807cdf0e10cSrcweir { 1808cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 1809cdf0e10cSrcweir 1810cdf0e10cSrcweir // Leerer String: TokenCount per Definition 0 1811cdf0e10cSrcweir if ( !mpData->mnLen ) 1812cdf0e10cSrcweir return 0; 1813cdf0e10cSrcweir 1814cdf0e10cSrcweir xub_StrLen nTokCount = 1; 1815cdf0e10cSrcweir sal_Int32 nLen = mpData->mnLen; 1816cdf0e10cSrcweir const STRCODE* pStr = mpData->maStr; 1817cdf0e10cSrcweir sal_Int32 nIndex = 0; 1818cdf0e10cSrcweir while ( nIndex < nLen ) 1819cdf0e10cSrcweir { 1820cdf0e10cSrcweir // Stimmt das Tokenzeichen ueberein, dann erhoehe TokCount 1821cdf0e10cSrcweir if ( *pStr == cTok ) 1822cdf0e10cSrcweir ++nTokCount; 1823cdf0e10cSrcweir ++pStr, 1824cdf0e10cSrcweir ++nIndex; 1825cdf0e10cSrcweir } 1826cdf0e10cSrcweir 1827cdf0e10cSrcweir return nTokCount; 1828cdf0e10cSrcweir } 1829cdf0e10cSrcweir 1830cdf0e10cSrcweir // ----------------------------------------------------------------------- 1831cdf0e10cSrcweir 1832cdf0e10cSrcweir void STRING::SetToken( xub_StrLen nToken, STRCODE cTok, const STRING& rStr, 1833cdf0e10cSrcweir xub_StrLen nIndex ) 1834cdf0e10cSrcweir { 1835cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 1836cdf0e10cSrcweir DBG_CHKOBJ( &rStr, STRING, DBGCHECKSTRING ); 1837cdf0e10cSrcweir 1838cdf0e10cSrcweir const STRCODE* pStr = mpData->maStr; 1839cdf0e10cSrcweir xub_StrLen nLen = (xub_StrLen)mpData->mnLen; 1840cdf0e10cSrcweir xub_StrLen nTok = 0; 1841cdf0e10cSrcweir xub_StrLen nFirstChar = nIndex; 1842cdf0e10cSrcweir xub_StrLen i = nFirstChar; 1843cdf0e10cSrcweir 1844cdf0e10cSrcweir // Bestimme die Token-Position und Laenge 1845cdf0e10cSrcweir pStr += i; 1846cdf0e10cSrcweir while ( i < nLen ) 1847cdf0e10cSrcweir { 1848cdf0e10cSrcweir // Stimmt das Tokenzeichen ueberein, dann erhoehe TokCount 1849cdf0e10cSrcweir if ( *pStr == cTok ) 1850cdf0e10cSrcweir { 1851cdf0e10cSrcweir ++nTok; 1852cdf0e10cSrcweir 1853cdf0e10cSrcweir if ( nTok == nToken ) 1854cdf0e10cSrcweir nFirstChar = i+1; 1855cdf0e10cSrcweir else 1856cdf0e10cSrcweir { 1857cdf0e10cSrcweir if ( nTok > nToken ) 1858cdf0e10cSrcweir break; 1859cdf0e10cSrcweir } 1860cdf0e10cSrcweir } 1861cdf0e10cSrcweir 1862cdf0e10cSrcweir ++pStr, 1863cdf0e10cSrcweir ++i; 1864cdf0e10cSrcweir } 1865cdf0e10cSrcweir 1866cdf0e10cSrcweir if ( nTok >= nToken ) 1867cdf0e10cSrcweir Replace( nFirstChar, i-nFirstChar, rStr ); 1868cdf0e10cSrcweir } 1869cdf0e10cSrcweir 1870cdf0e10cSrcweir // ----------------------------------------------------------------------- 1871cdf0e10cSrcweir 1872cdf0e10cSrcweir STRING STRING::GetToken( xub_StrLen nToken, STRCODE cTok, xub_StrLen& rIndex ) const 1873cdf0e10cSrcweir { 1874cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 1875cdf0e10cSrcweir 1876cdf0e10cSrcweir const STRCODE* pStr = mpData->maStr; 1877cdf0e10cSrcweir xub_StrLen nLen = (xub_StrLen)mpData->mnLen; 1878cdf0e10cSrcweir xub_StrLen nTok = 0; 1879cdf0e10cSrcweir xub_StrLen nFirstChar = rIndex; 1880cdf0e10cSrcweir xub_StrLen i = nFirstChar; 1881cdf0e10cSrcweir 1882cdf0e10cSrcweir // Bestimme die Token-Position und Laenge 1883cdf0e10cSrcweir pStr += i; 1884cdf0e10cSrcweir while ( i < nLen ) 1885cdf0e10cSrcweir { 1886cdf0e10cSrcweir // Stimmt das Tokenzeichen ueberein, dann erhoehe TokCount 1887cdf0e10cSrcweir if ( *pStr == cTok ) 1888cdf0e10cSrcweir { 1889cdf0e10cSrcweir ++nTok; 1890cdf0e10cSrcweir 1891cdf0e10cSrcweir if ( nTok == nToken ) 1892cdf0e10cSrcweir nFirstChar = i+1; 1893cdf0e10cSrcweir else 1894cdf0e10cSrcweir { 1895cdf0e10cSrcweir if ( nTok > nToken ) 1896cdf0e10cSrcweir break; 1897cdf0e10cSrcweir } 1898cdf0e10cSrcweir } 1899cdf0e10cSrcweir 1900cdf0e10cSrcweir ++pStr, 1901cdf0e10cSrcweir ++i; 1902cdf0e10cSrcweir } 1903cdf0e10cSrcweir 1904cdf0e10cSrcweir if ( nTok >= nToken ) 1905cdf0e10cSrcweir { 1906cdf0e10cSrcweir if ( i < nLen ) 1907cdf0e10cSrcweir rIndex = i+1; 1908cdf0e10cSrcweir else 1909cdf0e10cSrcweir rIndex = STRING_NOTFOUND; 1910cdf0e10cSrcweir return Copy( nFirstChar, i-nFirstChar ); 1911cdf0e10cSrcweir } 1912cdf0e10cSrcweir else 1913cdf0e10cSrcweir { 1914cdf0e10cSrcweir rIndex = STRING_NOTFOUND; 1915cdf0e10cSrcweir return STRING(); 1916cdf0e10cSrcweir } 1917cdf0e10cSrcweir } 1918cdf0e10cSrcweir 1919cdf0e10cSrcweir // ----------------------------------------------------------------------- 1920cdf0e10cSrcweir 1921cdf0e10cSrcweir xub_StrLen STRING::GetQuotedTokenCount( const STRING& rQuotedPairs, STRCODE cTok ) const 1922cdf0e10cSrcweir { 1923cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 1924cdf0e10cSrcweir DBG_CHKOBJ( &rQuotedPairs, STRING, DBGCHECKSTRING ); 1925cdf0e10cSrcweir DBG_ASSERT( !(rQuotedPairs.Len()%2), "String::GetQuotedTokenCount() - QuotedString%2 != 0" ); 1926cdf0e10cSrcweir DBG_ASSERT( rQuotedPairs.Search(cTok) == STRING_NOTFOUND, "String::GetQuotedTokenCount() - cTok in QuotedString" ); 1927cdf0e10cSrcweir 1928cdf0e10cSrcweir // Leerer String: TokenCount per Definition 0 1929cdf0e10cSrcweir if ( !mpData->mnLen ) 1930cdf0e10cSrcweir return 0; 1931cdf0e10cSrcweir 1932cdf0e10cSrcweir xub_StrLen nTokCount = 1; 1933cdf0e10cSrcweir sal_Int32 nLen = mpData->mnLen; 1934cdf0e10cSrcweir xub_StrLen nQuotedLen = rQuotedPairs.Len(); 1935cdf0e10cSrcweir STRCODE cQuotedEndChar = 0; 1936cdf0e10cSrcweir const STRCODE* pQuotedStr = rQuotedPairs.mpData->maStr; 1937cdf0e10cSrcweir const STRCODE* pStr = mpData->maStr; 1938cdf0e10cSrcweir sal_Int32 nIndex = 0; 1939cdf0e10cSrcweir while ( nIndex < nLen ) 1940cdf0e10cSrcweir { 1941cdf0e10cSrcweir STRCODE c = *pStr; 1942cdf0e10cSrcweir if ( cQuotedEndChar ) 1943cdf0e10cSrcweir { 1944cdf0e10cSrcweir // Ende des Quotes erreicht ? 1945cdf0e10cSrcweir if ( c == cQuotedEndChar ) 1946cdf0e10cSrcweir cQuotedEndChar = 0; 1947cdf0e10cSrcweir } 1948cdf0e10cSrcweir else 1949cdf0e10cSrcweir { 1950cdf0e10cSrcweir // Ist das Zeichen ein Quote-Anfang-Zeichen ? 1951cdf0e10cSrcweir xub_StrLen nQuoteIndex = 0; 1952cdf0e10cSrcweir while ( nQuoteIndex < nQuotedLen ) 1953cdf0e10cSrcweir { 1954cdf0e10cSrcweir if ( pQuotedStr[nQuoteIndex] == c ) 1955cdf0e10cSrcweir { 1956cdf0e10cSrcweir cQuotedEndChar = pQuotedStr[nQuoteIndex+1]; 1957cdf0e10cSrcweir break; 1958cdf0e10cSrcweir } 1959cdf0e10cSrcweir else 1960cdf0e10cSrcweir nQuoteIndex += 2; 1961cdf0e10cSrcweir } 1962cdf0e10cSrcweir 1963cdf0e10cSrcweir // Stimmt das Tokenzeichen ueberein, dann erhoehe TokCount 1964cdf0e10cSrcweir if ( c == cTok ) 1965cdf0e10cSrcweir ++nTokCount; 1966cdf0e10cSrcweir } 1967cdf0e10cSrcweir 1968cdf0e10cSrcweir ++pStr, 1969cdf0e10cSrcweir ++nIndex; 1970cdf0e10cSrcweir } 1971cdf0e10cSrcweir 1972cdf0e10cSrcweir return nTokCount; 1973cdf0e10cSrcweir } 1974cdf0e10cSrcweir 1975cdf0e10cSrcweir // ----------------------------------------------------------------------- 1976cdf0e10cSrcweir 1977cdf0e10cSrcweir STRING STRING::GetQuotedToken( xub_StrLen nToken, const STRING& rQuotedPairs, 1978cdf0e10cSrcweir STRCODE cTok, xub_StrLen& rIndex ) const 1979cdf0e10cSrcweir { 1980cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 1981cdf0e10cSrcweir DBG_CHKOBJ( &rQuotedPairs, STRING, DBGCHECKSTRING ); 1982cdf0e10cSrcweir DBG_ASSERT( !(rQuotedPairs.Len()%2), "String::GetQuotedToken() - QuotedString%2 != 0" ); 1983cdf0e10cSrcweir DBG_ASSERT( rQuotedPairs.Search(cTok) == STRING_NOTFOUND, "String::GetQuotedToken() - cTok in QuotedString" ); 1984cdf0e10cSrcweir 1985cdf0e10cSrcweir const STRCODE* pStr = mpData->maStr; 1986cdf0e10cSrcweir const STRCODE* pQuotedStr = rQuotedPairs.mpData->maStr; 1987cdf0e10cSrcweir STRCODE cQuotedEndChar = 0; 1988cdf0e10cSrcweir xub_StrLen nQuotedLen = rQuotedPairs.Len(); 1989cdf0e10cSrcweir xub_StrLen nLen = (xub_StrLen)mpData->mnLen; 1990cdf0e10cSrcweir xub_StrLen nTok = 0; 1991cdf0e10cSrcweir xub_StrLen nFirstChar = rIndex; 1992cdf0e10cSrcweir xub_StrLen i = nFirstChar; 1993cdf0e10cSrcweir 1994cdf0e10cSrcweir // Bestimme die Token-Position und Laenge 1995cdf0e10cSrcweir pStr += i; 1996cdf0e10cSrcweir while ( i < nLen ) 1997cdf0e10cSrcweir { 1998cdf0e10cSrcweir STRCODE c = *pStr; 1999cdf0e10cSrcweir if ( cQuotedEndChar ) 2000cdf0e10cSrcweir { 2001cdf0e10cSrcweir // Ende des Quotes erreicht ? 2002cdf0e10cSrcweir if ( c == cQuotedEndChar ) 2003cdf0e10cSrcweir cQuotedEndChar = 0; 2004cdf0e10cSrcweir } 2005cdf0e10cSrcweir else 2006cdf0e10cSrcweir { 2007cdf0e10cSrcweir // Ist das Zeichen ein Quote-Anfang-Zeichen ? 2008cdf0e10cSrcweir xub_StrLen nQuoteIndex = 0; 2009cdf0e10cSrcweir while ( nQuoteIndex < nQuotedLen ) 2010cdf0e10cSrcweir { 2011cdf0e10cSrcweir if ( pQuotedStr[nQuoteIndex] == c ) 2012cdf0e10cSrcweir { 2013cdf0e10cSrcweir cQuotedEndChar = pQuotedStr[nQuoteIndex+1]; 2014cdf0e10cSrcweir break; 2015cdf0e10cSrcweir } 2016cdf0e10cSrcweir else 2017cdf0e10cSrcweir nQuoteIndex += 2; 2018cdf0e10cSrcweir } 2019cdf0e10cSrcweir 2020cdf0e10cSrcweir // Stimmt das Tokenzeichen ueberein, dann erhoehe TokCount 2021cdf0e10cSrcweir if ( c == cTok ) 2022cdf0e10cSrcweir { 2023cdf0e10cSrcweir ++nTok; 2024cdf0e10cSrcweir 2025cdf0e10cSrcweir if ( nTok == nToken ) 2026cdf0e10cSrcweir nFirstChar = i+1; 2027cdf0e10cSrcweir else 2028cdf0e10cSrcweir { 2029cdf0e10cSrcweir if ( nTok > nToken ) 2030cdf0e10cSrcweir break; 2031cdf0e10cSrcweir } 2032cdf0e10cSrcweir } 2033cdf0e10cSrcweir } 2034cdf0e10cSrcweir 2035cdf0e10cSrcweir ++pStr, 2036cdf0e10cSrcweir ++i; 2037cdf0e10cSrcweir } 2038cdf0e10cSrcweir 2039cdf0e10cSrcweir if ( nTok >= nToken ) 2040cdf0e10cSrcweir { 2041cdf0e10cSrcweir if ( i < nLen ) 2042cdf0e10cSrcweir rIndex = i+1; 2043cdf0e10cSrcweir else 2044cdf0e10cSrcweir rIndex = STRING_NOTFOUND; 2045cdf0e10cSrcweir return Copy( nFirstChar, i-nFirstChar ); 2046cdf0e10cSrcweir } 2047cdf0e10cSrcweir else 2048cdf0e10cSrcweir { 2049cdf0e10cSrcweir rIndex = STRING_NOTFOUND; 2050cdf0e10cSrcweir return STRING(); 2051cdf0e10cSrcweir } 2052cdf0e10cSrcweir } 2053cdf0e10cSrcweir 2054cdf0e10cSrcweir // ----------------------------------------------------------------------- 2055cdf0e10cSrcweir 2056cdf0e10cSrcweir STRCODE* STRING::GetBufferAccess() 2057cdf0e10cSrcweir { 2058cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 2059cdf0e10cSrcweir 2060cdf0e10cSrcweir // Daten kopieren, wenn noetig 2061cdf0e10cSrcweir if ( mpData->mnLen ) 2062cdf0e10cSrcweir ImplCopyData(); 2063cdf0e10cSrcweir 2064cdf0e10cSrcweir // Pointer auf den String zurueckgeben 2065cdf0e10cSrcweir return mpData->maStr; 2066cdf0e10cSrcweir } 2067cdf0e10cSrcweir 2068cdf0e10cSrcweir // ----------------------------------------------------------------------- 2069cdf0e10cSrcweir 2070cdf0e10cSrcweir void STRING::ReleaseBufferAccess( xub_StrLen nLen ) 2071cdf0e10cSrcweir { 2072cdf0e10cSrcweir // Hier ohne Funktionstest, da String nicht konsistent 2073cdf0e10cSrcweir DBG_CHKTHIS( STRING, NULL ); 2074cdf0e10cSrcweir DBG_ASSERT( mpData->mnRefCount == 1, "String::ReleaseCharStr() called for String with RefCount" ); 2075cdf0e10cSrcweir 2076cdf0e10cSrcweir if ( nLen > mpData->mnLen ) 2077cdf0e10cSrcweir nLen = ImplStringLen( mpData->maStr ); 2078cdf0e10cSrcweir OSL_ASSERT(nLen <= mpData->mnLen); 2079cdf0e10cSrcweir if ( !nLen ) 2080cdf0e10cSrcweir { 2081cdf0e10cSrcweir STRING_NEW((STRING_TYPE **)&mpData); 2082cdf0e10cSrcweir } 2083cdf0e10cSrcweir // Bei mehr als 8 Zeichen unterschied, kuerzen wir den Buffer 2084cdf0e10cSrcweir else if ( mpData->mnLen - nLen > 8 ) 2085cdf0e10cSrcweir { 2086cdf0e10cSrcweir STRINGDATA* pNewData = ImplAllocData( nLen ); 2087cdf0e10cSrcweir memcpy( pNewData->maStr, mpData->maStr, nLen*sizeof( STRCODE ) ); 2088cdf0e10cSrcweir STRING_RELEASE((STRING_TYPE *)mpData); 2089cdf0e10cSrcweir mpData = pNewData; 2090cdf0e10cSrcweir } 2091cdf0e10cSrcweir else 2092cdf0e10cSrcweir mpData->mnLen = nLen; 2093cdf0e10cSrcweir } 2094cdf0e10cSrcweir 2095cdf0e10cSrcweir // ----------------------------------------------------------------------- 2096cdf0e10cSrcweir 2097cdf0e10cSrcweir STRCODE* STRING::AllocBuffer( xub_StrLen nLen ) 2098cdf0e10cSrcweir { 2099cdf0e10cSrcweir DBG_CHKTHIS( STRING, DBGCHECKSTRING ); 2100cdf0e10cSrcweir 2101cdf0e10cSrcweir STRING_RELEASE((STRING_TYPE *)mpData); 2102cdf0e10cSrcweir if ( nLen ) 2103cdf0e10cSrcweir mpData = ImplAllocData( nLen ); 2104cdf0e10cSrcweir else 2105cdf0e10cSrcweir { 2106cdf0e10cSrcweir mpData = NULL; 2107cdf0e10cSrcweir STRING_NEW((STRING_TYPE **)&mpData); 2108cdf0e10cSrcweir } 2109cdf0e10cSrcweir 2110cdf0e10cSrcweir return mpData->maStr; 2111cdf0e10cSrcweir } 2112