Based symbol_needs_quotes an invalid_chars (#386)
This commit is contained in:
parent
9edf413d9d
commit
48a5823181
2 changed files with 44 additions and 35 deletions
|
|
@ -490,42 +490,7 @@ commodity_t::operator bool() const
|
||||||
return this != pool().null_commodity;
|
return this != pool().null_commodity;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool commodity_t::symbol_needs_quotes(const string& symbol)
|
|
||||||
{
|
|
||||||
foreach (char ch, symbol)
|
|
||||||
if (std::isspace(ch) || std::isdigit(ch) || ch == '-' || ch == '.')
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
bool is_reserved_token(const char * buf)
|
|
||||||
{
|
|
||||||
switch (buf[0]) {
|
|
||||||
case 'a':
|
|
||||||
return std::strcmp(buf, "and") == 0;
|
|
||||||
case 'd':
|
|
||||||
return std::strcmp(buf, "div") == 0;
|
|
||||||
case 'e':
|
|
||||||
return std::strcmp(buf, "else") == 0;
|
|
||||||
case 'f':
|
|
||||||
return std::strcmp(buf, "false") == 0;
|
|
||||||
case 'i':
|
|
||||||
return std::strcmp(buf, "if") == 0;
|
|
||||||
case 'o':
|
|
||||||
return std::strcmp(buf, "or") == 0;
|
|
||||||
case 'n':
|
|
||||||
return std::strcmp(buf, "not") == 0;
|
|
||||||
case 't':
|
|
||||||
return std::strcmp(buf, "true") == 0;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void commodity_t::parse_symbol(std::istream& in, string& symbol)
|
|
||||||
{
|
|
||||||
// Invalid commodity characters:
|
// Invalid commodity characters:
|
||||||
// SPACE, TAB, NEWLINE, RETURN
|
// SPACE, TAB, NEWLINE, RETURN
|
||||||
// 0-9 . , ; : ? ! - + * / ^ & | =
|
// 0-9 . , ; : ? ! - + * / ^ & | =
|
||||||
|
|
@ -551,6 +516,41 @@ void commodity_t::parse_symbol(std::istream& in, string& symbol)
|
||||||
/* f0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
/* f0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool is_reserved_token(const char * buf)
|
||||||
|
{
|
||||||
|
switch (buf[0]) {
|
||||||
|
case 'a':
|
||||||
|
return std::strcmp(buf, "and") == 0;
|
||||||
|
case 'd':
|
||||||
|
return std::strcmp(buf, "div") == 0;
|
||||||
|
case 'e':
|
||||||
|
return std::strcmp(buf, "else") == 0;
|
||||||
|
case 'f':
|
||||||
|
return std::strcmp(buf, "false") == 0;
|
||||||
|
case 'i':
|
||||||
|
return std::strcmp(buf, "if") == 0;
|
||||||
|
case 'o':
|
||||||
|
return std::strcmp(buf, "or") == 0;
|
||||||
|
case 'n':
|
||||||
|
return std::strcmp(buf, "not") == 0;
|
||||||
|
case 't':
|
||||||
|
return std::strcmp(buf, "true") == 0;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool commodity_t::symbol_needs_quotes(const string& symbol)
|
||||||
|
{
|
||||||
|
foreach (char ch, symbol)
|
||||||
|
if (invalid_chars[static_cast<unsigned char>(ch)])
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void commodity_t::parse_symbol(std::istream& in, string& symbol)
|
||||||
|
{
|
||||||
istream_pos_type pos = in.tellg();
|
istream_pos_type pos = in.tellg();
|
||||||
|
|
||||||
char buf[256];
|
char buf[256];
|
||||||
|
|
|
||||||
9
test/regress/A28CF697.test
Normal file
9
test/regress/A28CF697.test
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
print
|
||||||
|
<<<
|
||||||
|
2010-02-05 * Flight SN2094
|
||||||
|
Assets:Rewards:Airmiles 125 "M&M"
|
||||||
|
Income:Rewards
|
||||||
|
>>>
|
||||||
|
2010/02/05 * Flight SN2094
|
||||||
|
Assets:Rewards:Airmiles 125 "M&M"
|
||||||
|
Income:Rewards
|
||||||
Loading…
Add table
Reference in a new issue