7#include "PvlTokenizer.h" 
   14#include "IException.h" 
   49    QString upTerminator(terminator.toUpper());
 
   52    bool newlineFound = 
false;
 
  105      if(t.keyUpper() == upTerminator) {
 
  120        if(t.keyUpper() == upTerminator) 
return;
 
  137          s = ReadToParen(stream);
 
  151          s = ReadToBrace(stream);
 
  165          s = ReadToDoubleQuote(stream);
 
  179          s = ReadToSingleQuote(stream);
 
 
  210    while((c != 
'\r') && (c != 
'\n') && (c != 
'\0')) {
 
  214      if(c == EOF) 
return s;
 
 
  238    while((!isspace(c)) && (c != 
'\0') && (c != 
'=')) {
 
  242      if(c == EOF) 
return s;
 
 
  258    bool foundNewline = 
false;
 
  263    while((isspace(c)) || (c == 
'\0')) {
 
 
  277  QString PvlTokenizer::ReadToDoubleQuote(std::istream &stream) {
 
  294    int pos = s.indexOf(QRegExp(
"[\\n\\r]"));
 
  296      QString first = s.mid(0, pos);
 
  297      bool addspace = 
false;
 
  298      if(first[pos-1] == 
' ') addspace = 
true;
 
  299      first = first.remove(QRegExp(
"[\\s]*$"));
 
  300      QString second = s.mid(pos + 1);
 
  301      if(second[0] == 
' ') addspace = 
true;
 
  302      if(second[0] == 
'\r') addspace = 
true;
 
  303      if(second[0] == 
'\n') addspace = 
true;
 
  304      second = second.remove(QRegExp(
"^[\\s]*"));
 
  305      if(second[0] == 
',') addspace = 
false;
 
  307      if(addspace) s += 
" ";
 
  310      pos = s.indexOf(QRegExp(
"[\\n\\r]"));
 
  315  QString PvlTokenizer::ReadToSingleQuote(std::istream &stream) {
 
  332    int pos = s.indexOf(QRegExp(
"[\\n\\r]"));
 
  334      QString first = s.mid(0, pos);
 
  335      bool addspace = 
false;
 
  336      if(first[pos-1] == 
' ') addspace = 
true;
 
  337      first = first.remove(QRegExp(
"[\\s]*$"));
 
  338      QString second = s.mid(pos + 1);
 
  339      if(second[0] == 
' ') addspace = 
true;
 
  340      if(second[0] == 
'\r') addspace = 
true;
 
  341      if(second[0] == 
'\n') addspace = 
true;
 
  342      second = second.remove(QRegExp(
"^[\\s]*"));
 
  343      if(second[0] == 
',') addspace = 
false;
 
  345      if(addspace) s += 
" ";
 
  347      pos = s.indexOf(QRegExp(
"[\\n\\r]"));
 
  353  QString PvlTokenizer::ReadToParen(std::istream &stream) {
 
  356    int leftParenCount = 1;
 
  367          s += 
"\"" + ReadToDoubleQuote(stream) + 
"\"";
 
  369        catch(IException &) {
 
  376          s += 
"'" + ReadToSingleQuote(stream) + 
"'";
 
  378        catch(IException &) {
 
  385        if(leftParenCount > 0) s += (char) c;
 
  389        if(c == 
'(') leftParenCount++;
 
  392    while(leftParenCount > 0);
 
  397  QString PvlTokenizer::ReadToBrace(std::istream &stream) {
 
  400    int leftBraceCount = 1;
 
  411          s += 
"\"" + ReadToDoubleQuote(stream) + 
"\"";
 
  413        catch(IException &e) {
 
  420          s += 
"'" + ReadToSingleQuote(stream) + 
"'";
 
  422        catch(IException &) {
 
  429        if(leftBraceCount > 0) s += (char) c;
 
  433        if(c == 
'{') leftBraceCount++;
 
  436    while(leftBraceCount > 0);
 
  450    stringstream stream(cl.toLatin1().data());
 
  458        s += ReadToDoubleQuote(stream);
 
  461        s += ReadToSingleQuote(stream);
 
  465        s += ReadToParen(stream);
 
  470        s += ReadToBrace(stream);
 
 
  487  vector<Isis::PvlToken> & PvlTokenizer::GetTokenList() {
 
  498    if(isprint(c)) 
return;
 
  499    if(isspace(c)) 
return;
 
  500    if(c == 
'\0') 
return;
 
  502    QString message = 
"ASCII data expected but found unprintable (binary) data";
 
 
@ Unknown
A type of error that cannot be classified as any of the other error types.
 
Container for Keyword-value pair.
 
bool SkipWhiteSpace(std::istream &stream)
Skips over whitespace so long as it is not inside quotes.
 
void Clear()
Empties the token list.
 
~PvlTokenizer()
Destroys the Tokenizer object and token list.
 
QString ReadToken(std::istream &stream)
Reads and returns a token from the stream.
 
QString ReadComment(std::istream &stream)
Reads and returns a comment from the stream.
 
std::vector< Isis::PvlToken > tokens
The array of Tokens parse out of the stream.
 
void ValidateCharacter(int c)
Make sure a character is valid printable (non-control) character.
 
void ParseCommaList(Isis::PvlToken &t, const QString &cl)
This routine parses a QString containing a comma separated list.
 
PvlTokenizer()
Constructs a Tokenizer with an empty token list.
 
void Load(std::istream &stream, const QString &terminator="END")
Loads the Token list from a stream.
 
QString MissingDelimiter(const char delimiter)
This error should be used when a delimiter is missing.
 
QString KeywordValueBad(const QString &key)
This error should be used when a supplied keyword does not appear in the list (e.g....
 
This is free and unencumbered software released into the public domain.
 
Namespace for the standard library.