update dev300-m58
[ooovba.git] / comphelper / source / misc / sequence.cxx
blob46d1f22ff8ada0e4548f026f0dffe5d96f983f50
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: sequence.cxx,v $
10 * $Revision: 1.6 $
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_comphelper.hxx"
33 #include <comphelper/sequence.hxx>
35 //.........................................................................
36 namespace comphelper
38 //.........................................................................
40 //------------------------------------------------------------------------------
41 staruno::Sequence<sal_Int16> findValue(const staruno::Sequence< ::rtl::OUString >& _rList, const ::rtl::OUString& _rValue, sal_Bool _bOnlyFirst)
43 sal_Int32 nLength = _rList.getLength();
45 if( _bOnlyFirst )
47 //////////////////////////////////////////////////////////////////////
48 // An welcher Position finde ich den Wert?
49 sal_Int32 nPos = -1;
50 const ::rtl::OUString* pTArray = _rList.getConstArray();
51 for (sal_Int32 i = 0; i < nLength; ++i, ++pTArray)
53 if( pTArray->equals(_rValue) )
55 nPos = i;
56 break;
60 //////////////////////////////////////////////////////////////////////
61 // Sequence fuellen
62 if( nPos>-1 )
64 staruno::Sequence<sal_Int16> aRetSeq( 1 );
65 aRetSeq.getArray()[0] = (sal_Int16)nPos;
67 return aRetSeq;
70 return staruno::Sequence<sal_Int16>();
73 else
75 staruno::Sequence<sal_Int16> aRetSeq( nLength );
76 sal_Int16* pReturn = aRetSeq.getArray();
78 //////////////////////////////////////////////////////////////////////
79 // Wie oft kommt der Wert vor?
80 const ::rtl::OUString* pTArray = _rList.getConstArray();
81 for (sal_Int32 i = 0; i < nLength; ++i, ++pTArray)
83 if( pTArray->equals(_rValue) )
85 *pReturn = (sal_Int16)i;
86 ++pReturn;
90 aRetSeq.realloc(pReturn - aRetSeq.getArray());
92 return aRetSeq;
95 // -----------------------------------------------------------------------------
96 sal_Bool existsValue(const ::rtl::OUString& Value,const staruno::Sequence< ::rtl::OUString >& _aList)
98 const ::rtl::OUString * pIter = _aList.getConstArray();
99 const ::rtl::OUString * pEnd = pIter + _aList.getLength();
100 return ::std::find(pIter,pEnd,Value) != pEnd;
103 //.........................................................................
104 } // namespace comphelper
105 //.........................................................................