Ejemplo n.º 1
0
// check if a specific character can be part of a header
bool ASBase::isCharPotentialHeader(const string& line, size_t i) const
{
	assert(!isWhiteSpace(line[i]));
	char prevCh = ' ';
	if (i > 0) prevCh = line[i - 1];
	if (!isLegalNameChar(prevCh) && isLegalNameChar(line[i]))
		return true;
	return false;
}
Ejemplo n.º 2
0
// get the current word on a line
// index must point to the beginning of the word
string ASBase::getCurrentWord(const string& line, size_t index) const
{
    assert(isCharPotentialHeader(line, index));
    size_t lineLength = line.length();
    size_t i;
    for(i = index; i < lineLength; i++) {
        if(!isLegalNameChar(line[i])) break;
    }
    return line.substr(index, i - index);
}
Ejemplo n.º 3
0
// get the current word on a line
// i must point to the beginning of the word
string ASBase::getCurrentWord(const string& line, size_t charNum) const
{
	assert(isCharPotentialHeader(line, charNum));
	size_t lineLength = line.length();
	size_t i;
	for (i = charNum; i < lineLength; i++)
	{
		if (!isLegalNameChar(line[i]))
			break;
	}
	return line.substr(charNum, i - charNum);
}
Ejemplo n.º 4
0
// check if a specific line position contains a keyword.
bool ASBase::findKeyword(const string& line, int i, const string& keyword) const
{
    assert(isCharPotentialHeader(line, i));
    // check the word
    const size_t keywordLength = keyword.length();
    const size_t wordEnd = i + keywordLength;
    if(wordEnd > line.length()) return false;
    if(line.compare(i, keywordLength, keyword) != 0) return false;
    // check that this is not part of a longer word
    if(wordEnd == line.length()) return true;
    if(isLegalNameChar(line[wordEnd])) return false;
    // is not a keyword if part of a definition
    const char peekChar = peekNextChar(line, wordEnd - 1);
    if(peekChar == ',' || peekChar == ')') return false;
    return true;
}
Ejemplo n.º 5
0
// check if a specific line position contains a header.
const string* ASBase::findHeader(const string& line, int i,
                                 const vector<const string*>* possibleHeaders) const
{
	assert(isCharPotentialHeader(line, i));
	// check the word
	size_t maxHeaders = possibleHeaders->size();
	for (size_t p = 0; p < maxHeaders; p++)
	{
		const string* header = (*possibleHeaders)[p];
		const size_t wordEnd = i + header->length();
		if (wordEnd > line.length())
			continue;
		int result = (line.compare(i, header->length(), *header));
		if (result > 0)
			continue;
		if (result < 0)
			break;
		// check that this is not part of a longer word
		if (wordEnd == line.length())
			return header;
		if (isLegalNameChar(line[wordEnd]))
			continue;
		const char peekChar = peekNextChar(line, wordEnd - 1);
		// is not a header if part of a definition
		if (peekChar == ',' || peekChar == ')')
			break;
		// the following accessor definitions are NOT headers
		// goto default; is NOT a header
		// default(int) keyword in C# is NOT a header
		if ((header == &AS_GET
		        || header == &AS_SET
		        || header == &AS_DEFAULT)
		        && (peekChar == ';' || peekChar == '(' || peekChar == '='))
			break;
		return header;
	}
	return nullptr;
}