diff options
author | Ivan Timofeev <timofeev.i.s@gmail.com> | 2011-10-23 17:45:34 +0400 |
---|---|---|
committer | Ivan Timofeev <timofeev.i.s@gmail.com> | 2011-10-24 00:10:33 +0400 |
commit | 3d5caa7ce38c9441d05b01c6feaaaa5ff3bd51de (patch) | |
tree | 8d0e0e37cb283959d2afc879fb1303b74ccf17e5 /tools/source/memtools/multisel.cxx | |
parent | 55170dd7a0cfd552a89b4bea6c7f4a9854971161 (diff) |
StringRangeEnumerator cleanup
* do not allow default unbounded min and max, syntax of the input string
requires them
* simplify logic, remove unused methods, make the class immutable, actualize
documentation
Diffstat (limited to 'tools/source/memtools/multisel.cxx')
-rw-r--r-- | tools/source/memtools/multisel.cxx | 46 |
1 files changed, 13 insertions, 33 deletions
diff --git a/tools/source/memtools/multisel.cxx b/tools/source/memtools/multisel.cxx index 4d6d577269c7..13275a863673 100644 --- a/tools/source/memtools/multisel.cxx +++ b/tools/source/memtools/multisel.cxx @@ -738,17 +738,16 @@ StringRangeEnumerator::StringRangeEnumerator( const rtl::OUString& i_rInput, , mnMin( i_nMinNumber ) , mnMax( i_nMaxNumber ) , mnOffset( i_nLogicalOffset ) + , mbValidInput( false ) { - setRange( i_rInput ); + // Parse string only if boundaries are valid. + if( mnMin >= 0 && mnMax >= 0 && mnMin <= mnMax ) + mbValidInput = setRange( i_rInput ); } bool StringRangeEnumerator::checkValue( sal_Int32 i_nValue, const std::set< sal_Int32 >* i_pPossibleValues ) const { - if( mnMin >= 0 && i_nValue < mnMin ) - return false; - if( mnMax >= 0 && i_nValue > mnMax ) - return false; - if( i_nValue < 0 ) + if( i_nValue < 0 || i_nValue < mnMin || i_nValue > mnMax ) return false; if( i_pPossibleValues && i_pPossibleValues->find( i_nValue ) == i_pPossibleValues->end() ) return false; @@ -760,10 +759,6 @@ bool StringRangeEnumerator::insertRange( sal_Int32 i_nFirst, sal_Int32 i_nLast, bool bSuccess = true; if( bSequence ) { - if( i_nFirst == -1 ) - i_nFirst = mnMin; - if( i_nLast == -1 ) - i_nLast = mnMax; if( bMayAdjust ) { if( i_nFirst < mnMin ) @@ -787,25 +782,15 @@ bool StringRangeEnumerator::insertRange( sal_Int32 i_nFirst, sal_Int32 i_nLast, } else { - if( i_nFirst >= 0 ) + if( checkValue( i_nFirst ) ) { - if( checkValue( i_nFirst ) ) - { - maSequence.push_back( Range( i_nFirst, i_nFirst ) ); - mnCount++; - } - else - bSuccess = false; + maSequence.push_back( Range( i_nFirst, i_nFirst ) ); + mnCount++; } - else if( i_nLast >= 0 ) + else if( checkValue( i_nLast ) ) { - if( checkValue( i_nLast ) ) - { - maSequence.push_back( Range( i_nLast, i_nLast ) ); - mnCount++; - } - else - bSuccess = false; + maSequence.push_back( Range( i_nLast, i_nLast ) ); + mnCount++; } else bSuccess = false; @@ -1002,12 +987,7 @@ bool StringRangeEnumerator::getRangesFromString( const OUString& i_rPageRange, { o_rPageVector.clear(); - StringRangeEnumerator aEnum; - aEnum.setMin( i_nMinNumber ); - aEnum.setMax( i_nMaxNumber ); - aEnum.setLogicalOffset( i_nLogicalOffset ); - - bool bRes = aEnum.setRange( i_rPageRange ); + StringRangeEnumerator aEnum( i_rPageRange, i_nMinNumber, i_nMaxNumber, i_nLogicalOffset ) ; //Even if the input range wasn't completely valid, return what ranges could //be extracted from the input. @@ -1018,7 +998,7 @@ bool StringRangeEnumerator::getRangesFromString( const OUString& i_rPageRange, o_rPageVector.push_back( *it ); } - return bRes; + return aEnum.isValidInput(); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |