Beispiel #1
0
/** @param flags the flags to get the names for
    @returns QStringList of the flags' names
*/
QStringList PartitionTable::flagNames(Flags flags)
{
    QStringList rval;

    int f = 1;

    QString s;
    while (!(s = flagName(static_cast<PartitionTable::Flag>(f))).isEmpty()) {
        if (flags & f)
            rval.append(s);

        f <<= 1;
    }

    return rval;
}
Beispiel #2
0
    void GTTParser::parseHeaderLine(const std::string& line) {
        const char *l = line.c_str();
        int i = 0, iValue = 0;
        BOOST_ASSERT(line.length() != 0);

        // Read flag name
        if (!isalpha(l[i]))
            throw ParserException("GTTParser", "flag_name should begin with [a-zA-Z] or we should add newline to end the header");
        i++;
        while (l[i] != ':') {
            if (!(isalnum(l[i]) || (l[i] == '_') || (l[i] == '-')))
                throw ParserException("GTTParser", "flag name should continue with [A-Za-z0-9-_]* or end with a space");
            i++;
        }
        std::string flagName(l, i);
        i++;

        // Skip spaces
        while (l[i] == ' ')
            i++;
        if (l[i] == 0)
            throw ParserException("GTTParser", "flag without value");

        // Read value
        iValue = i;
        while (l[i] != 0) {
            if (!(l[i] >= 32 && l[i] < 126))
                throw ParserException("GTTParser", "flag_value should consist of printable characters or just end with CRLF");
            i++;
        }
        std::string flagValue(l + iValue, i - iValue);

        // Content length
        if (!strcasecmp(flagName.c_str(), "content-length")) {
            if (currentPkt->size > 0)
                throw ParserException("GTTParser", "content-length flag has already appeared");
            currentPkt->size = String::toInt(flagValue.c_str());
            if (currentPkt->size <= 0)
                throw ParserException("GTTParser", "not valid body size, body size should be a positive integer");
        } else {
            currentPkt->headers[flagName] = flagValue;
        }
    }