unsigned int CCategoryHandler::GetCategory(std::string name) { StringTrimInPlace(name); StringToLowerInPlace(name); if (name.empty()) return 0; // the empty category unsigned int cat = 0; GML_STDMUTEX_LOCK(cat); // GetCategory if (categories.find(name) == categories.end()) { // this category is yet unknown if (firstUnused >= CCategoryHandler::GetMaxCategories()) { // skip this category LOG_L(L_WARNING, "too many unit categories (%i), skipping %s", firstUnused, name.c_str()); cat = 0; } else { // create the category (bit field value) cat = (1 << firstUnused); //LOG_L(L_DEBUG, "New unit-category %s #%i", name.c_str(), firstUnused); } // if (cat == 0), this will prevent further warnings for this category categories[name] = cat; firstUnused++; } else { // this category is already known cat = categories[name]; } return cat; }
bool StringToBool(std::string str) { bool value = true; StringTrimInPlace(str); StringToLowerInPlace(str); // regex would probably be more appropriate, // but it is better not to rely on any external lib here if ( (str == "n") || (str == "no") || (str == "f") || (str == "false") || (str == "0") ) { value = false; } return value; }
std::string StringTrim(const std::string& str, const std::string& ws) { std::string copy(str); StringTrimInPlace(copy, ws); return copy; }