Beispiel #1
0
std::string& removeInPlace(std::string& str, const std::string::value_type ch, std::string::size_type start)
{
	return replaceInPlace(str, ch, 0, start);
}
Beispiel #2
0
std::string replace(const std::string& str, const std::string::value_type from, const std::string::value_type to, std::string::size_type start)
{
	std::string result(str);
	replaceInPlace(result, from, to, start);
	return result;
}
Beispiel #3
0
std::string remove(const std::string& str, const std::string::value_type ch, std::string::size_type start)
{
	std::string result(str);
	replaceInPlace(result, ch, 0, start);
	return result;
}
void MyriadEnumSet::initialize(istream& in, size_t& currentLineNumber)
{
    enum READ_STATE { NOV, VLN, END };

    // reset old state
    reset();

    // reader variables
    READ_STATE currentState = NOV; // current reader machine state
    string currentLine; // the current line
    size_t currentItemIndex = 0; // current item index
    RegularExpression::MatchVec posVec; // a posVec for all regex matches

    // reader finite state machine
    while (currentState != END)
    {
        // read next line
        currentLine = "";
        getline(in, currentLine);

        // trim whitespace and unescape quotes
        trimInPlace(currentLine);

        // check if this line is empty or contains a single comment
        if (currentLine.empty() || currentLine.at(0) == '#')
        {
            if (!in.good()) // break on end of stream
            {
                if (currentState == VLN && currentItemIndex < _numberOfValues)
                {
                    throw DataException(format("line %z: Bad enum value line, should be: '%z ........... $value' (not enough items specified?)", currentLineNumber, currentItemIndex));
                }
                else
                {
                    currentState = END;
                }
            }

            currentLineNumber++;
            continue; // skip this line
        }

        if (currentState == NOV)
        {
            if (!headerLine1Format.match(currentLine, 0, posVec))
            {
                throw DataException(format("line %z: Bad header line, should be: '@numberofvalues = $N'", currentLineNumber));
            }

            I64 numberOfValues = NumberParser::parse64(currentLine.substr(posVec[1].offset, posVec[1].length).c_str());

            if (numberOfValues <= 0 && static_cast<size_t>(numberOfValues) > numeric_limits<size_t>::max())
            {
                throw DataException("Invalid number of values '" + toString(numberOfValues) +  "'");
            }

            _numberOfValues = numberOfValues;
            _values.resize(_numberOfValues);

            currentState = VLN;
        }
        else if (currentState == VLN)
        {
            if (!valueLineFormat.match(currentLine, 0, posVec))
            {
                throw DataException(format("line %z: Bad enum value line, should be: '%z ........... $value' (missing new line at the end of file?)", currentLineNumber, currentItemIndex));
            }

            String value = currentLine.substr(posVec[1].offset, posVec[1].length);
            replaceInPlace(value, "\\\"", "\"");
            replaceInPlace(value, "\\n", "\n");

            _values[currentItemIndex] = value;
            currentItemIndex++;

            if (currentItemIndex >= _numberOfValues)
            {
                currentState = END;
                currentItemIndex = 0;
            }
        }
    }

    // protect against unexpected reader state
    if (currentState != END)
    {
        throw RuntimeException("Unexpected state in CombinedPrFunction reader at line " + currentLineNumber);
    }
}