1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 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. 14 * 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). 20 * 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. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_comphelper.hxx" 30 #include <comphelper/sequence.hxx> 31 32 //......................................................................... 33 namespace comphelper 34 { 35 //......................................................................... 36 37 //------------------------------------------------------------------------------ 38 staruno::Sequence<sal_Int16> findValue(const staruno::Sequence< ::rtl::OUString >& _rList, const ::rtl::OUString& _rValue, sal_Bool _bOnlyFirst) 39 { 40 sal_Int32 nLength = _rList.getLength(); 41 42 if( _bOnlyFirst ) 43 { 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) 49 { 50 if( pTArray->equals(_rValue) ) 51 { 52 nPos = i; 53 break; 54 } 55 } 56 57 ////////////////////////////////////////////////////////////////////// 58 // Sequence fuellen 59 if( nPos>-1 ) 60 { 61 staruno::Sequence<sal_Int16> aRetSeq( 1 ); 62 aRetSeq.getArray()[0] = (sal_Int16)nPos; 63 64 return aRetSeq; 65 } 66 67 return staruno::Sequence<sal_Int16>(); 68 69 } 70 else 71 { 72 staruno::Sequence<sal_Int16> aRetSeq( nLength ); 73 sal_Int16* pReturn = aRetSeq.getArray(); 74 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) 79 { 80 if( pTArray->equals(_rValue) ) 81 { 82 *pReturn = (sal_Int16)i; 83 ++pReturn; 84 } 85 } 86 87 aRetSeq.realloc(pReturn - aRetSeq.getArray()); 88 89 return aRetSeq; 90 } 91 } 92 // ----------------------------------------------------------------------------- 93 sal_Bool existsValue(const ::rtl::OUString& Value,const staruno::Sequence< ::rtl::OUString >& _aList) 94 { 95 const ::rtl::OUString * pIter = _aList.getConstArray(); 96 const ::rtl::OUString * pEnd = pIter + _aList.getLength(); 97 return ::std::find(pIter,pEnd,Value) != pEnd; 98 } 99 100 //......................................................................... 101 } // namespace comphelper 102 //......................................................................... 103 104