CWS-TOOLING: integrate CWS os146
[LibreOffice.git] / comphelper / source / misc / sequence.cxx
blobb0d7c4da1587a77c1c304e5c637cc322b071f24d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_comphelper.hxx"
30 #include <comphelper/sequence.hxx>
32 //.........................................................................
33 namespace comphelper
35 //.........................................................................
37 //------------------------------------------------------------------------------
38 staruno::Sequence<sal_Int16> findValue(const staruno::Sequence< ::rtl::OUString >& _rList, const ::rtl::OUString& _rValue, sal_Bool _bOnlyFirst)
40 sal_Int32 nLength = _rList.getLength();
42 if( _bOnlyFirst )
44 //////////////////////////////////////////////////////////////////////
45 // An welcher Position finde ich den Wert?
46 sal_Int32 nPos = -1;
47 const ::rtl::OUString* pTArray = _rList.getConstArray();
48 for (sal_Int32 i = 0; i < nLength; ++i, ++pTArray)
50 if( pTArray->equals(_rValue) )
52 nPos = i;
53 break;
57 //////////////////////////////////////////////////////////////////////
58 // Sequence fuellen
59 if( nPos>-1 )
61 staruno::Sequence<sal_Int16> aRetSeq( 1 );
62 aRetSeq.getArray()[0] = (sal_Int16)nPos;
64 return aRetSeq;
67 return staruno::Sequence<sal_Int16>();
70 else
72 staruno::Sequence<sal_Int16> aRetSeq( nLength );
73 sal_Int16* pReturn = aRetSeq.getArray();
75 //////////////////////////////////////////////////////////////////////
76 // Wie oft kommt der Wert vor?
77 const ::rtl::OUString* pTArray = _rList.getConstArray();
78 for (sal_Int32 i = 0; i < nLength; ++i, ++pTArray)
80 if( pTArray->equals(_rValue) )
82 *pReturn = (sal_Int16)i;
83 ++pReturn;
87 aRetSeq.realloc(pReturn - aRetSeq.getArray());
89 return aRetSeq;
92 // -----------------------------------------------------------------------------
93 sal_Bool existsValue(const ::rtl::OUString& Value,const staruno::Sequence< ::rtl::OUString >& _aList)
95 const ::rtl::OUString * pIter = _aList.getConstArray();
96 const ::rtl::OUString * pEnd = pIter + _aList.getLength();
97 return ::std::find(pIter,pEnd,Value) != pEnd;
100 //.........................................................................
101 } // namespace comphelper
102 //.........................................................................