Beispiel #1
0
uint32 ConsoleWindow::findWordEnd(const Common::UString &line, uint32 pos) {
	Common::UString::iterator it = line.getPosition(pos);
	if ((it == line.end()) || (*it == ' '))
		return 0;

	while ((it != line.end()) && (*it != ' '))
		++it;

	return line.getPosition(it);
}
Beispiel #2
0
Common::UString Area::getName(const Common::UString &resRef) {
	try {
		Aurora::GFF3File are(resRef, Aurora::kFileTypeARE, MKTAG('A', 'R', 'E', ' '), true);

		Common::UString name = are.getTopLevel().getString("Name");
		if (!name.empty() && (*--name.end() == '\n'))
			name.erase(--name.end());

		return name;

	} catch (...) {
	}

	return "";
}
Beispiel #3
0
// "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;
}
Beispiel #4
0
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;
    }
}
Beispiel #5
0
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;
}
Beispiel #6
0
UString FilePath::relativize(const UString &basePath, const UString &path) {
	const Common::UString normPath = normalize(path, false);
	const Common::UString normBase = normalize(basePath, false);

	UString relative = "";

	if (normPath.beginsWith(normBase))
		relative = normPath.substr(normPath.getPosition(normBase.size() + 1), normPath.end());

	return relative;
}
Beispiel #7
0
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;
}
Beispiel #8
0
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 += "&quot;";
		else if (c == '\'')
			escaped += "&apos;";
		else if (c == '&')
			escaped += "&amp;";
		else if (c == '<')
			escaped += "&lt;";
		else if (c == '>')
			escaped += "&gt;";
		else
			escaped += c;

	}

	return escaped;
}
Beispiel #9
0
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);
	}
}
Beispiel #10
0
void TTFFont::buildChars(const Common::UString &str) {
	for (Common::UString::iterator c = str.begin(); c != str.end(); ++c)
		addChar(*c);

	rebuildPages();
}