summaryrefslogtreecommitdiffabout
path: root/lib/util.cc
authorMichael Krelin <hacker@klever.net>2005-01-29 21:21:05 (UTC)
committer Michael Krelin <hacker@klever.net>2005-01-29 21:21:05 (UTC)
commitce1f37aae46ea95020d7b865f7a80e8abdfad0d8 (patch) (unidiff)
tree4964383ab8cd7e6d8ea821f1a615d1bbcf98dad8 /lib/util.cc
parent3c75c860fc1ad5b3f5185e23ec6f438dd2528958 (diff)
downloadsitecing-0.0.zip
sitecing-0.0.tar.gz
sitecing-0.0.tar.bz2
initial commit into repository0.0
Diffstat (limited to 'lib/util.cc') (more/less context) (ignore whitespace changes)
-rw-r--r--lib/util.cc83
1 files changed, 83 insertions, 0 deletions
diff --git a/lib/util.cc b/lib/util.cc
new file mode 100644
index 0000000..1a81c56
--- a/dev/null
+++ b/lib/util.cc
@@ -0,0 +1,83 @@
1#ifdef USE_PCH
2 #include "pch.h"
3#else
4 #include <cassert>
5 #include "sitecing/util.h"
6#endif
7
8namespace sitecing {
9
10 static const char *unsafeChars = "<>& \n\"";
11
12 string html_escape(const string& str,int flags) {
13 string rv = str;
14 string::size_type screwed = 0;
15 for(;;) {
16 screwed = rv.find_first_of(unsafeChars,screwed);
17 if(screwed == string::npos)
18 break;
19 while(screwed<rv.length() && strchr(unsafeChars,rv.at(screwed))) {
20 char danger = rv.at(screwed);
21 switch(danger) {
22 case '<':
23 rv.replace(screwed,1,"&lt;"); screwed+=4;
24 break;
25 case '>':
26 rv.replace(screwed,1,"&gt;"); screwed+=4;
27 break;
28 case '&':
29 rv.replace(screwed,1,"&amp;"); screwed+=5;
30 break;
31 case ' ':
32 if(flags&html_escape_nbsp) {
33 rv.replace(screwed,1,"&nbsp;"); screwed+=6;
34 }else
35 screwed++;
36 break;
37 case '\n':
38 if(flags&html_escape_br) {
39 if(flags&html_escape_br_noslash) {
40 rv.replace(screwed,1,"<br>\n"); screwed += 5;
41 }else{
42 rv.replace(screwed,1,"<br/>\n"); screwed += 6;
43 }
44 }else
45 screwed++;
46 break;
47 case '\"':
48 if(flags&html_escape_quot) {
49 rv.replace(screwed,1,"&quot;"); screwed+=6;
50 }else
51 screwed++;
52 break;
53 default:
54 assert(false);
55 break;
56 }
57 }
58 }
59 return rv;
60 }
61
62 void checkpoint::set() {
63 point = stream->tellp();
64 if(last_will==will_intestate)
65 last_will = will_rollback;
66 }
67
68 void checkpoint::make_will(will_t lw) {
69 last_will = lw;
70 }
71
72 void checkpoint::rollback() {
73 stream->seekp(point);
74 if(last_will == will_rollback)
75 last_will = will_intestate;
76 }
77 void checkpoint::commit() {
78 point = stream->tellp();
79 if(last_will == will_rollback)
80 last_will = will_intestate;
81 }
82
83}