Source-highlight Library
|
00001 // 00002 // C++ Interface: textstyle 00003 // 00004 // Description: 00005 // 00006 // 00007 // Author: Lorenzo Bettini <http://www.lorenzobettini.it>, (C) 2005-2009 00008 // 00009 // Copyright: See COPYING file that comes with this distribution 00010 // 00011 // 00012 00013 #ifndef _TEXTSTYLE_H_ 00014 #define _TEXTSTYLE_H_ 00015 00016 #include <string> 00017 #include <vector> 00018 #include <map> 00019 #include <boost/regex.hpp> 00020 00021 namespace srchilite { 00022 00023 #define STYLE_VAR_TEXT "$style" // the text of the style variable 00024 #define TEXT_VAR_TEXT "$text" // the text of the text variable 00025 #define STYLE_VAR "\\" STYLE_VAR_TEXT // the name of the style variable as regexp 00026 #define TEXT_VAR "\\" TEXT_VAR_TEXT // the name of the text variable as regexp 00027 00028 typedef std::map<std::string, std::string> SubstitutionMapping; 00029 00036 class TextStyle { 00037 private: 00038 typedef std::vector<std::string> StringVector; 00039 typedef std::vector<int> IndexVector; 00040 typedef std::map<std::string, IndexVector> SubstitutionIndexes; 00041 00043 boost::regex var_exp; 00044 00045 std::string repr; 00046 00048 StringVector parts; 00049 00051 SubstitutionIndexes substitutions; 00052 00054 bool invalid; 00055 00056 void build_vectors(); 00057 00058 public: 00065 TextStyle(const std::string &s = "", const char **vars = 0); 00066 ~TextStyle(); 00067 00074 std::string output(const std::string &text, const std::string &style = ""); 00075 00081 std::string output(SubstitutionMapping &subst_map); 00082 00088 std::string subst_style(const std::string &style = ""); 00089 00093 const std::string &toString() const { 00094 return repr; 00095 } 00096 00104 TextStyle compose(const TextStyle &inner); 00105 00110 void update(const TextStyle &inner); 00111 00116 void update(const std::string &inner); 00117 00123 void update(const std::string &text, const std::string &style); 00124 00128 bool containsStyleVar() const; 00129 00133 bool empty() const; 00134 }; 00135 00136 } 00137 00138 #endif /*_TEXTSTYLE_H_*/