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