1 #include "motoroutput.h"
3 #include "util_string.h"
7 #include "motorconst.h"
10 /* ============================================================ */
11 static uregex re_encode ("(<)|(>)|(&)|(\")|(')");
12 static uregex re_encode_br ("(<)|(>)|(&)|(\")|(')|(\n)");
13 static uregex re_encode_br_a ("(<)|(>)|(&)|(\")|(')|(\n)|(" rHTML ")");
15 MotorOutput* MotorOutput::outamp (uiterator b, uiterator e, uregex* re) {
18 while (b != e && usearch (b, e, m, *re)) {
19 if (b != m[0].first) {
20 ustring t (b, m[0].first);
25 if (m[1].matched) { // <
26 out_raw (CharConst ("<"));
27 } else if (m[2].matched) { // >
28 out_raw (CharConst (">"));
29 } else if (m[3].matched) { // &
30 out_raw (CharConst ("&"));
31 } else if (m[4].matched) { // "
32 out_raw (CharConst ("""));
33 } else if (m[5].matched) { // '
34 out_raw (CharConst ("'"));
35 } else if (m[6].matched) { // \n
36 out_raw (CharConst ("<br />\n"));
37 } else if (m[7].matched) { // http...
38 out_raw (CharConst ("<a href=\""));
39 outamp (m[7].first, m[7].second, &re_encode);
40 out_raw (CharConst ("\">"));
41 outamp (m[7].first, m[7].second, &re_encode);
42 out_raw (CharConst ("</a>"));
54 MotorOutput* MotorOutput::out_templateText (const ustring& str) {
55 return out_raw (fixUTF8 (str));
58 MotorOutput* MotorOutput::out_toHTML (const ustring& str) {
59 ustring t = fixUTF8 (str);
60 outamp (t.begin (), t.end (), &re_encode);
64 MotorOutput* MotorOutput::out_toHTML_br (const ustring& str) {
65 ustring t = fixUTF8 (str);
66 outamp (t.begin (), t.end (), &re_encode_br);
70 MotorOutput* MotorOutput::out_toHTML_br_a (const ustring& str) {
71 ustring t = fixUTF8 (str);
72 outamp (t.begin (), t.end (), &re_encode_br_a);
76 MotorOutput* MotorOutput::out_toHTML_wbr (const ustring& str) {
77 ustring t = fixUTF8 (str);
78 outamp (t.begin (), t.end (), &re_encode);
84 MotorOutput* MotorOutput::out_toHTML_noCtrl (const ustring& str) {
85 out_toHTML (omitCtrl (str));
89 MotorOutput* MotorOutput::out_toJS (const ustring& str) {
90 out_raw (jsEncode (str));
94 MotorOutput* MotorOutput::out_noCtrl (const ustring& str) {
95 out_raw (omitCtrl (str));
99 MotorOutput* MotorOutput::outNbsp () {
104 MotorOutput* MotorOutput::out_file (const ustring& src) {
109 if (f.openRead (src.c_str ())) {
111 while ((s = f.read (b, 65536)) > 0) {
119 MotorOutput* MotorOutput::outamp (const ustring& t) {
120 outamp (t.begin (), t.end (), &re_encode);
124 MotorOutput* MotorOutput::outamp_br (const ustring& t) {
125 outamp (t.begin (), t.end (), &re_encode_br);
129 MotorOutput* MotorOutput::outamp_wbr (const ustring& t) {
130 outamp (t.begin (), t.end (), &re_encode);
136 MotorOutput* MotorOutput::outamp_nw (const ustring& t) {
144 MotorOutput* MotorOutput::outamp_c3 (const ustring& t) {
148 /* ============================================================ */
149 MotorOutput* MotorOutputCOut::out (const ustring::value_type* s, size_t len) {
150 std::cout.write (s, len);
154 /* ============================================================ */
155 MotorOutput* MotorOutputString::out (const ustring::value_type* s, size_t len) {
160 /* ============================================================ */
161 MotorOutput* MotorOutputOStream::out (const ustring::value_type* s, size_t len) {
162 ostream->write (s, len);
166 /* ============================================================ */