diff options
author | Eike Rathke <erack@redhat.com> | 2013-08-26 18:10:53 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2013-08-26 18:16:30 +0200 |
commit | 5af6437f6b602773fb76dca76be1fc079d93c922 (patch) | |
tree | d37a6a9c73009b379ac0474e983b8f5b33590877 /sc/source/ui/dbgui/asciiopt.cxx | |
parent | d198d2fb1b3d1d65450f9be30a94b00631d3c9b8 (diff) |
resolved fdo#53449 weight given separators to pick one for output
Change-Id: Iaef3ed270d870f7c26062cdbbc9bf243bc5b5a78
Diffstat (limited to 'sc/source/ui/dbgui/asciiopt.cxx')
-rw-r--r-- | sc/source/ui/dbgui/asciiopt.cxx | 61 |
1 files changed, 44 insertions, 17 deletions
diff --git a/sc/source/ui/dbgui/asciiopt.cxx b/sc/source/ui/dbgui/asciiopt.cxx index 0f514ce9bcc4..2170a042ee38 100644 --- a/sc/source/ui/dbgui/asciiopt.cxx +++ b/sc/source/ui/dbgui/asciiopt.cxx @@ -179,6 +179,25 @@ bool ScAsciiOptions::operator==( const ScAsciiOptions& rCmp ) const return false; } +String lcl_decodeSepString( const String & rSepNums, bool & o_bMergeFieldSeps ) +{ + String aFieldSeps; + xub_StrLen nSub = comphelper::string::getTokenCount( rSepNums, '/'); + for (xub_StrLen i=0; i<nSub; ++i) + { + String aCode = rSepNums.GetToken( i, '/' ); + if ( aCode.EqualsAscii(pStrMrg) ) + o_bMergeFieldSeps = true; + else + { + sal_Int32 nVal = aCode.ToInt32(); + if ( nVal ) + aFieldSeps += (sal_Unicode) nVal; + } + } + return aFieldSeps; +} + // The options string must not contain semicolons (because of the pick list), // use comma as separator. @@ -186,31 +205,16 @@ void ScAsciiOptions::ReadFromString( const String& rString ) { xub_StrLen nCount = comphelper::string::getTokenCount(rString, ','); String aToken; - xub_StrLen nSub; - xub_StrLen i; // Field separator. if ( nCount >= 1 ) { bFixedLen = bMergeFieldSeps = false; - aFieldSeps.Erase(); aToken = rString.GetToken(0,','); if ( aToken.EqualsAscii(pStrFix) ) bFixedLen = true; - nSub = comphelper::string::getTokenCount(aToken, '/'); - for ( i=0; i<nSub; i++ ) - { - String aCode = aToken.GetToken( i, '/' ); - if ( aCode.EqualsAscii(pStrMrg) ) - bMergeFieldSeps = true; - else - { - sal_Int32 nVal = aCode.ToInt32(); - if ( nVal ) - aFieldSeps += (sal_Unicode) nVal; - } - } + aFieldSeps = lcl_decodeSepString( aToken, bMergeFieldSeps); } // Text separator. @@ -242,7 +246,7 @@ void ScAsciiOptions::ReadFromString( const String& rString ) delete[] pColFormat; aToken = rString.GetToken(4,','); - nSub = comphelper::string::getTokenCount(aToken, '/'); + xub_StrLen nSub = comphelper::string::getTokenCount(aToken, '/'); nInfoCount = nSub / 2; if (nInfoCount) { @@ -354,4 +358,27 @@ String ScAsciiOptions::WriteToString() const return aOutStr; } +// static +sal_Unicode ScAsciiOptions::GetWeightedFieldSep( const String & rFieldSeps, bool bDecodeNumbers ) +{ + bool bMergeFieldSeps = false; + String aFieldSeps( bDecodeNumbers ? lcl_decodeSepString( rFieldSeps, bMergeFieldSeps) : rFieldSeps); + if (aFieldSeps.Len() <= 1) + return aFieldSeps.GetChar(0); + else + { + // There can be only one separator for output. See also fdo#53449 + if (aFieldSeps.Search(',') != STRING_NOTFOUND) + return ','; + else if (aFieldSeps.Search('\t') != STRING_NOTFOUND) + return '\t'; + else if (aFieldSeps.Search(';') != STRING_NOTFOUND) + return ';'; + else if (aFieldSeps.Search(' ') != STRING_NOTFOUND) + return ' '; + else + return aFieldSeps.GetChar(0); + } +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |