void parsePassword(const Common::UString &arg, std::vector<byte> &password) { const size_t length = arg.size(); password.clear(); password.reserve(length / 2); size_t i = 0; byte c = 0x00; for (Common::UString::iterator s = arg.begin(); s != arg.end(); ++s, i++) { byte d = 0; if (*s >= '0' && *s <= '9') d = *s - '0'; else if (*s >= 'a' && *s <= 'f') d = *s - 'a' + 10; else if (*s >= 'A' && *s <= 'F') d = *s - 'A' + 10; else throw Common::Exception("0x%08X is not a valid hex digit", (uint) *s); if ((i % 2) == 1) { c |= d; password.push_back(c); c = 0x00; } else c |= d << 4; } }
uint32 ConsoleWindow::findWordStart(const Common::UString &line, uint32 pos) { Common::UString::iterator it = line.getPosition(pos); if ((it == line.end()) || (*it == ' ')) return 0; while ((it != line.begin()) && (*it != ' ')) --it; if (*it == ' ') ++it; return line.getPosition(it); }
Common::UString FileTypeManager::getExtension(FileType type) { buildTypeLookup(); Common::UString ext; TypeLookup::const_iterator t = _typeLookup.find(type); if (t != _typeLookup.end()) ext = t->second->extension; if (ext.beginsWith(".")) ext.erase(ext.begin()); return ext; }
// "Elfland: The Woods" -> "The Woods" Common::UString Area::createDisplayName(const Common::UString &name) { for (Common::UString::iterator it = name.begin(); it != name.end(); ++it) { if (*it == ':') { if (++it == name.end()) break; if (*it == ' ') if (++it == name.end()) break; return Common::UString(it, name.end()); } } return name; }
static bool parseOption(const Common::UString &arg, Common::UString &key) { if (arg.size() < 2) { warning("Unrecognized command line argument \"%s\"", arg.c_str()); return false; } Common::UString::iterator start = arg.begin(); ++start; Common::UString value; if (*start == '-') { // Long option ++start; Common::UString::iterator e = arg.findFirst('='); if (e != arg.end()) { key = arg.substr(start, e++); value = arg.substr(e, arg.end()); } else key = arg.substr(start, arg.end()); } else { // Short option key = convertShortToLongOption(*start++); value = arg.substr(start, arg.end()); } if (key.empty()) { warning("Unrecognized command line argument \"%s\"", arg.c_str()); return false; } if (value.empty()) return true; if (!setOption(key, value)) return false; return true; }
Common::UString createDisplayName(const Common::UString &name) { bool inBrace = false; Common::UString displayName; for (Common::UString::iterator it = name.begin(); it != name.end(); ++it) { if (*it == '{') { inBrace = true; continue; } if (*it == '}') { inBrace = false; continue; } if (!inBrace) displayName += *it; } return displayName; }
Common::UString XMLWriter::escape(const Common::UString &str) { Common::UString escaped; for (Common::UString::iterator s = str.begin(); s != str.end(); ++s) { uint32 c = *s; if (c == '\"') escaped += """; else if (c == '\'') escaped += "'"; else if (c == '&') escaped += "&"; else if (c == '<') escaped += "<"; else if (c == '>') escaped += ">"; else escaped += c; } return escaped; }
void Text::drawLine(const Common::UString &line, ColorPositions::const_iterator color, size_t position) { Font &font = _font.getFont(); // Horizontal Align glTranslatef(roundf((_width - font.getLineWidth(line)) * _halign), 0.0f, 0.0f); // Draw line for (Common::UString::iterator s = line.begin(); s != line.end(); ++s, position++) { // If we have color changes, apply them while ((color != _colors.end()) && (color->position <= position)) { if (color->defaultColor) glColor4f(_r, _g, _b, _a); else glColor4f(color->r, color->g, color->b, color->a); ++color; } font.draw(*s); } }
void TTFFont::buildChars(const Common::UString &str) { for (Common::UString::iterator c = str.begin(); c != str.end(); ++c) addChar(*c); rebuildPages(); }