Beispiel #1
0
	bool ConfManager::HandleLine(const string& line)
	{
		regex matchComment("^\\s*\\#(.*)\\s*$");
		regex matchEmpty("^\\s*$");
		regex matchSection("^\\s*\\[(.*)\\]\\s*$");
		regex matchKeyValue("^\\s*(\\S+)\\s*\\=\\s*(.*)\\s*$");
		cmatch match;
		if(regex_match(line.c_str(), match, matchComment)
		|| regex_match(line.c_str(), match, matchEmpty)){
			return true;
		}
		if(regex_match(line.c_str(), match, matchSection)){
			curSection_ = match[1];
			return true;
		}
		if(regex_match(line.c_str(), match, matchKeyValue)){
			if(curSection_ != ""){
				confItemMap_[curSection_ + "." + match[1]] = match[2];
			}
			return true;
		}

		return false;
	}
Beispiel #2
0
void find_comments_and_literals(char * orig_buffer, char * buffer, items * Items, int add_literals, int add_comments, int add_backslashes)
{
    int i, n, end;

    n = strlen(buffer);

    for (i = 0; i < n;)
    {
        switch (buffer[i])
        {
        case '\"':
            end = match_symbol(buffer, i, '\"');
            assert(end > 0);
            if (add_literals)
                add_item(Items, i, end - 1, STRING);
            i = end;
            break;

        case '\'':
            end = match_symbol(buffer, i, '\'');
            assert(end > 0);
            if (add_literals)
                add_item(Items, i, end - 1, LITERAL);
            i = end;
            break;

        case '/':
            if (buffer[i + 1] == '*')
            {
                if (flag_nested_comments)
                {
                    end = match_bracket(orig_buffer, buffer, n, i, "/*", "*/");
                    if (end < 0)
                    {
                        printf("No matching closing comment\n");
                        exit(-1);
                    }
                    if (add_comments)
                        add_item(Items, i, end + 1, COMMENT);
                    i = end + 2;
                }
                else
                {
                    end = matchComment(buffer, i, Items);
                    assert(end > 0);
                    if (add_comments)
                        add_item(Items, i, end - 1, COMMENT);
                    i = end;
                }
            }
            else
                i++;
            break;

        case '\\':
            if (add_backslashes)
                add_item(Items, i, i + 1, ESCSEQ);
            i += 2;
            break;

        default:
            i++;
            break;
        }

        if (i < 0)
        {
            printf("Internal error detected\n");
            exit(-1);
        }
    }

}