1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sstring.cxx,v $
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
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
)
63 ByteString
* pString
= GetObject( 0 );
64 if ( pString
&& (*pString
== *pStr
) )
71 ULONG
SByteStringList::GetPrevString( ByteString
* pStr
)
75 ULONG nCountMember
= Count();
76 ULONG nUpper
= nCountMember
;
78 ULONG nCurrent
= nUpper
/ 2;
84 if ( (nCurrent
== nLower
) || (nCurrent
== nUpper
) )
86 pString
= GetObject( nCurrent
);
87 StringCompare nResult
= pStr
->CompareTo( *pString
);
88 if ( nResult
== COMPARE_LESS
)
91 nCurrent
= (nCurrent
+ nLower
) /2;
93 else if ( nResult
== COMPARE_GREATER
)
96 nCurrent
= (nUpper
+ nCurrent
) /2;
98 else if ( nResult
== COMPARE_EQUAL
)
100 if ( nRem
== nCurrent
)
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
);
121 ByteString
* pString
= GetObject( 0 );
122 if ( pString
->CompareTo( *pStr
) == COMPARE_GREATER
)
124 Insert( pStr
, (ULONG
)0 );
128 ByteString
* pString
= GetObject( nPos
);
129 if ( *pStr
!= *pString
)
131 Insert( pStr
, nPos
+1 );
144 ByteString
* SByteStringList::RemoveString( const ByteString
& rName
)
149 for( i
= 0 ; i
< Count(); i
++ )
151 if ( rName
== *GetObject( i
) )
153 pReturn
= GetObject(i
);
162 void SByteStringList::CleanUp()
164 ByteString
* pByteString
= First();
165 while (pByteString
) {
167 pByteString
= Next();
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
);
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();
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
)
223 UniString
* pString
= GetObject( 0 );
224 if ( pString
&& (*pString
== *pStr
) )
231 ULONG
SUniStringList::GetPrevString( UniString
* pStr
)
235 ULONG nCountMember
= Count();
236 ULONG nUpper
= nCountMember
;
238 ULONG nCurrent
= nUpper
/ 2;
244 if ( (nCurrent
== nLower
) || (nCurrent
== nUpper
) )
246 pString
= GetObject( nCurrent
);
247 StringCompare nResult
= pStr
->CompareTo( *pString
);
248 if ( nResult
== COMPARE_LESS
)
251 nCurrent
= (nCurrent
+ nLower
) /2;
253 else if ( nResult
== COMPARE_GREATER
)
256 nCurrent
= (nUpper
+ nCurrent
) /2;
258 else if ( nResult
== COMPARE_EQUAL
)
260 if ( nRem
== nCurrent
)
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
);
281 UniString
* pString
= GetObject( 0 );
282 if ( pString
->CompareTo( *pStr
) == COMPARE_GREATER
)
284 Insert( pStr
, (ULONG
)0);
288 UniString
* pString
= GetObject( nPos
);
289 if ( *pStr
!= *pString
)
291 Insert( pStr
, nPos
+1 );
304 UniString
* SUniStringList::RemoveString( const UniString
& rName
)
309 for( i
= 0 ; i
< Count(); i
++ )
311 if ( rName
== *GetObject( i
) )
313 pReturn
= GetObject(i
);