Menu

[r471]: / framework / trunk / base_view.cpp  Maximize  Restore  History

Download this file

105 lines (95 with data), 1.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
#include "base_view.h"
#include "worker_thread.h"
namespace cppcms {
string base_view::escape(string const &s)
{
string content;
unsigned i,len=s.size();
content.reserve(len*3/2);
for(i=0;i<len;i++) {
char c=s[i];
switch(c){
case '<': content+="&lt;"; break;
case '>': content+="&gt;"; break;
case '&': content+="&amp;"; break;
case '\"': content+="&quot;"; break;
default: content+=c;
}
}
return content;
}
string base_view::urlencode(string const &s)
{
string content;
unsigned i,len=s.size();
content.reserve(3*len);
for(i=0;i<len;i++){
char c=s[i];
if( ('a'<=c && c<='z')
|| ('A'<=c && c<='Z')
|| ('0'<=c && c<='9'))
{
content+=c;
}
else {
switch(c) {
case '-':
case '_':
case '.':
case '~':
case '!':
case '*':
case '\'':
case '(':
case ')':
case ';':
case ':':
case '@':
case '&':
case '=':
case '+':
case '$':
case ',':
case '/':
case '?':
case '%':
case '#':
case '[':
case ']':
content+=c;
break;
default:
{
char buf[4];
snprintf(buf,sizeof(buf),"%%%02x",(unsigned)(c));
content.append(buf,3);
}
};
}
};
return content;
}
namespace details {
views_storage &views_storage::instance() {
static views_storage this_instance;
return this_instance;
};
void views_storage::add_view(string t,string v,view_factory_t f)
{
storage[t][v]=f;
}
void views_storage::remove_views(string t)
{
storage.erase(t);
}
base_view *views_storage::fetch_view(string t,string v,base_view::settings s,base_content *c)
{
templates_t::iterator p=storage.find(t);
if(p==storage.end()) return NULL;
template_views_t::iterator p2=p->second.find(v);
if(p2==p->second.end()) return NULL;
view_factory_t &f=p2->second;
return f(s,c);
}
};
}// CPPCMS
MongoDB Logo MongoDB