From ce1f37aae46ea95020d7b865f7a80e8abdfad0d8 Mon Sep 17 00:00:00 2001 From: Michael Krelin Date: Sat, 29 Jan 2005 21:21:05 +0000 Subject: initial commit into repository --- (limited to 'lib/util.cc') 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 + #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.replace(screwed,1,">"); screwed+=4; + break; + case '&': + rv.replace(screwed,1,"&"); screwed+=5; + break; + case ' ': + if(flags&html_escape_nbsp) { + rv.replace(screwed,1," "); screwed+=6; + }else + screwed++; + break; + case '\n': + if(flags&html_escape_br) { + if(flags&html_escape_br_noslash) { + rv.replace(screwed,1,"
\n"); screwed += 5; + }else{ + rv.replace(screwed,1,"
\n"); screwed += 6; + } + }else + screwed++; + break; + case '\"': + if(flags&html_escape_quot) { + rv.replace(screwed,1,"""); 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; + } + +} -- cgit v0.9.0.2