Exemplo n.º 1
0
bool menu::basic_sorter::less(int column, const item& row1, const item& row2) const
{
	const std::map<int,int>::const_iterator redirect = redirect_sort_.find(column);
	if(redirect != redirect_sort_.end()) {
		return less(redirect->second,row1,row2);
	}

	if(id_sort_.count(column) == 1) {
		return row1.id < row2.id;
	}

	if(column < 0 || column >= int(row2.fields.size())) {
		return false;
	}

	if(column >= int(row1.fields.size())) {
		return true;
	}

	const std::string& item1 = font::del_tags(row1.fields[column]);
	const std::string& item2 = font::del_tags(row2.fields[column]);

	if(alpha_sort_.count(column) == 1) {
		std::string::const_iterator begin1 = item1.begin(), end1 = item1.end(),
		                            begin2 = item2.begin(), end2 = item2.end();
		while(begin1 != end1 && is_wml_separator(*begin1)) {
			++begin1;
		}

		while(begin2 != end2 && is_wml_separator(*begin2)) {
			++begin2;
		}

		return std::lexicographical_compare(begin1,end1,begin2,end2,chars_less_insensitive);
	} else if(numeric_sort_.count(column) == 1) {
		int val_1 = lexical_cast_default<int>(item1, 0);
		int val_2 = lexical_cast_default<int>(item2, 0);

		return val_1 > val_2;
	} else if(xp_sort_.count(column) == 1) {
		return xp_to_advance(item1) < xp_to_advance(item2);
	} else if(level_sort_.count(column) == 1) {
		int level_1 = lexical_cast_default<int>(item1, 0);
		int level_2 = lexical_cast_default<int>(item2, 0);
		if (level_1 == level_2) {
			//break tie using xp
			const std::string& xp_item1 = font::del_tags(row1.fields[xp_col_]);
			const std::string& xp_item2 = font::del_tags(row2.fields[xp_col_]);
			return xp_to_advance(xp_item1) < xp_to_advance(xp_item2);
		}
		return level_1 > level_2;
	}

	const std::map<int,std::vector<int> >::const_iterator itor = pos_sort_.find(column);
	if(itor != pos_sort_.end()) {
		const std::vector<int>& pos = itor->second;
		if(row1.id >= pos.size()) {
			return false;
		}

		if(row2.id >= pos.size()) {
			return true;
		}

		return pos[row1.id] < pos[row2.id];
	}

	return false;
}
Exemplo n.º 2
0
bool menu::basic_sorter::less(int column, const item& row1, const item& row2) const
{
	const std::map<int,int>::const_iterator redirect = redirect_sort_.find(column);
	if(redirect != redirect_sort_.end()) {
		return less(redirect->second,row1,row2);
	}

	if(id_sort_.count(column) == 1) {
		return row1.id < row2.id;
	}

	if(column < 0 || column >= int(row2.fields.size())) {
		return false;
	}

	if(column >= int(row1.fields.size())) {
		return true;
	}

	if(alpha_sort_.count(column) == 1) {
		const std::string& item1 = font::del_tags(row1.fields[column]);
		const std::string& item2 = font::del_tags(row2.fields[column]);

		std::string::const_iterator begin1 = item1.begin(), end1 = item1.end(),
		                            begin2 = item2.begin(), end2 = item2.end();
		while(begin1 != end1 && is_wml_separator(*begin1)) {
			++begin1;
		}

		while(begin2 != end2 && is_wml_separator(*begin2)) {
			++begin2;
		}

		return std::lexicographical_compare(begin1,end1,begin2,end2,chars_less_insensitive);
	} else if(numeric_sort_.count(column) == 1) {
		const std::string& item1 = font::del_tags(row1.fields[column]);
		const std::string& item2 = font::del_tags(row2.fields[column]);

		const char* a = item1.c_str();
		const char* b = item2.c_str();

		while(*a != 0 && !isdigit(*a)) {
			++a;
		}

		while(*b != 0 && !isdigit(*b)) {
			++b;
		}

		return atoi(a) > atoi(b);
	}

	const std::map<int,std::vector<int> >::const_iterator itor = pos_sort_.find(column);
	if(itor != pos_sort_.end()) {
		const std::vector<int>& pos = itor->second;
		if(row1.id >= pos.size()) {
			return false;
		}

		if(row2.id >= pos.size()) {
			return true;
		}

		return pos[row1.id] < pos[row2.id];
	}

	return false;
}