예제 #1
0
 void CmdBase::PrintUsage(const Args& args, Str::StringRef syntax, Str::StringRef description) const {
     if(description.empty()) {
         Print("%s: %s %s", _("usage"), args.Argv(0).c_str(), syntax.c_str());
     } else {
         Print("%s: %s %s — %s", _("usage"), args.Argv(0).c_str(), syntax.c_str(), description.c_str());
     }
 }
예제 #2
0
	bool ParseCvarValue(Str::StringRef value, std::size_t& result) {
		if ( value.empty() || !Str::cisdigit(value[0]) )
		{
			return false;
		}
		result = std::stoul(value);
		return true;
	}
예제 #3
0
    void Field::RunCommand(Str::StringRef defaultCommand) {
        if (GetText().empty()) {
            return;
        }

        std::string current = Str::UTF32To8(GetText());
        if (current[0] == '/' or current[0] == '\\') {
            Cmd::BufferCommandText(current.c_str() + 1, true);
        } else if (defaultCommand.empty()) {
            Cmd::BufferCommandText(current, true);
        } else {
            Cmd::BufferCommandText(defaultCommand + " " + Cmd::Escape(current), true);
        }
        AddToHistory(hist, std::move(current));

        Clear();
    }
예제 #4
0
    std::string Escape(Str::StringRef text) {
        if (text.empty()) {
            return "\"\"";
        }

        bool escaped = false;
        bool maybeComment = false;
        std::string res = "\"";

        for (char c: text) {
            if (c == '\\') {
                res.append("\\\\");
            } else if (c == '\"') {
                res.append("\\\"");
            } else if (c == '$') {
                res.append("\\$");
            } else {
                if (Str::cisspace(c) || c == ';') {
                    escaped = true;
                }
                res.push_back(c);
            }

            if (maybeComment && (c == '/' || c == '*')) {
                escaped = true;
                maybeComment = false;
            } else if (c == '/') {
                maybeComment = true;
            } else {
                maybeComment = false;
            }
        }

        if (escaped) {
            res += "\"";
        } else {
            res.erase(0, 1);
        }

        return res;
    }