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) (side-by-side diff)
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) (show 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 @@
+#ifdef USE_PCH
+ #include "pch.h"
+#else
+ #include <cassert>
+ #include "sitecing/util.h"
+#endif
+
+namespace sitecing {
+
+ static const char *unsafeChars = "<>& \n\"";
+
+ string html_escape(const string& str,int flags) {
+ string rv = str;
+ string::size_type screwed = 0;
+ for(;;) {
+ screwed = rv.find_first_of(unsafeChars,screwed);
+ if(screwed == string::npos)
+ break;
+ while(screwed<rv.length() && strchr(unsafeChars,rv.at(screwed))) {
+ char danger = rv.at(screwed);
+ switch(danger) {
+ case '<':
+ rv.replace(screwed,1,"&lt;"); screwed+=4;
+ break;
+ case '>':
+ rv.replace(screwed,1,"&gt;"); screwed+=4;
+ break;
+ case '&':
+ rv.replace(screwed,1,"&amp;"); screwed+=5;
+ break;
+ case ' ':
+ if(flags&html_escape_nbsp) {
+ rv.replace(screwed,1,"&nbsp;"); screwed+=6;
+ }else
+ screwed++;
+ break;
+ case '\n':
+ if(flags&html_escape_br) {
+ if(flags&html_escape_br_noslash) {
+ rv.replace(screwed,1,"<br>\n"); screwed += 5;
+ }else{
+ rv.replace(screwed,1,"<br/>\n"); screwed += 6;
+ }
+ }else
+ screwed++;
+ break;
+ case '\"':
+ if(flags&html_escape_quot) {
+ rv.replace(screwed,1,"&quot;"); screwed+=6;
+ }else
+ screwed++;
+ break;
+ default:
+ assert(false);
+ break;
+ }
+ }
+ }
+ return rv;
+ }
+
+ void checkpoint::set() {
+ point = stream->tellp();
+ if(last_will==will_intestate)
+ last_will = will_rollback;
+ }
+
+ void checkpoint::make_will(will_t lw) {
+ last_will = lw;
+ }
+
+ void checkpoint::rollback() {
+ stream->seekp(point);
+ if(last_will == will_rollback)
+ last_will = will_intestate;
+ }
+ void checkpoint::commit() {
+ point = stream->tellp();
+ if(last_will == will_rollback)
+ last_will = will_intestate;
+ }
+
+}