Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / comphelper / source / misc / sequence.cxx
blobdacba9d62be64f69f893a81bc0cfc678ce7abea9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <comphelper/sequence.hxx>
22 //.........................................................................
23 namespace comphelper
25 //.........................................................................
27 //------------------------------------------------------------------------------
28 staruno::Sequence<sal_Int16> findValue(const staruno::Sequence< ::rtl::OUString >& _rList, const ::rtl::OUString& _rValue, sal_Bool _bOnlyFirst)
30 sal_Int32 nLength = _rList.getLength();
32 if( _bOnlyFirst )
34 //////////////////////////////////////////////////////////////////////
35 // An welcher Position finde ich den Wert?
36 sal_Int32 nPos = -1;
37 const ::rtl::OUString* pTArray = _rList.getConstArray();
38 for (sal_Int32 i = 0; i < nLength; ++i, ++pTArray)
40 if( pTArray->equals(_rValue) )
42 nPos = i;
43 break;
47 //////////////////////////////////////////////////////////////////////
48 // Sequence fuellen
49 if( nPos>-1 )
51 staruno::Sequence<sal_Int16> aRetSeq( 1 );
52 aRetSeq.getArray()[0] = (sal_Int16)nPos;
54 return aRetSeq;
57 return staruno::Sequence<sal_Int16>();
60 else
62 staruno::Sequence<sal_Int16> aRetSeq( nLength );
63 sal_Int16* pReturn = aRetSeq.getArray();
65 //////////////////////////////////////////////////////////////////////
66 // Wie oft kommt der Wert vor?
67 const ::rtl::OUString* pTArray = _rList.getConstArray();
68 for (sal_Int32 i = 0; i < nLength; ++i, ++pTArray)
70 if( pTArray->equals(_rValue) )
72 *pReturn = (sal_Int16)i;
73 ++pReturn;
77 aRetSeq.realloc(pReturn - aRetSeq.getArray());
79 return aRetSeq;
82 // -----------------------------------------------------------------------------
83 sal_Bool existsValue(const ::rtl::OUString& Value,const staruno::Sequence< ::rtl::OUString >& _aList)
85 const ::rtl::OUString * pIter = _aList.getConstArray();
86 const ::rtl::OUString * pEnd = pIter + _aList.getLength();
87 return ::std::find(pIter,pEnd,Value) != pEnd;
90 //.........................................................................
91 } // namespace comphelper
92 //.........................................................................
94 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */