merge the formfield patch from ooo-build
[ooovba.git] / tools / bootstrp / sstring.cxx
blobafc75bc8e390839fb0abf7ff219d9b64fb1f2f1e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sstring.cxx,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_tools.hxx"
34 #ifndef _TOOLS_STRINGLIST
35 # define _TOOLS_STRINGLIST
36 #endif
38 #define ENABLE_BYTESTRING_STREAM_OPERATORS
39 #include <tools/stream.hxx>
40 #include "bootstrp/sstring.hxx"
42 SByteStringList::SByteStringList()
46 SByteStringList::~SByteStringList()
50 ULONG SByteStringList::IsString( ByteString* pStr )
52 ULONG nRet = NOT_THERE;
53 if ( (nRet = GetPrevString( pStr )) != 0 )
55 ByteString* pString = GetObject( nRet );
56 if ( *pString == *pStr )
57 return nRet;
58 else
59 return NOT_THERE;
61 else
63 ByteString* pString = GetObject( 0 );
64 if ( pString && (*pString == *pStr) )
65 return 0;
66 else
67 return NOT_THERE;
71 ULONG SByteStringList::GetPrevString( ByteString* pStr )
73 ULONG nRet = 0;
74 BOOL bFound = FALSE;
75 ULONG nCountMember = Count();
76 ULONG nUpper = nCountMember;
77 ULONG nLower = 0;
78 ULONG nCurrent = nUpper / 2;
79 ULONG nRem = 0;
80 ByteString* pString;
84 if ( (nCurrent == nLower) || (nCurrent == nUpper) )
85 return nLower;
86 pString = GetObject( nCurrent );
87 StringCompare nResult = pStr->CompareTo( *pString );
88 if ( nResult == COMPARE_LESS )
90 nUpper = nCurrent;
91 nCurrent = (nCurrent + nLower) /2;
93 else if ( nResult == COMPARE_GREATER )
95 nLower = nCurrent;
96 nCurrent = (nUpper + nCurrent) /2;
98 else if ( nResult == COMPARE_EQUAL )
99 return nCurrent;
100 if ( nRem == nCurrent )
101 return nCurrent;
102 nRem = nCurrent;
104 while ( !bFound );
105 return nRet;
108 /**************************************************************************
110 * Sortiert einen ByteString in die Liste ein und gibt die Position,
111 * an der einsortiert wurde, zurueck
113 **************************************************************************/
115 ULONG SByteStringList::PutString( ByteString* pStr )
117 ULONG nPos = GetPrevString ( pStr );
118 if ( Count() )
121 ByteString* pString = GetObject( 0 );
122 if ( pString->CompareTo( *pStr ) == COMPARE_GREATER )
124 Insert( pStr, (ULONG)0 );
125 return (ULONG)0;
128 ByteString* pString = GetObject( nPos );
129 if ( *pStr != *pString )
131 Insert( pStr, nPos+1 );
132 return ( nPos +1 );
135 else
137 Insert( pStr );
138 return (ULONG)0;
141 return NOT_THERE;
144 ByteString* SByteStringList::RemoveString( const ByteString& rName )
146 ULONG i;
147 ByteString* pReturn;
149 for( i = 0 ; i < Count(); i++ )
151 if ( rName == *GetObject( i ) )
153 pReturn = GetObject(i);
154 Remove(i);
155 return pReturn;
159 return NULL;
162 void SByteStringList::CleanUp()
164 ByteString* pByteString = First();
165 while (pByteString) {
166 delete pByteString;
167 pByteString = Next();
169 Clear();
172 SByteStringList& SByteStringList::operator<< ( SvStream& rStream )
174 sal_uInt32 nListCount;
175 rStream >> nListCount;
176 for ( USHORT i = 0; i < nListCount; i++ ) {
177 ByteString* pByteString = new ByteString();
178 rStream >> *pByteString;
179 Insert (pByteString, LIST_APPEND);
181 return *this;
184 SByteStringList& SByteStringList::operator>> ( SvStream& rStream )
186 sal_uInt32 nListCount = Count();
187 rStream << nListCount;
188 ByteString* pByteString = First();
189 while (pByteString) {
190 rStream << *pByteString;
191 pByteString = Next();
193 return *this;
202 SUniStringList::SUniStringList()
206 SUniStringList::~SUniStringList()
210 ULONG SUniStringList::IsString( UniString* pStr )
212 ULONG nRet = NOT_THERE;
213 if ( (nRet = GetPrevString( pStr )) != 0 )
215 UniString* pString = GetObject( nRet );
216 if ( *pString == *pStr )
217 return nRet;
218 else
219 return NOT_THERE;
221 else
223 UniString* pString = GetObject( 0 );
224 if ( pString && (*pString == *pStr) )
225 return 0;
226 else
227 return NOT_THERE;
231 ULONG SUniStringList::GetPrevString( UniString* pStr )
233 ULONG nRet = 0;
234 BOOL bFound = FALSE;
235 ULONG nCountMember = Count();
236 ULONG nUpper = nCountMember;
237 ULONG nLower = 0;
238 ULONG nCurrent = nUpper / 2;
239 ULONG nRem = 0;
240 UniString* pString;
244 if ( (nCurrent == nLower) || (nCurrent == nUpper) )
245 return nLower;
246 pString = GetObject( nCurrent );
247 StringCompare nResult = pStr->CompareTo( *pString );
248 if ( nResult == COMPARE_LESS )
250 nUpper = nCurrent;
251 nCurrent = (nCurrent + nLower) /2;
253 else if ( nResult == COMPARE_GREATER )
255 nLower = nCurrent;
256 nCurrent = (nUpper + nCurrent) /2;
258 else if ( nResult == COMPARE_EQUAL )
259 return nCurrent;
260 if ( nRem == nCurrent )
261 return nCurrent;
262 nRem = nCurrent;
264 while ( !bFound );
265 return nRet;
268 /**************************************************************************
270 * Sortiert einen UniString in die Liste ein und gibt die Position,
271 * an der einsortiert wurde, zurueck
273 **************************************************************************/
275 ULONG SUniStringList::PutString( UniString* pStr )
277 ULONG nPos = GetPrevString ( pStr );
278 if ( Count() )
281 UniString* pString = GetObject( 0 );
282 if ( pString->CompareTo( *pStr ) == COMPARE_GREATER )
284 Insert( pStr, (ULONG)0);
285 return (ULONG)0;
288 UniString* pString = GetObject( nPos );
289 if ( *pStr != *pString )
291 Insert( pStr, nPos+1 );
292 return ( nPos +1 );
295 else
297 Insert( pStr );
298 return (ULONG)0;
301 return NOT_THERE;
304 UniString* SUniStringList::RemoveString( const UniString& rName )
306 ULONG i;
307 UniString* pReturn;
309 for( i = 0 ; i < Count(); i++ )
311 if ( rName == *GetObject( i ) )
313 pReturn = GetObject(i);
314 Remove(i);
315 return pReturn;
319 return NULL;