- Applied patch to fix bug #581, in which backslashes in annotations and
  descriptions caused problems (thanks to Itay Perl).
- Corrected unit tests that were shown to be incorrect, after the patch
  corrected other behavior.
This commit is contained in:
Paul Beckingham 2010-12-23 23:14:20 -05:00
parent 1d4c79b897
commit 595dd9f3f4
5 changed files with 48 additions and 61 deletions

View file

@ -213,66 +213,51 @@ bool Nibbler::getUntilEOS (std::string& result)
bool Nibbler::getQuoted (
char c,
std::string& result,
bool unescape /* = true */,
bool quote /* = false */)
{
if (mCursor < mLength)
bool inquote = false;
bool inescape = false;
char current = 0;
char previous = 0;
result = "";
if (mCursor >= mLength ||
mInput[mCursor] != c)
{
if (mInput[mCursor] != c)
return false;
return false;
}
result = "";
bool inquote = false;
char current = 0;
char previous = 0;
for (std::string::size_type i = mCursor; i < mLength; ++i)
{
previous = current;
current = mInput[i];
// '"'
// p c
// - -
// '
// ' "
// " '
for (std::string::size_type i = mCursor; i < mLength; ++i)
if (current == '\\' && !inescape)
{
previous = current;
current = mInput[i];
inescape = true;
continue;
}
if (current == c)
if (current == c && !inescape)
{
if (quote)
result += current;
if (!inquote)
{
if (previous == '\\')
{
if (!unescape)
result += previous;
result += current;
}
else
{
if (!inquote)
{
inquote = true;
if (quote)
result += current;
}
else
{
if (quote)
result += current;
mCursor = i + 1;
return true;
}
}
}
else if (current == '\\')
{
// NOP
inquote = true;
}
else
{
result += current;
mCursor = i + 1;
return true;
}
}
else
{
result += current;
inescape = false;
}
}
return false;

View file

@ -47,7 +47,7 @@ public:
bool getUntilEOL (std::string&);
bool getUntilEOS (std::string&);
bool getQuoted (char, std::string&, bool unescape = true, bool quote = false);
bool getQuoted (char, std::string&, bool quote = false);
bool getInt (int&);
bool getUnsignedInt (int&);
bool getNumber (double&);

View file

@ -258,13 +258,13 @@ int main (int argc, char** argv)
n = Nibbler ("name:\"&quot;\"");
a7.parse (n);
t.is (a7.composeF4 (), "name:\"&dquot;\"",
"Att::parse (name:\"&quot;\")");
t.is (a7.composeF4 (), "name:\"'\"",
"Att::parse (name:\"'\")");
n = Nibbler ("name:\"&tab;&quot;&comma;&open;&close;&colon;\"");
a7.parse (n);
t.is (a7.composeF4 (), "name:\"&tab;&dquot;,&open;&close;:\"",
"Att::parse (name:\"&tab;&quot;,&open;&close;:\")");
t.is (a7.composeF4 (), "name:\"&tab;',&open;&close;:\"",
"Att::parse (name:\"&tab;',&open;&close;:\")");
n = Nibbler ("total gibberish");
good = true;

View file

@ -190,23 +190,23 @@ int main (int argc, char** argv)
t.notok (n.getQuoted ('\'', s), " 'x' : getQuoted (''') -> false");
n = Nibbler ("\"one\\\"two\"");
t.notok (n.getQuoted ('\'', s), "\"one\\\"two\" : getQuoted (''') -> false"); // 86
t.notok (n.getQuoted ('\'', s), "\"one\\\"two\" : getQuoted (''') -> false"); // 86
n = Nibbler ("\"one\\\"two\"");
t.ok (n.getQuoted ('"', s, false, false), "\"one\\\"two\" : getQuoted ('\"', false, false) -> true"); // 87
t.is (s, "one\\\"two", "getQuoted ('\"', false, false) -> one\\\"two"); // 88
t.ok (n.getQuoted ('"', s, false), "\"one\\\"two\" : getQuoted ('\"', false, false) -> true"); // 87
t.is (s, "one\"two", "getQuoted ('\"', false) -> one\"two"); // 88
n = Nibbler ("\"one\\\"two\"");
t.ok (n.getQuoted ('"', s, false, true), "\"one\\\"two\" : getQuoted ('\"', false, true) -> true"); // 89
t.is (s, "\"one\\\"two\"", "getQuoted ('\"', false, true) -> \"one\\\"two\""); // 90
t.ok (n.getQuoted ('"', s, true), "\"one\\\"two\" : getQuoted ('\"', false, true) -> true"); // 89
t.is (s, "\"one\"two\"", "getQuoted ('\"', true) -> \"one\"two\""); // 90
n = Nibbler ("\"one\\\"two\"");
t.ok (n.getQuoted ('"', s, true, false), "\"one\\\"two\" : getQuoted ('\"', true, false) -> true"); // 91
t.is (s, "one\"two", "getQuoted ('\"', true, false) -> one\"two"); // 92
t.ok (n.getQuoted ('"', s, false), "\"one\\\"two\" : getQuoted ('\"', true, false) -> true"); // 91
t.is (s, "one\"two", "getQuoted ('\"', false) -> one\"two"); // 92
n = Nibbler ("\"one\\\"two\"");
t.ok (n.getQuoted ('"', s, true, true), "\"one\\\"two\" : getQuoted ('\"', true, true) -> true"); // 93
t.is (s, "\"one\"two\"", "getQuoted ('\"', true, true) -> \"one\"two\""); // 94
t.ok (n.getQuoted ('"', s, true), "\"one\\\"two\" : getQuoted ('\"', true, true) -> true"); // 93
t.is (s, "\"one\"two\"", "getQuoted ('\"', true) -> \"one\"two\""); // 94
// bool getInt (int&);