Files
winix/templates/localefilter.cpp
Tomasz Sowa ba63c8c661 changed: removed Languages::Land enum
now we set the languages in the config file: option locale_files, sample:
  locale_files = ( en, pl )
it represents the name of locale files (those from locale_dir directory)
renamed config option: locale to locale_default


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@722 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-02-24 17:06:12 +00:00

120 lines
1.7 KiB
C++
Executable File

/*
* This file is a part of Winix
* 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::wstring & LocaleFilter::FilterValue(const std::wstring & in)
{
value.clear();
const wchar_t * 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::wstring & str)
{
res.clear();
pchar = str.c_str();
while( *pchar )
{
if( *pchar == open_mark )
{
++pchar;
ReadKey();
res += FilterValue(plocale->Get(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_)
{
plocale = &locale;
lang = lang_;
FilterText( pattern.item_root );
}