118 lines
1.7 KiB
C++
Executable File
118 lines
1.7 KiB
C++
Executable File
/*
|
|
* 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 );
|
|
}
|