added unistring type, working on parser
This commit is contained in:
parent
cbb64f82e5
commit
ed03f19a6d
@ -1,21 +1,26 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h> /* isspace() */
|
||||
#include "parse-input.h"
|
||||
using namespace std;
|
||||
|
||||
#define SET_ERROR(err, args...) \
|
||||
sprintf(errstr, err " at line %d, column %d", ##args, lineno, colno)
|
||||
do { \
|
||||
error = true; \
|
||||
sprintf(errstr, err " at line %d, column %d", ##args, lineno, colno); \
|
||||
} while(0)
|
||||
|
||||
void parse_input(refptr< vector<unichar_t> > ucs)
|
||||
{
|
||||
enum State { INITIAL, LB, SECTION_NAME, RB };
|
||||
enum State { INITIAL, SECTION_NAME, RULES };
|
||||
State state = INITIAL;
|
||||
int lineno = 1;
|
||||
int colno = 1;
|
||||
bool error = false;
|
||||
char errstr[200];
|
||||
unistring build_str;
|
||||
|
||||
for (int i = 0, sz = ucs->size(); i < sz; i++)
|
||||
{
|
||||
@ -34,18 +39,36 @@ void parse_input(refptr< vector<unichar_t> > ucs)
|
||||
case INITIAL:
|
||||
if (c == '[')
|
||||
{
|
||||
state = LB;
|
||||
state = SECTION_NAME;
|
||||
build_str = "";
|
||||
}
|
||||
else if (isspace(c))
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
error = true;
|
||||
SET_ERROR("Unexpected character 0x%x (%c) in input file",
|
||||
c, c);
|
||||
}
|
||||
break;
|
||||
case SECTION_NAME:
|
||||
switch (c)
|
||||
{
|
||||
case ']':
|
||||
if (build_str == "rules")
|
||||
{
|
||||
state = RULES;
|
||||
}
|
||||
else
|
||||
{
|
||||
SET_ERROR("Unknown section name");
|
||||
}
|
||||
break;
|
||||
case '\n':
|
||||
SET_ERROR("Unterminated section header");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
27
unicode.cc
Normal file
27
unicode.cc
Normal file
@ -0,0 +1,27 @@
|
||||
|
||||
#include "unicode.h"
|
||||
#include <string.h>
|
||||
|
||||
unistring & unistring::operator=(const char * ascii_str)
|
||||
{
|
||||
chars.clear();
|
||||
const char * as_ptr = ascii_str;
|
||||
while (*as_ptr != '\0')
|
||||
{
|
||||
chars.push_back(*as_ptr);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool unistring::operator==(const char * ascii_str)
|
||||
{
|
||||
int len = chars.size();
|
||||
if (len != strlen(ascii_str))
|
||||
return false;
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if (chars[i] != ascii_str[i])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user