ionflux.org | Impressum

StringFilter.hpp

Go to the documentation of this file.
00001 #ifndef IONFLUX_TOOLS_STRINGFILTER
00002 #define IONFLUX_TOOLS_STRINGFILTER
00003 /* ==========================================================================
00004  * Ionflux Tools
00005  * Copyright (c) 2004 Joern P. Meier
00006  * mail@ionflux.org
00007  * --------------------------------------------------------------------------
00008  * StringFilter.hpp                    String filter.
00009  * ==========================================================================
00010  * 
00011  * This file is part of Ionflux Tools.
00012  * 
00013  * Ionflux Tools is free software; you can redistribute it and/or modify it 
00014  * under the terms of the GNU General Public License as published by the Free
00015  * Software Foundation; either version 2 of the License, or (at  your option)
00016  * any later version.
00017  * 
00018  * Ionflux Tools is distributed in the hope that it will be useful, but 
00019  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00020  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00021  * for more details.
00022  * 
00023  * You should have received a copy of the GNU General Public License
00024  * along with Ionflux Tools; if not, write to the Free Software Foundation, 
00025  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00026  * 
00027  * ========================================================================== */
00028 
00029 #include <string>
00030 #include <iostream>
00031 #include <sstream>
00032 #include <vector>
00033 #include <map>
00034 #include "ionflux/Reporter.hpp"
00035 #include "ionflux/Tokenizer.hpp"
00036 #include "ionflux/StringManipulator.hpp"
00037 
00038 namespace Ionflux
00039 {
00040 
00041 namespace Tools
00042 {
00043 
00052 
00053 struct StringFilterFunction
00054 {
00056     std::string func;
00058     std::vector<std::string> args;
00060     StringManipulator *manip;
00061 };
00062 
00064 struct StringManipulatorEntry
00065 {
00067     StringManipulator *manip;
00069     bool manage;
00070 };
00071 
00094 class StringFilter
00095 {
00096     protected:
00098         Ionflux::Tools::Reporter log;
00100         std::string filter;
00102         std::vector<StringFilterFunction *> functions;
00104         std::vector<StringManipulatorEntry> manipulators;
00106         std::map<std::string, StringManipulator*> manipIndex;
00108         Tokenizer tok;
00110         static StringUppercase STRINGMANIP_UPPERCASE;
00112         static StringLowercase STRINGMANIP_LOWERCASE;
00114         static StringErase STRINGMANIP_ERASE;
00116         static StringReplace STRINGMANIP_REPLACE;
00118         static StringTrim STRINGMANIP_TRIM;
00120         static StringLTrim STRINGMANIP_LTRIM;
00122         static StringRTrim STRINGMANIP_RTRIM;
00124         static StringTruncate STRINGMANIP_TRUNCATE;
00126         static StringCenter STRINGMANIP_CENTER;
00128         static StringMove STRINGMANIP_MOVE;
00130         static StringAppend STRINGMANIP_APPEND;
00132         static StringInsert STRINGMANIP_INSERT;
00134         static StringNumFormat STRINGMANIP_NUMFORMAT;
00136         static StringTranslate STRINGMANIP_TRANSLATE;
00138         static StringSubstr STRINGMANIP_SUBSTR;
00140         static StringLPad STRINGMANIP_LPAD;
00142         static StringRPad STRINGMANIP_RPAD;
00144         static StringSWrap STRINGMANIP_SWRAP;
00146         static StringXMLEscape STRINGMANIP_XMLESCAPE;
00148         static StringURLEncode STRINGMANIP_URLENCODE;
00149         
00154         virtual void clearFunctions();
00155         
00160         virtual void clearManipulators();
00161         
00166         virtual void initTokenTypes();
00167         
00172         virtual void initManipulators();
00173         
00178         virtual void parse();
00179         
00190         virtual StringManipulator *getManipulator(const std::string& manipName);
00191         
00192     public:
00194         static const TokenType TT_FUNC_SEP;
00196         static const TokenType TT_FUNC_BRACKET_LEFT;
00198         static const TokenType TT_FUNC_BRACKET_RIGHT;
00200         static const TokenType TT_FUNC_ARG_DELIM;
00202         static const TokenType TT_FUNC_ARG_SEP;
00203         
00208         StringFilter();
00209         
00216         StringFilter(const std::string& initFilter);
00217         
00222         virtual ~StringFilter();
00223         
00230         virtual void setFilter(const std::string& newFilter);
00231         
00246         virtual void addManipulator(StringManipulator *newManip, bool manage);
00247         
00256         virtual std::string apply(const std::string& bytes);
00257         
00259         virtual void printDebugInfo();
00260         
00265         virtual Reporter &getLog();
00266 };
00267 
00269 
00270 }
00271 
00272 }
00273 
00277 #endif

Generated on Tue Mar 14 20:58:29 2006 for Ionflux Tools Class Library (iftools) by  doxygen 1.4.6