winix/templates/localefilter.cpp

97 lines
1.4 KiB
C++
Executable File

/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010-2014, Tomasz Sowa
* All rights reserved.
*
*/
#include "localefilter.h"
#include "../core/misc.h"
namespace Winix
{
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);
}
void LocaleFilter::Parse(std::wstring & str)
{
res.clear();
pchar = str.c_str();
while( *pchar )
{
if( *pchar == open_mark )
{
++pchar;
ReadKey();
res += plocale->GetByIndex(key, lang);
}
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::Item & item)
{
if( !item.text.empty() )
Parse(item.text);
std::vector<Ezc::Item*>::iterator i = item.item_tab.begin();
for( ; i != item.item_tab.end() ; ++i )
FilterText(**i);
}
void LocaleFilter::Filter(Ezc::Pattern & pattern, const Locale & locale, size_t lang_index)
{
plocale = &locale;
lang = lang_index;
FilterText( pattern.item_root );
}
} // namespace Winix