00001 #ifndef MODULESPARSER_H_
00002 #define MODULESPARSER_H_
00003 #include <string>
00004 #include <vector>
00005 #include <utility>
00006 #include <exception>
00007
00008 namespace modules{
00009 namespace parser{
00010 namespace errors{
00011
00012 class unmatched_parenthesis;
00013 }
00014 struct Constructor_t{
00015 std::string before;
00016 std::string inside;
00017 };
00018 }
00019 }
00020
00021 class modules::parser::errors::unmatched_parenthesis:public std::exception{
00022 public:
00023 unmatched_parenthesis(char open, char close):
00024 fOpen(open),fClose(close){};
00025 virtual const char* what() const throw()
00026 {
00027 std::string msg = "Unmatched parethensis '";
00028 msg+=fOpen;
00029 msg+="'. Looking for '";
00030 msg+=fClose;
00031 msg+="'.";
00032 return msg.c_str();
00033 }
00034 private:
00035 char fOpen, fClose;
00036
00037 };
00038
00039 namespace modules{
00040 namespace parser{
00041 const int max_line=2048;
00042
00043 int TokeniseByDelimiter(const std::string& input,
00044 std::vector<std::string>& output,
00045 const char* delim);
00046
00047 int TokeniseByWhiteSpace(const std::string& input,
00048 std::vector<std::string>& output);
00049
00050 std::string GetOneWord(const std::string& in,
00051 size_t start=0,
00052 size_t stop=std::string::npos);
00053
00054 Constructor_t ParseConstructor(const std::string& input, char open='(', char close=')')
00055 throw(modules::parser::errors::unmatched_parenthesis);
00056
00057 void ToCppValid(std::string& input);
00058 const std::string& ToCppValid(const std::string& input);
00059 void ReplaceAll(std::string& input, const std::string& search, const std::string& replace);
00060 void ReplaceWords(std::string& input, const std::string& search, const std::string& replace);
00061 const std::string& ReplaceAll(const std::string& input, const std::string& search, const std::string& replace);
00062 size_t RemoveWhitespace(std::string& input);
00063 size_t RemoveWhitespace(std::string& input, std::string::iterator start,std::string::iterator end);
00064 void TrimWhiteSpaceBeforeAfter(std::string& input);
00065
00066 bool IsWhitespace(char in);
00067 bool IsDigit(char in);
00068 bool IsDecimal(char in);
00069 bool IsFloatChar(char in);
00070 bool IsNotFloatChar(char in);
00071 bool IsNumber(const std::string& input);
00072 int GetNumber(const std::string& input);
00073 bool IsTrue(const std::string& input);
00074 double GetDouble(const std::string& input, size_t start=0, size_t stop=std::string::npos);
00075 bool iequals(const std::string& a, const std::string& b);
00076 bool iequals(const char a, const char b);
00077 }
00078 }
00079
00080 #endif //MODULESPARSER_H_