00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef Parser_conf_Replacements_H
00025 #define Parser_conf_Replacements_H
00026
00027
00028 #include <vector>
00029
00030
00031 #include "conf/conf.h"
00032 #include "text/RegExp.h"
00033
00034 using namespace Tanl::Text;
00035
00036 namespace IXE {
00037
00041 class Pattern2 : public RegExp::Pattern
00042 {
00043 public:
00044 Pattern2() { }
00045 Pattern2(std::string& pattern, int cflags = 0) :
00046 RegExp::Pattern(pattern, cflags),
00047 pattern(pattern)
00048 { }
00049
00053 Pattern2& operator =(Pattern2 const& other) {
00054 if (this != &other) {
00055 this->Pattern::operator=(other);
00056 pattern = other.pattern;
00057 }
00058 return *this;
00059 }
00060
00061 std::string pattern;
00062 };
00063
00073 typedef std::vector<std::pair<Pattern2, std::string> > Replacements;
00074
00075
00076
00077 template<>
00078 void Var<Replacements>::serialize(std::ostream& os) { }
00079
00080 template<>
00081 class conf<Replacements> : public Var<Replacements>
00082 {
00083 public:
00084
00085 conf<Replacements>(char const* name) : Var<value_type>(name) { }
00086
00087 protected:
00094 virtual void parseValue(char const*& line) {
00095 char const* tok = next_token_line(line, " \r\t");
00096 std::string pattern(tok, line - tok);
00097 while ((tok = next_token_line(line, " \r\t")))
00098 value.push_back(std::make_pair(Pattern2(pattern, RegExp::Anchored), std::string(tok, line - tok)));
00099 }
00100 virtual void reset() { }
00101
00102 void serialize(std::ostream& os)
00103 {
00104 FOR_EACH (Replacements, value, fit)
00105 os << name() << "\t\"" << fit->first.pattern << "\" " << fit->second << std::endl;
00106 }
00107
00108 };
00109
00110 }
00111
00112 #endif