From 30996f14a9cf8b1f86659a8ab1079a82058b53d5 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 4 Jun 2011 20:51:48 +0300 Subject: [PATCH 1/2] Additional Hebrew support Conversions to unicode (when needed) Removal of extra chars Addition of RTL Committer: Nitzan Arazi On branch master Changes to be committed: Conversions to unicode when needed (for hebrew only) Removal of extra chars (for hebrew only) Addition of RTL (for hebrew only) (use "git reset HEAD ..." to unstage) modified: bgl.cc --- bgl.cc | 49 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/bgl.cc b/bgl.cc index c88633da..8753780a 100644 --- a/bgl.cc +++ b/bgl.cc @@ -548,6 +548,9 @@ public: isCancelled.ref(); } + void fixHebString(string & hebStr); // Hebrew support + void fixHebArticle(string & hebArticle); // Hebrew support + ~BglArticleRequest() { isCancelled.ref(); @@ -560,6 +563,27 @@ void BglArticleRequestRunnable::run() r.run(); } +void BglArticleRequest::fixHebString(string & hebStr) // Hebrew support - convert non-unicode to unicode +{ + wstring hebWStr=Utf8::decode(hebStr); + for (unsigned int i=0; i=224 && hebWStr[i]<=250) // Hebrew chars encoded ecoded as windows-1255 or ISO-8859-8 + hebWStr[i]+=1488-224; // Convert to Hebrew unicode + } + hebStr=Utf8::encode(hebWStr); +} + +void BglArticleRequest::fixHebArticle(string & hebArticle) // Hebrew support - remove extra chars at the end +{ + int nulls=hebArticle.size()-1; + while ((hebArticle[nulls]<=32 && hebArticle[nulls]>=0) || (hebArticle[nulls]>=65 && hebArticle[nulls]<=90)) //special chars and A-Z + { + nulls--; + } + hebArticle.erase (hebArticle.begin()+nulls+1, hebArticle.end()); +} + void BglArticleRequest::run() { if ( isCancelled ) @@ -570,6 +594,8 @@ void BglArticleRequest::run() vector< WordArticleLink > chain = dict.findArticles( word ); + static Language::Id hebrew = LangCoder::code2toInt( "he" ); // Hebrew support + for( unsigned x = 0; x < alts.size(); ++x ) { /// Make an additional query for each alt @@ -616,6 +642,15 @@ void BglArticleRequest::run() wstring headwordStripped = Folding::applySimpleCaseOnly( Utf8::decode( removePostfix( headword ) ) ); + // Hebrew support - fix Hebrew text + if (dict.idxHeader.langFrom == hebrew) + { + displayedHeadword= displayedHeadword.size() ? displayedHeadword : headword; + fixHebString(articleText); + fixHebArticle(articleText); + fixHebString(displayedHeadword); + } + string const & targetHeadword = displayedHeadword.size() ? displayedHeadword : headword; @@ -652,12 +687,12 @@ void BglArticleRequest::run() """""""""""" "" ""; - - static Language::Id hebrew = LangCoder::code2toInt( "he" ); - for( i = mainArticles.begin(); i != mainArticles.end(); ++i ) { - result += "

"; + if (dict.idxHeader.langFrom == hebrew) // Hebrew support - format as RTL + result += "

"; + else + result += "

"; result += postfixToSuperscript( i->second.first ); result += "

"; if ( dict.idxHeader.langTo == hebrew ) @@ -666,10 +701,14 @@ void BglArticleRequest::run() result += i->second.second ; result += cleaner; } + for( i = alternateArticles.begin(); i != alternateArticles.end(); ++i ) { - result += "

"; + if (dict.idxHeader.langFrom == hebrew) // Hebrew support - format as RTL + result += "

"; + else + result += "

"; result += postfixToSuperscript( i->second.first ); result += "

"; if ( dict.idxHeader.langTo == hebrew ) From f57c554a7c2e39d0f17a293cc74b0ae578ef6689 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 5 Jun 2011 22:34:05 +0300 Subject: [PATCH 2/2] Added protection for not fixing empty hebArticle Committer: nitnit On branch master Changes to be committed: modified: bgl.cc --- bgl.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bgl.cc b/bgl.cc index 8753780a..f70085ba 100644 --- a/bgl.cc +++ b/bgl.cc @@ -577,7 +577,7 @@ void BglArticleRequest::fixHebString(string & hebStr) // Hebrew support - conver void BglArticleRequest::fixHebArticle(string & hebArticle) // Hebrew support - remove extra chars at the end { int nulls=hebArticle.size()-1; - while ((hebArticle[nulls]<=32 && hebArticle[nulls]>=0) || (hebArticle[nulls]>=65 && hebArticle[nulls]<=90)) //special chars and A-Z + while ( nulls>=0 && ((hebArticle[nulls]<=32 && hebArticle[nulls]>=0) || (hebArticle[nulls]>=65 && hebArticle[nulls]<=90))) //special chars and A-Z { nulls--; }