bump product version to 4.1.6.2
[LibreOffice.git] / sc / source / ui / dbgui / csvsplits.cxx
blobae7b198b116e67a7081bdb226ae7b56ba60b663a
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 "csvsplits.hxx"
22 #include <algorithm>
25 // ============================================================================
27 bool ScCsvSplits::Insert( sal_Int32 nPos )
29 bool bValid = (nPos >= 0);
30 if( bValid )
32 iterator aIter = ::std::lower_bound( maVec.begin(), maVec.end(), nPos );
33 bValid = (aIter == maVec.end()) || (*aIter != nPos);
34 if( bValid )
35 aIter = maVec.insert( aIter, nPos );
37 return bValid;
40 bool ScCsvSplits::Remove( sal_Int32 nPos )
42 sal_uInt32 nIndex = GetIndex( nPos );
43 bool bValid = (nIndex != CSV_VEC_NOTFOUND);
44 if( bValid )
45 maVec.erase( maVec.begin() + nIndex );
46 return bValid;
49 void ScCsvSplits::RemoveRange( sal_Int32 nPosStart, sal_Int32 nPosEnd )
51 sal_uInt32 nStartIx = LowerBound( nPosStart );
52 sal_uInt32 nEndIx = UpperBound( nPosEnd );
53 if( (nStartIx != CSV_VEC_NOTFOUND) && (nEndIx != CSV_VEC_NOTFOUND) && (nStartIx <= nEndIx) )
54 maVec.erase( maVec.begin() + nStartIx, maVec.begin() + nEndIx + 1 );
57 void ScCsvSplits::Clear()
59 maVec.clear();
62 bool ScCsvSplits::HasSplit( sal_Int32 nPos ) const
64 return GetIndex( nPos ) != CSV_VEC_NOTFOUND;
68 // ----------------------------------------------------------------------------
70 sal_uInt32 ScCsvSplits::GetIndex( sal_Int32 nPos ) const
72 const_iterator aIter = ::std::lower_bound( maVec.begin(), maVec.end(), nPos );
73 return GetIterIndex( ((aIter != maVec.end()) && (*aIter == nPos)) ? aIter : maVec.end() );
76 sal_uInt32 ScCsvSplits::LowerBound( sal_Int32 nPos ) const
78 return GetIterIndex( ::std::lower_bound( maVec.begin(), maVec.end(), nPos ) );
81 sal_uInt32 ScCsvSplits::UpperBound( sal_Int32 nPos ) const
83 sal_uInt32 nIndex = LowerBound( nPos );
84 if( nIndex == CSV_VEC_NOTFOUND )
85 return Count() ? (Count() - 1) : CSV_VEC_NOTFOUND;
86 if( GetPos( nIndex ) == nPos )
87 return nIndex;
88 return nIndex ? (nIndex - 1) : CSV_VEC_NOTFOUND;
91 sal_Int32 ScCsvSplits::GetPos( sal_uInt32 nIndex ) const
93 return (nIndex < Count()) ? maVec[ nIndex ] : CSV_POS_INVALID;
97 // ----------------------------------------------------------------------------
99 sal_uInt32 ScCsvSplits::GetIterIndex( const_iterator aIter ) const
101 return (aIter == maVec.end()) ? CSV_VEC_NOTFOUND : (aIter - maVec.begin());
105 // ============================================================================
107 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */