File indexing completed on 2025-02-02 04:57:57
0001 /* This is RTF to HTML converter, implemented as a text filter, generally. 0002 Copyright (C) 2003 Valentin Lavrinenko, vlavrinenko@users.sourceforge.net 0003 0004 available at http://rtf2html.sf.net 0005 0006 Original available under the terms of the GNU LGPL2, and according 0007 to those terms, relicensed under the GNU GPL2 for inclusion in Tellico */ 0008 0009 /*************************************************************************** 0010 * * 0011 * This program is free software; you can redistribute it and/or * 0012 * modify it under the terms of the GNU General Public License as * 0013 * published by the Free Software Foundation; either version 2 of * 0014 * the License or (at your option) version 3 or any later version * 0015 * accepted by the membership of KDE e.V. (or its successor approved * 0016 * by the membership of KDE e.V.), which shall act as a proxy * 0017 * defined in Section 14 of version 3 of the license. * 0018 * * 0019 * This program is distributed in the hope that it will be useful, * 0020 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0021 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0022 * GNU General Public License for more details. * 0023 * * 0024 * You should have received a copy of the GNU General Public License * 0025 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 0026 * * 0027 ***************************************************************************/ 0028 0029 #ifndef __RTF_KEYWORD_H__ 0030 #define __RTF_KEYWORD_H__ 0031 0032 0033 #include <string> 0034 #include <map> 0035 #include <ctype.h> 0036 #include <cstdlib> 0037 0038 namespace rtf { 0039 0040 class rtf_keyword{ 0041 public: 0042 enum keyword_type {rkw_unknown, 0043 rkw_b, rkw_bin, rkw_blue, rkw_brdrnone, rkw_bullet, 0044 rkw_cb, rkw_cell, rkw_cellx, rkw_cf, rkw_clbrdrb, rkw_clbrdrl, 0045 rkw_clbrdrr, rkw_clbrdrt, rkw_clvertalb, rkw_clvertalc, 0046 rkw_clvertalt, rkw_clvmgf, rkw_clvmrg, rkw_colortbl, 0047 rkw_emdash, rkw_emspace, rkw_endash, rkw_enspace, 0048 rkw_fi, rkw_field, rkw_filetbl, 0049 rkw_f, rkw_fprq, rkw_fcharset, 0050 rkw_fnil, rkw_froman, rkw_fswiss, rkw_fmodern, 0051 rkw_fscript, rkw_fdecor, rkw_ftech, rkw_fbidi, 0052 rkw_fldrslt, rkw_fonttbl, rkw_footer, rkw_footerf, rkw_fs, 0053 rkw_green, 0054 rkw_header, rkw_headerf, rkw_highlight, 0055 rkw_i, rkw_info, rkw_intbl, 0056 rkw_ldblquote, rkw_li, rkw_line, rkw_lquote, 0057 rkw_margl, 0058 rkw_object, 0059 rkw_paperw, rkw_par, rkw_pard, rkw_pict, rkw_plain, 0060 rkw_qc, rkw_qj, rkw_ql, rkw_qmspace, rkw_qr, 0061 rkw_rdblquote, rkw_red, rkw_ri, rkw_row, rkw_rquote, 0062 rkw_sa, rkw_sb, rkw_sect, rkw_softline, rkw_stylesheet, 0063 rkw_sub, rkw_super, 0064 rkw_tab, rkw_title, rkw_trleft, rkw_trowd, rkw_trrh, 0065 rkw_ul, rkw_ulnone 0066 }; 0067 private: 0068 class keyword_map : public std::map<std::string, keyword_type> 0069 { 0070 private: 0071 typedef std::map<std::string, keyword_type> base_class; 0072 public: 0073 keyword_map(); 0074 }; 0075 private: 0076 static keyword_map keymap; 0077 std::string s_keyword; 0078 keyword_type e_keyword; 0079 int param; 0080 char ctrl_chr; 0081 bool is_ctrl_chr; 0082 public: 0083 // iter must point after the backslash starting the keyword. We don't check it. 0084 // after construction, iter points at the char following the keyword 0085 template <class InputIter> explicit rtf_keyword(InputIter &iter); 0086 bool is_control_char() const 0087 { return is_ctrl_chr; } 0088 const std::string &keyword_str() const 0089 { return s_keyword; } 0090 keyword_type keyword() const 0091 { return e_keyword; } 0092 int parameter() const 0093 { return param; } 0094 char control_char() const 0095 { return ctrl_chr; } 0096 }; 0097 0098 template <class InputIter> 0099 rtf_keyword::rtf_keyword(InputIter &iter) 0100 { 0101 char curchar=*iter; 0102 is_ctrl_chr=!isalpha(curchar); 0103 0104 if (is_ctrl_chr) 0105 { 0106 ctrl_chr=curchar; 0107 ++iter; 0108 } 0109 else 0110 { 0111 do 0112 s_keyword+=curchar; 0113 while (isalpha(curchar=*++iter)); 0114 std::string param_str; 0115 while (isdigit(curchar)||curchar=='-') 0116 { 0117 param_str+=curchar; 0118 curchar=*++iter; 0119 } 0120 if (param_str.empty()) 0121 param=-1; 0122 else 0123 param=std::atoi(param_str.c_str()); 0124 if (curchar==' ') 0125 ++iter; 0126 keyword_map::iterator kw_pos=keymap.find(s_keyword); 0127 if (kw_pos==keymap.end()) 0128 e_keyword=rkw_unknown; 0129 else 0130 e_keyword=kw_pos->second; 0131 } 0132 } 0133 0134 } 0135 0136 #endif