Exemple #1
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;
}
Exemple #2
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;
}
Exemple #3
0
Common::UString ConsoleWindow::getHighlight() const {
	if ((_highlightLength == 0) || (_highlightY >= kConsoleLines))
		return "";

	int32 start = _highlightX;
	int32 end   = _highlightX + _highlightLength;

	if (start > end)
		SWAP(start, end);

	Common::UString line;
	if (_highlightY == 0) {
		start = start - _prompt->get().size();
		end   = end   - _prompt->get().size();
		line  = _input->get();
	} else
		line = _lines[_lines.size() - _highlightY]->get();

	start = MAX(0, start);
	end   = MAX(0, end  );

	return line.substr(line.getPosition(start), line.getPosition(end));
}