changed: rename cmslu to winix
changed: html templates are a part of winix now and the user can provide special html templates for its site added: locales added: html templates are using HtmlFilter now (locales) changed: now we have html templates for each language git-svn-id: svn://ttmath.org/publicrep/winix/trunk@560 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
117
templates/localefilter.cpp
Executable file
117
templates/localefilter.cpp
Executable file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2010, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "localefilter.h"
|
||||
#include "../core/misc.h"
|
||||
|
||||
|
||||
|
||||
LocaleFilter::LocaleFilter()
|
||||
{
|
||||
open_mark = '{';
|
||||
closing_mark = '}';
|
||||
}
|
||||
|
||||
|
||||
|
||||
void LocaleFilter::ReadKey()
|
||||
{
|
||||
key.clear();
|
||||
|
||||
for( ; *pchar && *pchar != closing_mark ; ++pchar)
|
||||
key += *pchar;
|
||||
|
||||
// skipping last closing mark (if exists)
|
||||
if( *pchar == closing_mark )
|
||||
++pchar;
|
||||
|
||||
TrimWhite(key);
|
||||
}
|
||||
|
||||
|
||||
std::string & LocaleFilter::FilterValue(const std::string & in)
|
||||
{
|
||||
value.clear();
|
||||
const char * p = in.c_str();
|
||||
|
||||
while( *p )
|
||||
{
|
||||
if( *p == '\\' && (*(p+1) == 'n') )
|
||||
{
|
||||
value += '\n';
|
||||
p += 2;
|
||||
}
|
||||
else
|
||||
if( *p == '\\' && (*(p+1) == '\\') )
|
||||
{
|
||||
value += '\\';
|
||||
p += 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
value += *p;
|
||||
p += 1;
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void LocaleFilter::Parse(std::string & str)
|
||||
{
|
||||
res.clear();
|
||||
pchar = str.c_str();
|
||||
|
||||
while( *pchar )
|
||||
{
|
||||
if( *pchar == open_mark )
|
||||
{
|
||||
++pchar;
|
||||
ReadKey();
|
||||
res += FilterValue(plocale->Get(key));
|
||||
}
|
||||
else
|
||||
if( *pchar == '\\' && (*(pchar+1) == open_mark || *(pchar+1) == closing_mark || *(pchar+1) == '\\') )
|
||||
{
|
||||
res += *(pchar+1);
|
||||
pchar += 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
res += *pchar;
|
||||
pchar += 1;
|
||||
}
|
||||
}
|
||||
|
||||
str = res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void LocaleFilter::FilterText(Ezc::Pattern::Item & item)
|
||||
{
|
||||
if( !item.text.empty() )
|
||||
Parse(item.text);
|
||||
|
||||
std::vector<Ezc::Pattern::Item*>::iterator i = item.item_table.begin();
|
||||
|
||||
for( ; i != item.item_table.end() ; ++i )
|
||||
FilterText(**i);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void LocaleFilter::Filter(Ezc::Pattern & pattern, const Locale & locale)
|
||||
{
|
||||
plocale = &locale;
|
||||
FilterText( pattern.item_root );
|
||||
}
|
Reference in New Issue
Block a user