The FileParser class

Design and implement a class called FileParser that scans a file for a given string tag followed by a character '=' and then reads and stores the string after the '=' either up to the first space character or, if an opening quote character '"' is present after '=', up to the closing quote character. The class functionality is to be able to detect all contexts such as tag = string or tag = "string" in a text file, store the strings and allow subsequent access to them.

The class should be declared in fileparser.h and implemented in fileparser.cxx. You can use the following header code for class declaration.

/***************************************************************
** Name:        fileparser.h
** Author:      Leo Liberti
** Source:      GNU C++
** Purpose:     www exploring topologizer - file parser (header)
** History:     060820 work started
****************************************************************/

#ifndef _WETFILEPARSERH
#define _WETFILEPARSERH

#include<string>
#include<vector>

class FileParserException {
 public:
  FileParserException();
  ~FileParserException();
};

class FileParser {

 public:
  FileParser();
  FileParser(std::string theFileName, std::string theParseTag);
  ~FileParser();

  void setFileName(std::string theFileName);
  std::string getFileName(void) const;
  void setParseTag(std::string theParseTag);
  std::string getParseTag(void) const;

  // parse the file and build the list of parsed strings
  void parse(void) throw(FileParserException);

  // get the number of parsed strings after parsing
  int getNumberOfParsedStrings(void) const;

  // get the i-th parsed string
  std::string getParsedString(int i) const throw(FileParserException);

 protected:
  std::string fileName;
  std::string parseTag;

  // compare two strings (case insensitive), return 0 if equal
  int compareCaseInsensitive(const std::string& s1, 
                             const std::string& s2) const;

  // return true if s2 is the tail (case insensitive) of string s1
  bool isTailCaseInsensitive(const std::string& s1, 
                             const std::string& s2) const;
  
 private:
  std::vector<std::string> parsedString;

};

#endif
Pay attention to the following details:



Subsections
Leo Liberti 2008-01-12