1*40df464eSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*40df464eSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*40df464eSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*40df464eSAndrew Rist * distributed with this work for additional information 6*40df464eSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*40df464eSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*40df464eSAndrew Rist * "License"); you may not use this file except in compliance 9*40df464eSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*40df464eSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*40df464eSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*40df464eSAndrew Rist * software distributed under the License is distributed on an 15*40df464eSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*40df464eSAndrew Rist * KIND, either express or implied. See the License for the 17*40df464eSAndrew Rist * specific language governing permissions and limitations 18*40df464eSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*40df464eSAndrew Rist *************************************************************/ 21*40df464eSAndrew Rist 22*40df464eSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_svl.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #define _SVARRAY_CXX 28cdf0e10cSrcweir 29cdf0e10cSrcweir #define _SVSTDARR_BOOLS 30cdf0e10cSrcweir #define _SVSTDARR_BYTES 31cdf0e10cSrcweir #define _SVSTDARR_ULONGS 32cdf0e10cSrcweir #define _SVSTDARR_ULONGSSORT 33cdf0e10cSrcweir #define _SVSTDARR_USHORTS 34cdf0e10cSrcweir #define _SVSTDARR_LONGS 35cdf0e10cSrcweir #define _SVSTDARR_LONGSSORT 36cdf0e10cSrcweir #define _SVSTDARR_SHORTS 37cdf0e10cSrcweir #define _SVSTDARR_STRINGS 38cdf0e10cSrcweir #define _SVSTDARR_STRINGSDTOR 39cdf0e10cSrcweir #define _SVSTDARR_STRINGSSORT 40cdf0e10cSrcweir #define _SVSTDARR_STRINGSSORTDTOR 41cdf0e10cSrcweir #define _SVSTDARR_STRINGSISORT 42cdf0e10cSrcweir #define _SVSTDARR_STRINGSISORTDTOR 43cdf0e10cSrcweir #define _SVSTDARR_USHORTSSORT 44cdf0e10cSrcweir 45cdf0e10cSrcweir #define _SVSTDARR_BYTESTRINGS 46cdf0e10cSrcweir #define _SVSTDARR_BYTESTRINGSDTOR 47cdf0e10cSrcweir #define _SVSTDARR_BYTESTRINGSSORT 48cdf0e10cSrcweir #define _SVSTDARR_BYTESTRINGSSORTDTOR 49cdf0e10cSrcweir #define _SVSTDARR_BYTESTRINGSISORT 50cdf0e10cSrcweir #define _SVSTDARR_BYTESTRINGSISORTDTOR 51cdf0e10cSrcweir 52cdf0e10cSrcweir #define _SVSTDARR_XUB_STRLEN 53cdf0e10cSrcweir #define _SVSTDARR_XUB_STRLENSORT 54cdf0e10cSrcweir 55cdf0e10cSrcweir #include <svl/svstdarr.hxx> 56cdf0e10cSrcweir #include <tools/string.hxx> 57cdf0e10cSrcweir #include <tools/debug.hxx> 58cdf0e10cSrcweir 59cdf0e10cSrcweir SV_IMPL_VARARR(SvPtrarr,VoidPtr) 60cdf0e10cSrcweir 61cdf0e10cSrcweir sal_uInt16 SvPtrarr::GetPos( const VoidPtr& aElement ) const 62cdf0e10cSrcweir { sal_uInt16 n; 63cdf0e10cSrcweir for( n=0; n < nA && *(GetData()+n) != aElement; ) n++; 64cdf0e10cSrcweir return ( n >= nA ? USHRT_MAX : n ); 65cdf0e10cSrcweir } 66cdf0e10cSrcweir 67cdf0e10cSrcweir SV_IMPL_VARARR( SvULongs, sal_uLong ) 68cdf0e10cSrcweir SV_IMPL_VARARR( SvUShorts, sal_uInt16 ) 69cdf0e10cSrcweir SV_IMPL_VARARR( SvLongs, long) 70cdf0e10cSrcweir 71cdf0e10cSrcweir SV_IMPL_VARARR_SORT( SvULongsSort, sal_uLong ) 72cdf0e10cSrcweir SV_IMPL_VARARR_SORT( SvLongsSort, long ) 73cdf0e10cSrcweir 74cdf0e10cSrcweir SV_IMPL_PTRARR( SvStrings, StringPtr ) 75cdf0e10cSrcweir SV_IMPL_PTRARR( SvStringsDtor, StringPtr ) 76cdf0e10cSrcweir SV_IMPL_OP_PTRARR_SORT( SvStringsSort, StringPtr ) 77cdf0e10cSrcweir SV_IMPL_OP_PTRARR_SORT( SvStringsSortDtor, StringPtr ) 78cdf0e10cSrcweir 79cdf0e10cSrcweir SV_IMPL_PTRARR( SvByteStrings, ByteStringPtr ) 80cdf0e10cSrcweir SV_IMPL_PTRARR( SvByteStringsDtor, ByteStringPtr ) 81cdf0e10cSrcweir SV_IMPL_OP_PTRARR_SORT( SvByteStringsSort, ByteStringPtr ) 82cdf0e10cSrcweir SV_IMPL_OP_PTRARR_SORT( SvByteStringsSortDtor, ByteStringPtr ) 83cdf0e10cSrcweir 84cdf0e10cSrcweir 85cdf0e10cSrcweir 86cdf0e10cSrcweir // ---------------- strings ------------------------------------- 87cdf0e10cSrcweir 88cdf0e10cSrcweir // Array mit anderer Seek-Methode! 89cdf0e10cSrcweir _SV_IMPL_SORTAR_ALG( SvStringsISort, StringPtr ) 90cdf0e10cSrcweir void SvStringsISort::DeleteAndDestroy( sal_uInt16 nP, sal_uInt16 nL ) 91cdf0e10cSrcweir { 92cdf0e10cSrcweir if( nL ) 93cdf0e10cSrcweir { 94cdf0e10cSrcweir DBG_ASSERT( nP < nA && nP + nL <= nA, "ERR_VAR_DEL" ); 95cdf0e10cSrcweir for( sal_uInt16 n=nP; n < nP + nL; n++ ) 96cdf0e10cSrcweir delete *((StringPtr*)pData+n); 97cdf0e10cSrcweir SvPtrarr::Remove( nP, nL ); 98cdf0e10cSrcweir } 99cdf0e10cSrcweir } 100cdf0e10cSrcweir sal_Bool SvStringsISort::Seek_Entry( const StringPtr aE, sal_uInt16* pP ) const 101cdf0e10cSrcweir { 102cdf0e10cSrcweir register sal_uInt16 nO = SvStringsISort_SAR::Count(), 103cdf0e10cSrcweir nM, 104cdf0e10cSrcweir nU = 0; 105cdf0e10cSrcweir if( nO > 0 ) 106cdf0e10cSrcweir { 107cdf0e10cSrcweir nO--; 108cdf0e10cSrcweir while( nU <= nO ) 109cdf0e10cSrcweir { 110cdf0e10cSrcweir nM = nU + ( nO - nU ) / 2; 111cdf0e10cSrcweir StringCompare eCmp = (*((StringPtr*)pData + nM))-> 112cdf0e10cSrcweir CompareIgnoreCaseToAscii( *(aE) ); 113cdf0e10cSrcweir if( COMPARE_EQUAL == eCmp ) 114cdf0e10cSrcweir { 115cdf0e10cSrcweir if( pP ) *pP = nM; 116cdf0e10cSrcweir return sal_True; 117cdf0e10cSrcweir } 118cdf0e10cSrcweir else if( COMPARE_LESS == eCmp ) 119cdf0e10cSrcweir nU = nM + 1; 120cdf0e10cSrcweir else if( nM == 0 ) 121cdf0e10cSrcweir { 122cdf0e10cSrcweir if( pP ) *pP = nU; 123cdf0e10cSrcweir return sal_False; 124cdf0e10cSrcweir } 125cdf0e10cSrcweir else 126cdf0e10cSrcweir nO = nM - 1; 127cdf0e10cSrcweir } 128cdf0e10cSrcweir } 129cdf0e10cSrcweir if( pP ) *pP = nU; 130cdf0e10cSrcweir return sal_False; 131cdf0e10cSrcweir } 132cdf0e10cSrcweir 133cdf0e10cSrcweir // ---------------- strings ------------------------------------- 134cdf0e10cSrcweir 135cdf0e10cSrcweir // Array mit anderer Seek-Methode! 136cdf0e10cSrcweir _SV_IMPL_SORTAR_ALG( SvStringsISortDtor, StringPtr ) 137cdf0e10cSrcweir void SvStringsISortDtor::DeleteAndDestroy( sal_uInt16 nP, sal_uInt16 nL ) 138cdf0e10cSrcweir { 139cdf0e10cSrcweir if( nL ) 140cdf0e10cSrcweir { 141cdf0e10cSrcweir DBG_ASSERT( nP < nA && nP + nL <= nA, "ERR_VAR_DEL" ); 142cdf0e10cSrcweir for( sal_uInt16 n=nP; n < nP + nL; n++ ) 143cdf0e10cSrcweir delete *((StringPtr*)pData+n); 144cdf0e10cSrcweir SvPtrarr::Remove( nP, nL ); 145cdf0e10cSrcweir } 146cdf0e10cSrcweir } 147cdf0e10cSrcweir sal_Bool SvStringsISortDtor::Seek_Entry( const StringPtr aE, sal_uInt16* pP ) const 148cdf0e10cSrcweir { 149cdf0e10cSrcweir register sal_uInt16 nO = SvStringsISortDtor_SAR::Count(), 150cdf0e10cSrcweir nM, 151cdf0e10cSrcweir nU = 0; 152cdf0e10cSrcweir if( nO > 0 ) 153cdf0e10cSrcweir { 154cdf0e10cSrcweir nO--; 155cdf0e10cSrcweir while( nU <= nO ) 156cdf0e10cSrcweir { 157cdf0e10cSrcweir nM = nU + ( nO - nU ) / 2; 158cdf0e10cSrcweir StringCompare eCmp = (*((StringPtr*)pData + nM))-> 159cdf0e10cSrcweir CompareIgnoreCaseToAscii( *(aE) ); 160cdf0e10cSrcweir if( COMPARE_EQUAL == eCmp ) 161cdf0e10cSrcweir { 162cdf0e10cSrcweir if( pP ) *pP = nM; 163cdf0e10cSrcweir return sal_True; 164cdf0e10cSrcweir } 165cdf0e10cSrcweir else if( COMPARE_LESS == eCmp ) 166cdf0e10cSrcweir nU = nM + 1; 167cdf0e10cSrcweir else if( nM == 0 ) 168cdf0e10cSrcweir { 169cdf0e10cSrcweir if( pP ) *pP = nU; 170cdf0e10cSrcweir return sal_False; 171cdf0e10cSrcweir } 172cdf0e10cSrcweir else 173cdf0e10cSrcweir nO = nM - 1; 174cdf0e10cSrcweir } 175cdf0e10cSrcweir } 176cdf0e10cSrcweir if( pP ) *pP = nU; 177cdf0e10cSrcweir return sal_False; 178cdf0e10cSrcweir } 179cdf0e10cSrcweir 180cdf0e10cSrcweir // ---------------- Ushorts ------------------------------------- 181cdf0e10cSrcweir 182cdf0e10cSrcweir /* SortArray fuer UShorts */ 183cdf0e10cSrcweir sal_Bool SvUShortsSort::Seek_Entry( const sal_uInt16 aE, sal_uInt16* pP ) const 184cdf0e10cSrcweir { 185cdf0e10cSrcweir register sal_uInt16 nO = SvUShorts::Count(), 186cdf0e10cSrcweir nM, 187cdf0e10cSrcweir nU = 0; 188cdf0e10cSrcweir if( nO > 0 ) 189cdf0e10cSrcweir { 190cdf0e10cSrcweir nO--; 191cdf0e10cSrcweir while( nU <= nO ) 192cdf0e10cSrcweir { 193cdf0e10cSrcweir nM = nU + ( nO - nU ) / 2; 194cdf0e10cSrcweir if( *(pData + nM) == aE ) 195cdf0e10cSrcweir { 196cdf0e10cSrcweir if( pP ) *pP = nM; 197cdf0e10cSrcweir return sal_True; 198cdf0e10cSrcweir } 199cdf0e10cSrcweir else if( *(pData + nM) < aE ) 200cdf0e10cSrcweir nU = nM + 1; 201cdf0e10cSrcweir else if( nM == 0 ) 202cdf0e10cSrcweir { 203cdf0e10cSrcweir if( pP ) *pP = nU; 204cdf0e10cSrcweir return sal_False; 205cdf0e10cSrcweir } 206cdf0e10cSrcweir else 207cdf0e10cSrcweir nO = nM - 1; 208cdf0e10cSrcweir } 209cdf0e10cSrcweir } 210cdf0e10cSrcweir if( pP ) *pP = nU; 211cdf0e10cSrcweir return sal_False; 212cdf0e10cSrcweir } 213cdf0e10cSrcweir 214cdf0e10cSrcweir void SvUShortsSort::Insert( const SvUShortsSort * pI, sal_uInt16 nS, sal_uInt16 nE ) 215cdf0e10cSrcweir { 216cdf0e10cSrcweir if( USHRT_MAX == nE ) 217cdf0e10cSrcweir nE = pI->Count(); 218cdf0e10cSrcweir sal_uInt16 nP; 219cdf0e10cSrcweir const sal_uInt16 * pIArr = pI->GetData(); 220cdf0e10cSrcweir for( ; nS < nE; ++nS ) 221cdf0e10cSrcweir { 222cdf0e10cSrcweir if( ! Seek_Entry( *(pIArr+nS), &nP) ) 223cdf0e10cSrcweir SvUShorts::Insert( *(pIArr+nS), nP ); 224cdf0e10cSrcweir if( ++nP >= Count() ) 225cdf0e10cSrcweir { 226cdf0e10cSrcweir SvUShorts::Insert( pI, nP, nS+1, nE ); 227cdf0e10cSrcweir nS = nE; 228cdf0e10cSrcweir } 229cdf0e10cSrcweir } 230cdf0e10cSrcweir } 231cdf0e10cSrcweir 232cdf0e10cSrcweir sal_Bool SvUShortsSort::Insert( const sal_uInt16 aE ) 233cdf0e10cSrcweir { 234cdf0e10cSrcweir sal_uInt16 nP; 235cdf0e10cSrcweir sal_Bool bExist = Seek_Entry( aE, &nP ); 236cdf0e10cSrcweir if( !bExist ) 237cdf0e10cSrcweir SvUShorts::Insert( aE, nP ); 238cdf0e10cSrcweir return !bExist; 239cdf0e10cSrcweir } 240cdf0e10cSrcweir 241cdf0e10cSrcweir sal_Bool SvUShortsSort::Insert( const sal_uInt16 aE, sal_uInt16& rP ) 242cdf0e10cSrcweir { 243cdf0e10cSrcweir sal_Bool bExist = Seek_Entry( aE, &rP ); 244cdf0e10cSrcweir if( !bExist ) 245cdf0e10cSrcweir SvUShorts::Insert( aE, rP ); 246cdf0e10cSrcweir return !bExist; 247cdf0e10cSrcweir } 248cdf0e10cSrcweir 249cdf0e10cSrcweir void SvUShortsSort::Insert( const sal_uInt16* pE, sal_uInt16 nL) 250cdf0e10cSrcweir { 251cdf0e10cSrcweir sal_uInt16 nP; 252cdf0e10cSrcweir for( sal_uInt16 n = 0; n < nL; ++n ) 253cdf0e10cSrcweir if( ! Seek_Entry( *(pE+n), &nP )) 254cdf0e10cSrcweir SvUShorts::Insert( *(pE+n), nP ); 255cdf0e10cSrcweir } 256cdf0e10cSrcweir 257cdf0e10cSrcweir // remove ab Pos 258cdf0e10cSrcweir void SvUShortsSort::RemoveAt( const sal_uInt16 nP, sal_uInt16 nL ) 259cdf0e10cSrcweir { 260cdf0e10cSrcweir if( nL ) 261cdf0e10cSrcweir SvUShorts::Remove( nP, nL); 262cdf0e10cSrcweir } 263cdf0e10cSrcweir 264cdf0e10cSrcweir // remove ab dem Eintrag 265cdf0e10cSrcweir void SvUShortsSort::Remove( const sal_uInt16 aE, sal_uInt16 nL ) 266cdf0e10cSrcweir { 267cdf0e10cSrcweir sal_uInt16 nP; 268cdf0e10cSrcweir if( nL && Seek_Entry( aE, &nP ) ) 269cdf0e10cSrcweir SvUShorts::Remove( nP, nL); 270cdf0e10cSrcweir } 271cdf0e10cSrcweir 272cdf0e10cSrcweir // ---------------- bytestrings ------------------------------------- 273cdf0e10cSrcweir 274cdf0e10cSrcweir // Array mit anderer Seek-Methode! 275cdf0e10cSrcweir _SV_IMPL_SORTAR_ALG( SvByteStringsISort, ByteStringPtr ) 276cdf0e10cSrcweir void SvByteStringsISort::DeleteAndDestroy( sal_uInt16 nP, sal_uInt16 nL ) 277cdf0e10cSrcweir { 278cdf0e10cSrcweir if( nL ) 279cdf0e10cSrcweir { 280cdf0e10cSrcweir DBG_ASSERT( nP < nA && nP + nL <= nA, "ERR_VAR_DEL" ); 281cdf0e10cSrcweir for( sal_uInt16 n=nP; n < nP + nL; n++ ) 282cdf0e10cSrcweir delete *((ByteStringPtr*)pData+n); 283cdf0e10cSrcweir SvPtrarr::Remove( nP, nL ); 284cdf0e10cSrcweir } 285cdf0e10cSrcweir } 286cdf0e10cSrcweir sal_Bool SvByteStringsISort::Seek_Entry( const ByteStringPtr aE, sal_uInt16* pP ) const 287cdf0e10cSrcweir { 288cdf0e10cSrcweir register sal_uInt16 nO = SvByteStringsISort_SAR::Count(), 289cdf0e10cSrcweir nM, 290cdf0e10cSrcweir nU = 0; 291cdf0e10cSrcweir if( nO > 0 ) 292cdf0e10cSrcweir { 293cdf0e10cSrcweir nO--; 294cdf0e10cSrcweir while( nU <= nO ) 295cdf0e10cSrcweir { 296cdf0e10cSrcweir nM = nU + ( nO - nU ) / 2; 297cdf0e10cSrcweir StringCompare eCmp = (*((ByteStringPtr*)pData + nM))-> 298cdf0e10cSrcweir CompareIgnoreCaseToAscii( *(aE) ); 299cdf0e10cSrcweir if( COMPARE_EQUAL == eCmp ) 300cdf0e10cSrcweir { 301cdf0e10cSrcweir if( pP ) *pP = nM; 302cdf0e10cSrcweir return sal_True; 303cdf0e10cSrcweir } 304cdf0e10cSrcweir else if( COMPARE_LESS == eCmp ) 305cdf0e10cSrcweir nU = nM + 1; 306cdf0e10cSrcweir else if( nM == 0 ) 307cdf0e10cSrcweir { 308cdf0e10cSrcweir if( pP ) *pP = nU; 309cdf0e10cSrcweir return sal_False; 310cdf0e10cSrcweir } 311cdf0e10cSrcweir else 312cdf0e10cSrcweir nO = nM - 1; 313cdf0e10cSrcweir } 314cdf0e10cSrcweir } 315cdf0e10cSrcweir if( pP ) *pP = nU; 316cdf0e10cSrcweir return sal_False; 317cdf0e10cSrcweir } 318cdf0e10cSrcweir 319cdf0e10cSrcweir 320cdf0e10cSrcweir // Array mit anderer Seek-Methode! 321cdf0e10cSrcweir _SV_IMPL_SORTAR_ALG( SvByteStringsISortDtor, ByteStringPtr ) 322cdf0e10cSrcweir void SvByteStringsISortDtor::DeleteAndDestroy( sal_uInt16 nP, sal_uInt16 nL ) 323cdf0e10cSrcweir { 324cdf0e10cSrcweir if( nL ) 325cdf0e10cSrcweir { 326cdf0e10cSrcweir DBG_ASSERT( nP < nA && nP + nL <= nA, "ERR_VAR_DEL" ); 327cdf0e10cSrcweir for( sal_uInt16 n=nP; n < nP + nL; n++ ) 328cdf0e10cSrcweir delete *((ByteStringPtr*)pData+n); 329cdf0e10cSrcweir SvPtrarr::Remove( nP, nL ); 330cdf0e10cSrcweir } 331cdf0e10cSrcweir } 332cdf0e10cSrcweir sal_Bool SvByteStringsISortDtor::Seek_Entry( const ByteStringPtr aE, sal_uInt16* pP ) const 333cdf0e10cSrcweir { 334cdf0e10cSrcweir register sal_uInt16 nO = SvByteStringsISortDtor_SAR::Count(), 335cdf0e10cSrcweir nM, 336cdf0e10cSrcweir nU = 0; 337cdf0e10cSrcweir if( nO > 0 ) 338cdf0e10cSrcweir { 339cdf0e10cSrcweir nO--; 340cdf0e10cSrcweir while( nU <= nO ) 341cdf0e10cSrcweir { 342cdf0e10cSrcweir nM = nU + ( nO - nU ) / 2; 343cdf0e10cSrcweir StringCompare eCmp = (*((ByteStringPtr*)pData + nM))-> 344cdf0e10cSrcweir CompareIgnoreCaseToAscii( *(aE) ); 345cdf0e10cSrcweir if( COMPARE_EQUAL == eCmp ) 346cdf0e10cSrcweir { 347cdf0e10cSrcweir if( pP ) *pP = nM; 348cdf0e10cSrcweir return sal_True; 349cdf0e10cSrcweir } 350cdf0e10cSrcweir else if( COMPARE_LESS == eCmp ) 351cdf0e10cSrcweir nU = nM + 1; 352cdf0e10cSrcweir else if( nM == 0 ) 353cdf0e10cSrcweir { 354cdf0e10cSrcweir if( pP ) *pP = nU; 355cdf0e10cSrcweir return sal_False; 356cdf0e10cSrcweir } 357cdf0e10cSrcweir else 358cdf0e10cSrcweir nO = nM - 1; 359cdf0e10cSrcweir } 360cdf0e10cSrcweir } 361cdf0e10cSrcweir if( pP ) *pP = nU; 362cdf0e10cSrcweir return sal_False; 363cdf0e10cSrcweir } 364cdf0e10cSrcweir 365