1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* 3 * This file is part of the LibreOffice project. 4 * 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/. 8 */ 9 10 #include <typedstrdata.hxx> 11 #include <global.hxx> 12 13 #include <unotools/collatorwrapper.hxx> 14 #include <unotools/transliterationwrapper.hxx> 15 #include <utility> 16 17 bool ScTypedStrData::LessHiddenRows::operator() (const ScTypedStrData& left, const ScTypedStrData& right) const 18 { 19 return left.mbIsHiddenByFilter < right.mbIsHiddenByFilter; 20 } 21 22 bool ScTypedStrData::LessCaseSensitive::operator() (const ScTypedStrData& left, const ScTypedStrData& right) const 23 { 24 if (left.meStrType != right.meStrType) 25 return left.meStrType < right.meStrType; 26 27 if (left.meStrType == Value) 28 { 29 if (left.mfValue == right.mfValue) 30 return left.mbIsHiddenByFilter < right.mbIsHiddenByFilter; 31 return left.mfValue < right.mfValue; 32 } 33 34 if (left.mbIsDate != right.mbIsDate) 35 return left.mbIsDate < right.mbIsDate; 36 37 sal_Int32 nEqual 38 = ScGlobal::GetCaseTransliteration().compareString(left.maStrValue, right.maStrValue); 39 40 if (!nEqual) 41 return left.mbIsHiddenByFilter < right.mbIsHiddenByFilter; 42 43 return nEqual < 0; 44 } 45 46 bool ScTypedStrData::LessSortCaseSensitive::operator() (const ScTypedStrData& left, const ScTypedStrData& right) const 47 { 48 if (left.meStrType != right.meStrType) 49 return left.meStrType < right.meStrType; 50 51 if (left.meStrType == Value) 52 { 53 if (left.mfValue == right.mfValue) 54 return left.mbIsHiddenByFilter < right.mbIsHiddenByFilter; 55 return left.mfValue < right.mfValue; 56 } 57 58 if (left.mbIsDate != right.mbIsDate) 59 return left.mbIsDate < right.mbIsDate; 60 61 sal_Int32 nEqual = ScGlobal::GetCaseCollator().compareString(left.maStrValue, right.maStrValue); 62 63 if (!nEqual) 64 return left.mbIsHiddenByFilter < right.mbIsHiddenByFilter; 65 66 return nEqual < 0; 67 } 68 69 bool ScTypedStrData::LessCaseInsensitive::operator() (const ScTypedStrData& left, const ScTypedStrData& right) const 70 { 71 if (left.meStrType != right.meStrType) 72 return left.meStrType < right.meStrType; 73 74 if (left.meStrType == Value) 75 { 76 if (left.mfValue == right.mfValue) 77 return left.mbIsHiddenByFilter < right.mbIsHiddenByFilter; 78 return left.mfValue < right.mfValue; 79 } 80 81 if (left.mbIsDate != right.mbIsDate) 82 return left.mbIsDate < right.mbIsDate; 83 84 sal_Int32 nEqual 85 = ScGlobal::GetTransliteration().compareString(left.maStrValue, right.maStrValue); 86 87 if (!nEqual) 88 return left.mbIsHiddenByFilter < right.mbIsHiddenByFilter; 89 90 return nEqual < 0; 91 } 92 93 bool ScTypedStrData::LessSortCaseInsensitive::operator() (const ScTypedStrData& left, const ScTypedStrData& right) const 94 { 95 if (left.meStrType != right.meStrType) 96 return left.meStrType < right.meStrType; 97 98 if (left.meStrType == Value) 99 { 100 if (left.mfValue == right.mfValue) 101 return left.mbIsHiddenByFilter < right.mbIsHiddenByFilter; 102 return left.mfValue < right.mfValue; 103 } 104 105 if (left.mbIsDate != right.mbIsDate) 106 return left.mbIsDate < right.mbIsDate; 107 108 sal_Int32 nEqual = ScGlobal::GetCaseCollator().compareString(left.maStrValue, right.maStrValue); 109 110 if (!nEqual) 111 return left.mbIsHiddenByFilter < right.mbIsHiddenByFilter; 112 113 return nEqual < 0; 114 } 115 116 bool ScTypedStrData::EqualCaseSensitive::operator() (const ScTypedStrData& left, const ScTypedStrData& right) const 117 { 118 if (left.meStrType != right.meStrType) 119 return false; 120 121 if (left.meStrType == Value && left.mfRoundedValue != right.mfRoundedValue) 122 return false; 123 124 if (left.mbIsDate != right.mbIsDate ) 125 return false; 126 127 return ScGlobal::GetCaseTransliteration().isEqual(left.maStrValue, right.maStrValue); 128 } 129 130 bool ScTypedStrData::EqualCaseInsensitive::operator() (const ScTypedStrData& left, const ScTypedStrData& right) const 131 { 132 if (left.meStrType != right.meStrType) 133 return false; 134 135 if (left.meStrType == Value && left.mfRoundedValue != right.mfRoundedValue) 136 return false; 137 138 if (left.mbIsDate != right.mbIsDate ) 139 return false; 140 141 return ScGlobal::GetTransliteration().isEqual(left.maStrValue, right.maStrValue); 142 } 143 144 bool ScTypedStrData::operator< (const ScTypedStrData& r) const 145 { 146 // Case insensitive comparison by default. 147 return LessCaseInsensitive()(*this, r); 148 } 149 150 ScTypedStrData::ScTypedStrData( 151 const OUString& rStr, double fVal, double fRVal, StringType nType, bool bDate, bool bIsHiddenByFilter ) : 152 maStrValue(rStr), 153 mfValue(fVal), 154 mfRoundedValue(fRVal), 155 meStrType(nType), 156 mbIsDate( bDate ), 157 mbIsHiddenByFilter(bIsHiddenByFilter) {} 158 159 FindTypedStrData::FindTypedStrData(ScTypedStrData aVal, bool bCaseSens) : 160 maVal(std::move(aVal)), mbCaseSens(bCaseSens) {} 161 162 bool FindTypedStrData::operator() (const ScTypedStrData& r) const 163 { 164 if (mbCaseSens) 165 { 166 return ScTypedStrData::EqualCaseSensitive()(maVal, r); 167 } 168 else 169 { 170 return ScTypedStrData::EqualCaseInsensitive()(maVal, r); 171 } 172 } 173 174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 175
