merge the formfield patch from ooo-build
[ooovba.git] / sc / source / ui / dbgui / csvsplits.cxx
blobc8e447723a77f185bb52d13d55a3003a4e610b71
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: csvsplits.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
35 // ============================================================================
36 #include "csvsplits.hxx"
37 #include <tools/debug.hxx>
39 #include <algorithm>
42 // ============================================================================
44 bool ScCsvSplits::Insert( sal_Int32 nPos )
46 bool bValid = (nPos >= 0);
47 if( bValid )
49 iterator aIter = ::std::lower_bound( maVec.begin(), maVec.end(), nPos );
50 bValid = (aIter == maVec.end()) || (*aIter != nPos);
51 if( bValid )
52 aIter = maVec.insert( aIter, nPos );
54 return bValid;
57 bool ScCsvSplits::Remove( sal_Int32 nPos )
59 sal_uInt32 nIndex = GetIndex( nPos );
60 bool bValid = (nIndex != CSV_VEC_NOTFOUND);
61 if( bValid )
62 maVec.erase( maVec.begin() + nIndex );
63 return bValid;
66 void ScCsvSplits::RemoveRange( sal_Int32 nPosStart, sal_Int32 nPosEnd )
68 sal_uInt32 nStartIx = LowerBound( nPosStart );
69 sal_uInt32 nEndIx = UpperBound( nPosEnd );
70 if( (nStartIx != CSV_VEC_NOTFOUND) && (nEndIx != CSV_VEC_NOTFOUND) && (nStartIx <= nEndIx) )
71 maVec.erase( maVec.begin() + nStartIx, maVec.begin() + nEndIx + 1 );
74 void ScCsvSplits::Clear()
76 maVec.clear();
79 bool ScCsvSplits::HasSplit( sal_Int32 nPos ) const
81 return GetIndex( nPos ) != CSV_VEC_NOTFOUND;
85 // ----------------------------------------------------------------------------
87 sal_uInt32 ScCsvSplits::GetIndex( sal_Int32 nPos ) const
89 const_iterator aIter = ::std::lower_bound( maVec.begin(), maVec.end(), nPos );
90 return GetIterIndex( ((aIter != maVec.end()) && (*aIter == nPos)) ? aIter : maVec.end() );
93 sal_uInt32 ScCsvSplits::LowerBound( sal_Int32 nPos ) const
95 return GetIterIndex( ::std::lower_bound( maVec.begin(), maVec.end(), nPos ) );
98 sal_uInt32 ScCsvSplits::UpperBound( sal_Int32 nPos ) const
100 sal_uInt32 nIndex = LowerBound( nPos );
101 if( nIndex == CSV_VEC_NOTFOUND )
102 return Count() ? (Count() - 1) : CSV_VEC_NOTFOUND;
103 if( GetPos( nIndex ) == nPos )
104 return nIndex;
105 return nIndex ? (nIndex - 1) : CSV_VEC_NOTFOUND;
108 sal_Int32 ScCsvSplits::GetPos( sal_uInt32 nIndex ) const
110 return (nIndex < Count()) ? maVec[ nIndex ] : CSV_POS_INVALID;
114 // ----------------------------------------------------------------------------
116 sal_uInt32 ScCsvSplits::GetIterIndex( const_iterator aIter ) const
118 return (aIter == maVec.end()) ? CSV_VEC_NOTFOUND : (aIter - maVec.begin());
122 // ============================================================================