| 138 | } |
| 139 | |
| 140 | void sortWindowDescriptions(std::vector<WindowDescription> & window_descriptions) |
| 141 | { |
| 142 | auto window_description_comparator = [](const WindowDescription & lhs, const WindowDescription & rhs) -> bool |
| 143 | { |
| 144 | const auto & left = lhs.full_sort_description; |
| 145 | const auto & right = rhs.full_sort_description; |
| 146 | |
| 147 | for (size_t i = 0; i < std::min(left.size(), right.size()); ++i) |
| 148 | { |
| 149 | if (left[i].column_name < right[i].column_name) |
| 150 | return true; |
| 151 | if (left[i].column_name > right[i].column_name) |
| 152 | return false; |
| 153 | if (left[i].direction < right[i].direction) |
| 154 | return true; |
| 155 | if (left[i].direction > right[i].direction) |
| 156 | return false; |
| 157 | if (left[i].nulls_direction < right[i].nulls_direction) |
| 158 | return true; |
| 159 | if (left[i].nulls_direction > right[i].nulls_direction) |
| 160 | return false; |
| 161 | |
| 162 | if (left[i].collator || right[i].collator) |
| 163 | { |
| 164 | if (!left[i].collator) |
| 165 | return true; |
| 166 | if (!right[i].collator) |
| 167 | return false; |
| 168 | if (left[i].collator->getLocale() < right[i].collator->getLocale()) |
| 169 | return true; |
| 170 | if (left[i].collator->getLocale() > right[i].collator->getLocale()) |
| 171 | return false; |
| 172 | } |
| 173 | |
| 174 | chassert(left[i] == right[i]); |
| 175 | } |
| 176 | |
| 177 | /** Note that we check the length last, because we want to put together the |
| 178 | * sort orders that have common prefix but different length. |
| 179 | */ |
| 180 | return left.size() > right.size(); |
| 181 | }; |
| 182 | |
| 183 | ::sort(window_descriptions.begin(), window_descriptions.end(), window_description_comparator); |
| 184 | } |
| 185 | |
| 186 | } |