From 50f08cb0b43a7d9fee1d4b3047d71f569d741380 Mon Sep 17 00:00:00 2001 From: Pixel Date: Mon, 28 Nov 2011 00:47:12 -0800 Subject: Whoops: forgot to implement the escaping function. --- includes/SimpleMustache.h | 2 +- src/SimpleMustache.cc | 87 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 1 deletion(-) diff --git a/includes/SimpleMustache.h b/includes/SimpleMustache.h index 7bf0342..5d0b9cf 100644 --- a/includes/SimpleMustache.h +++ b/includes/SimpleMustache.h @@ -98,7 +98,7 @@ class SimpleMustache { Fragments m_fragments; Fragments::iterator render_r(IO h, Context * ctx, const String & endSection, Fragments::iterator begin, bool noWrite, int forceIdx); - String escape(const String & s) { return s; } + String escape(const String & s); }; }; diff --git a/src/SimpleMustache.cc b/src/SimpleMustache.cc index a7b2c45..6ed8401 100644 --- a/src/SimpleMustache.cc +++ b/src/SimpleMustache.cc @@ -420,3 +420,90 @@ Balau::SimpleMustache::Fragments::iterator Balau::SimpleMustache::render_r(IO': + size += 4; + break; + default: + size++; + break; + } + } + + char * t = (char *) malloc(size + 1); + char * p = t; + + for (int i = 0; i < s.strlen(); i++) { + switch (s[i]) { + case '%': + *p++ = '%'; + *p++ = 'a'; + *p++ = 'm'; + *p++ = 'p'; + *p++ = ';'; + break; + case '"': + *p++ = '&'; + *p++ = 'q'; + *p++ = 'u'; + *p++ = 'o'; + *p++ = 't'; + *p++ = ';'; + break; + case '\'': + *p++ = '&'; + *p++ = '#'; + *p++ = '3'; + *p++ = '5'; + *p++ = ';'; + break; + case '\\': + *p++ = '&'; + *p++ = '#'; + *p++ = '9'; + *p++ = '2'; + *p++ = ';'; + break; + case '<': + *p++ = '&'; + *p++ = 'l'; + *p++ = 't'; + *p++ = ';'; + break; + case '>': + *p++ = '&'; + *p++ = 'g'; + *p++ = 't'; + *p++ = ';'; + break; + default: + break; + } + } + + *p = 0; + + String r(t, size); + free(t); + return r; +} -- cgit v1.2.3