1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_comphelper.hxx"
26 #include <comphelper/sequence.hxx>
27
28 //.........................................................................
29 namespace comphelper
30 {
31 //.........................................................................
32
33 //------------------------------------------------------------------------------
findValue(const staruno::Sequence<::rtl::OUString> & _rList,const::rtl::OUString & _rValue,sal_Bool _bOnlyFirst)34 staruno::Sequence<sal_Int16> findValue(const staruno::Sequence< ::rtl::OUString >& _rList, const ::rtl::OUString& _rValue, sal_Bool _bOnlyFirst)
35 {
36 sal_Int32 nLength = _rList.getLength();
37
38 if( _bOnlyFirst )
39 {
40 //////////////////////////////////////////////////////////////////////
41 // An welcher Position finde ich den Wert?
42 sal_Int32 nPos = -1;
43 const ::rtl::OUString* pTArray = _rList.getConstArray();
44 for (sal_Int32 i = 0; i < nLength; ++i, ++pTArray)
45 {
46 if( pTArray->equals(_rValue) )
47 {
48 nPos = i;
49 break;
50 }
51 }
52
53 //////////////////////////////////////////////////////////////////////
54 // Sequence fuellen
55 if( nPos>-1 )
56 {
57 staruno::Sequence<sal_Int16> aRetSeq( 1 );
58 aRetSeq.getArray()[0] = (sal_Int16)nPos;
59
60 return aRetSeq;
61 }
62
63 return staruno::Sequence<sal_Int16>();
64
65 }
66 else
67 {
68 staruno::Sequence<sal_Int16> aRetSeq( nLength );
69 sal_Int16* pReturn = aRetSeq.getArray();
70
71 //////////////////////////////////////////////////////////////////////
72 // Wie oft kommt der Wert vor?
73 const ::rtl::OUString* pTArray = _rList.getConstArray();
74 for (sal_Int32 i = 0; i < nLength; ++i, ++pTArray)
75 {
76 if( pTArray->equals(_rValue) )
77 {
78 *pReturn = (sal_Int16)i;
79 ++pReturn;
80 }
81 }
82
83 aRetSeq.realloc(pReturn - aRetSeq.getArray());
84
85 return aRetSeq;
86 }
87 }
88 // -----------------------------------------------------------------------------
existsValue(const::rtl::OUString & Value,const staruno::Sequence<::rtl::OUString> & _aList)89 sal_Bool existsValue(const ::rtl::OUString& Value,const staruno::Sequence< ::rtl::OUString >& _aList)
90 {
91 const ::rtl::OUString * pIter = _aList.getConstArray();
92 const ::rtl::OUString * pEnd = pIter + _aList.getLength();
93 return ::std::find(pIter,pEnd,Value) != pEnd;
94 }
95
96 //.........................................................................
97 } // namespace comphelper
98 //.........................................................................
99
100