added: two tables to locales/substitute: smallleters, capitalics

added: locale.ToSmall(wchar_t), locale.ToCapital(wchar_t)
       now we are able to recognize other than ASCII characters
added: static/basic/winix.css with basic styles
removed: [include "item_options.html"] from html templates (fun_cat.html and others)




git-svn-id: svn://ttmath.org/publicrep/winix/trunk@760 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2011-08-29 22:23:54 +00:00
parent b984475e49
commit 8c01b0f6c0
10 changed files with 626 additions and 54 deletions

View File

@@ -6,7 +6,8 @@
* All rights reserved.
*
*/
#include <algorithm>
#include "locale.h"
#include "core/log.h"
#include "utf8.h"
@@ -102,8 +103,9 @@ void Locale::ReadSubstTable(const char * dir, const char * dir_def)
{
bool read = false;
subst_original.clear();
subst_changeto.clear();
subst_url.clear();
subst_smalllet.clear();
subst_capitallet.clear();
if( dir_def && ReadSubstTable(dir_def) )
read = true;
@@ -130,8 +132,10 @@ bool read = false;
if( loc_parser.Parse(file_name) == ConfParser::ok )
{
read = true;
subst_original = loc_parser.table_single[L"original"];
subst_changeto = loc_parser.table_single[L"changeto"];
CreateSubstVector(subst_url, loc_parser.table_single[L"url_original"], loc_parser.table_single[L"url_changeto"]);
CreateSubstVector(subst_smalllet, loc_parser.table_single[L"smallleters"], loc_parser.table_single[L"capitalics"]);
CreateSubstVector(subst_capitallet, loc_parser.table_single[L"capitalics"], loc_parser.table_single[L"smallleters"]);
log << log3 << "Locale: read characters substitution tables from: " << file_name << logend;
}
@@ -139,6 +143,28 @@ return read;
}
void Locale::CreateSubstVector(std::vector<SubstItem> & vect, const std::wstring & tab1, const std::wstring & tab2)
{
size_t i, min_size = (tab1.size() < tab2.size()) ? tab1.size() : tab2.size();
SubstItem s;
vect.clear();
if( min_size == 0 )
return;
vect.reserve(min_size);
for(i=0 ; i<min_size ; ++i)
{
s.from = tab1[i];
s.to = tab2[i];
vect.push_back(s);
}
std::sort(vect.begin(), vect.end());
}
void Locale::Read(const char * dir, const char * dir_def)
{
@@ -149,9 +175,6 @@ void Locale::Read(const char * dir, const char * dir_def)
}
ReadSubstTable(dir, dir_def);
if( subst_original.size() != subst_changeto.size() )
log << log1 << "Locale: substitution tables have different sizes" << logend;
}
@@ -431,20 +454,94 @@ void Locale::UTF8(bool utf)
}
wchar_t Locale::Subst(wchar_t c)
/*
binary search in vect
vect should be sorted by 'from'
if the 'val' is found in vect[].from then vect[].to is reterned
else 'val' is returned
*/
wchar_t Locale::SubstFind(const std::vector<SubstItem> & vect, wchar_t val)
{
size_t i = subst_original.find(c);
if( vect.empty() )
return val;
if( i == std::wstring::npos || i >= subst_changeto.size() )
return c;
size_t o1 = 0;
size_t o2 = vect.size() - 1;
return subst_changeto[i];
if( val < vect[o1].from )
return val;
if( val == vect[o1].from )
return vect[o1].to;
if( val > vect[o2].from )
return val;
if( val == vect[o2].from )
return vect[o2].to;
while( o1 + 1 < o2 )
{
size_t o = (o1 + o2) / 2;
if( val == vect[o].from )
return vect[o].to;
if( val < vect[o].from )
o2 = o;
else
o1 = o;
}
return val;
}
void Locale::Subst(std::wstring & str)
wchar_t Locale::UrlSubst(wchar_t c)
{
return SubstFind(subst_url, c);
}
void Locale::UrlSubst(std::wstring & str)
{
for(size_t i=0 ; i<str.size() ; ++i)
str[i] = Subst(str[i]);
str[i] = UrlSubst(str[i]);
}
wchar_t Locale::ToSmall(wchar_t c)
{
if( c>='A' && c<='Z' )
return c - 'A' + 'a';
return SubstFind(subst_capitallet, c);
}
void Locale::ToSmall(std::wstring & str)
{
for(size_t i=0 ; i<str.size() ; ++i)
str[i] = ToSmall(str[i]);
}
wchar_t Locale::ToCapital(wchar_t c)
{
if( c>='a' && c<='z' )
return c - 'a' + 'A';
return SubstFind(subst_smalllet, c);
}
void Locale::ToCapital(std::wstring & str)
{
for(size_t i=0 ; i<str.size() ; ++i)
str[i] = ToCapital(str[i]);
}