1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef _TOOLS_STRINGLIST 25 # define _TOOLS_STRINGLIST 26 #endif 27 28 #define ENABLE_BYTESTRING_STREAM_OPERATORS 29 #include <tools/stream.hxx> 30 #include "soldep/sstring.hxx" 31 32 SByteStringList::SByteStringList() 33 { 34 } 35 36 SByteStringList::~SByteStringList() 37 { 38 } 39 40 sal_uIntPtr SByteStringList::IsString( ByteString* pStr ) 41 { 42 sal_uIntPtr nRet = NOT_THERE; 43 if ( (nRet = GetPrevString( pStr )) != 0 ) 44 { 45 ByteString* pString = GetObject( nRet ); 46 if ( *pString == *pStr ) 47 return nRet; 48 else 49 return NOT_THERE; 50 } 51 else 52 { 53 ByteString* pString = GetObject( 0 ); 54 if ( pString && (*pString == *pStr) ) 55 return 0; 56 else 57 return NOT_THERE; 58 } 59 } 60 61 sal_uIntPtr SByteStringList::GetPrevString( ByteString* pStr ) 62 { 63 sal_uIntPtr nRet = 0; 64 sal_Bool bFound = sal_False; 65 sal_uIntPtr nCountMember = Count(); 66 sal_uIntPtr nUpper = nCountMember; 67 sal_uIntPtr nLower = 0; 68 sal_uIntPtr nCurrent = nUpper / 2; 69 sal_uIntPtr nRem = 0; 70 ByteString* pString; 71 72 do 73 { 74 if ( (nCurrent == nLower) || (nCurrent == nUpper) ) 75 return nLower; 76 pString = GetObject( nCurrent ); 77 StringCompare nResult = pStr->CompareTo( *pString ); 78 if ( nResult == COMPARE_LESS ) 79 { 80 nUpper = nCurrent; 81 nCurrent = (nCurrent + nLower) /2; 82 } 83 else if ( nResult == COMPARE_GREATER ) 84 { 85 nLower = nCurrent; 86 nCurrent = (nUpper + nCurrent) /2; 87 } 88 else if ( nResult == COMPARE_EQUAL ) 89 return nCurrent; 90 if ( nRem == nCurrent ) 91 return nCurrent; 92 nRem = nCurrent; 93 } 94 while ( !bFound ); 95 return nRet; 96 } 97 98 /************************************************************************** 99 * 100 * Sortiert einen ByteString in die Liste ein und gibt die Position, 101 * an der einsortiert wurde, zurueck 102 * 103 **************************************************************************/ 104 105 sal_uIntPtr SByteStringList::PutString( ByteString* pStr ) 106 { 107 sal_uIntPtr nPos = GetPrevString ( pStr ); 108 if ( Count() ) 109 { 110 { 111 ByteString* pString = GetObject( 0 ); 112 if ( pString->CompareTo( *pStr ) == COMPARE_GREATER ) 113 { 114 Insert( pStr, (sal_uIntPtr)0 ); 115 return (sal_uIntPtr)0; 116 } 117 } 118 ByteString* pString = GetObject( nPos ); 119 if ( *pStr != *pString ) 120 { 121 Insert( pStr, nPos+1 ); 122 return ( nPos +1 ); 123 } 124 } 125 else 126 { 127 Insert( pStr ); 128 return (sal_uIntPtr)0; 129 } 130 131 return NOT_THERE; 132 } 133 134 ByteString* SByteStringList::RemoveString( const ByteString& rName ) 135 { 136 sal_uIntPtr i; 137 ByteString* pReturn; 138 139 for( i = 0 ; i < Count(); i++ ) 140 { 141 if ( rName == *GetObject( i ) ) 142 { 143 pReturn = GetObject(i); 144 Remove(i); 145 return pReturn; 146 } 147 } 148 149 return NULL; 150 } 151 152 void SByteStringList::CleanUp() 153 { 154 ByteString* pByteString = First(); 155 while (pByteString) { 156 delete pByteString; 157 pByteString = Next(); 158 } 159 Clear(); 160 } 161 162 SByteStringList& SByteStringList::operator<< ( SvStream& rStream ) 163 { 164 sal_uInt32 nListCount; 165 rStream >> nListCount; 166 for ( sal_uInt16 i = 0; i < nListCount; i++ ) { 167 ByteString* pByteString = new ByteString(); 168 rStream >> *pByteString; 169 Insert (pByteString, LIST_APPEND); 170 } 171 return *this; 172 } 173 174 SByteStringList& SByteStringList::operator>> ( SvStream& rStream ) 175 { 176 sal_uInt32 nListCount = Count(); 177 rStream << nListCount; 178 ByteString* pByteString = First(); 179 while (pByteString) { 180 rStream << *pByteString; 181 pByteString = Next(); 182 } 183 return *this; 184 } 185 186 187 188 189 190 191 192 SUniStringList::SUniStringList() 193 { 194 } 195 196 SUniStringList::~SUniStringList() 197 { 198 } 199 200 sal_uIntPtr SUniStringList::IsString( UniString* pStr ) 201 { 202 sal_uIntPtr nRet = NOT_THERE; 203 if ( (nRet = GetPrevString( pStr )) != 0 ) 204 { 205 UniString* pString = GetObject( nRet ); 206 if ( *pString == *pStr ) 207 return nRet; 208 else 209 return NOT_THERE; 210 } 211 else 212 { 213 UniString* pString = GetObject( 0 ); 214 if ( pString && (*pString == *pStr) ) 215 return 0; 216 else 217 return NOT_THERE; 218 } 219 } 220 221 sal_uIntPtr SUniStringList::GetPrevString( UniString* pStr ) 222 { 223 sal_uIntPtr nRet = 0; 224 sal_Bool bFound = sal_False; 225 sal_uIntPtr nCountMember = Count(); 226 sal_uIntPtr nUpper = nCountMember; 227 sal_uIntPtr nLower = 0; 228 sal_uIntPtr nCurrent = nUpper / 2; 229 sal_uIntPtr nRem = 0; 230 UniString* pString; 231 232 do 233 { 234 if ( (nCurrent == nLower) || (nCurrent == nUpper) ) 235 return nLower; 236 pString = GetObject( nCurrent ); 237 StringCompare nResult = pStr->CompareTo( *pString ); 238 if ( nResult == COMPARE_LESS ) 239 { 240 nUpper = nCurrent; 241 nCurrent = (nCurrent + nLower) /2; 242 } 243 else if ( nResult == COMPARE_GREATER ) 244 { 245 nLower = nCurrent; 246 nCurrent = (nUpper + nCurrent) /2; 247 } 248 else if ( nResult == COMPARE_EQUAL ) 249 return nCurrent; 250 if ( nRem == nCurrent ) 251 return nCurrent; 252 nRem = nCurrent; 253 } 254 while ( !bFound ); 255 return nRet; 256 } 257 258 /************************************************************************** 259 * 260 * Sortiert einen UniString in die Liste ein und gibt die Position, 261 * an der einsortiert wurde, zurueck 262 * 263 **************************************************************************/ 264 265 sal_uIntPtr SUniStringList::PutString( UniString* pStr ) 266 { 267 sal_uIntPtr nPos = GetPrevString ( pStr ); 268 if ( Count() ) 269 { 270 { 271 UniString* pString = GetObject( 0 ); 272 if ( pString->CompareTo( *pStr ) == COMPARE_GREATER ) 273 { 274 Insert( pStr, (sal_uIntPtr)0); 275 return (sal_uIntPtr)0; 276 } 277 } 278 UniString* pString = GetObject( nPos ); 279 if ( *pStr != *pString ) 280 { 281 Insert( pStr, nPos+1 ); 282 return ( nPos +1 ); 283 } 284 } 285 else 286 { 287 Insert( pStr ); 288 return (sal_uIntPtr)0; 289 } 290 291 return NOT_THERE; 292 } 293 294 UniString* SUniStringList::RemoveString( const UniString& rName ) 295 { 296 sal_uIntPtr i; 297 UniString* pReturn; 298 299 for( i = 0 ; i < Count(); i++ ) 300 { 301 if ( rName == *GetObject( i ) ) 302 { 303 pReturn = GetObject(i); 304 Remove(i); 305 return pReturn; 306 } 307 } 308 309 return NULL; 310 } 311