Skip to content

Commit

Permalink
Added two internal parser methods to the API.
Browse files Browse the repository at this point in the history
  • Loading branch information
fruxo committed Jun 16, 2014
1 parent f2d1f93 commit 6b32a96
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/tb/parser/tb_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,16 @@ bool is_pending_multiline(const char *str)
return str[0] == '\\' && str[1] == 0;
}

bool IsEndQuote(const char *buf_start, const char *buf, const char quote_type)
{
if (*buf != quote_type)
return false;
int num_backslashes = 0;
while (buf_start < buf && *(buf-- - 1) == '\\')
num_backslashes++;
return !(num_backslashes & 1);
}

// == Parser ============================================================================

TBParser::STATUS TBParser::Read(TBParserStream *stream, TBParserTarget *target)
Expand Down Expand Up @@ -320,19 +330,6 @@ void TBParser::OnLine(char *line, TBParserTarget *target)
}
}

/** Check if buf is pointing at a end quote. It may need to iterate
buf backwards toward buf_start to check if any preceding backslashes
make it a escaped quote (which should not be the end quote) */
bool IsEndQuote(const char *buf_start, const char *buf, const char quote_type)
{
if (*buf != quote_type)
return false;
int num_backslashes = 0;
while (buf_start < buf && *(buf-- - 1) == '\\')
num_backslashes++;
return !(num_backslashes & 1);
}

void TBParser::OnCompactLine(char *line, TBParserTarget *target)
{
target->Enter();
Expand Down
9 changes: 9 additions & 0 deletions src/tb/parser/tb_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@

namespace tb {

/** Unescape backslash codes. This is done in place using the string both as source
and destination. */
void UnescapeString(char *str);

/** Check if buf is pointing at a end quote. It may need to iterate
buf backwards toward buf_start to check if any preceding backslashes
make it a escaped quote (which should not be the end quote) */
bool IsEndQuote(const char *buf_start, const char *buf, const char quote_type);

class TBParserTarget
{
public:
Expand Down

0 comments on commit 6b32a96

Please sign in to comment.