The following commit has been merged in the master branch:
commit b432dc06a7620629b5b1c91d0127510586ba586f
Author: Miriam Ruiz <[email protected]>
Date:   Wed May 6 22:32:37 2009 +0200

    FLTK list of packages now shows i18n descriptions in Latin1

diff --git a/gui_fltk.cpp b/gui_fltk.cpp
index a014757..36d8df2 100644
--- a/gui_fltk.cpp
+++ b/gui_fltk.cpp
@@ -156,7 +156,7 @@ static void UpdateUILists(GamesUI& ui)
 
                        std::string desc;
                        std::string shortdesc;
-                       if (pkgdata.GetPkgShortDesc(rec.package(), shortdesc))
+                       if (pkgdata.GetPkgLatin1ShortDesc(rec.package(), 
shortdesc))
                        {
                                desc = std::string(fmtstr) + rec.package() + 
"\t" + 
                                        std::string(fmtstr) + shortdesc;
diff --git a/pkgdata.cpp b/pkgdata.cpp
index 91e77f7..e00d234 100644
--- a/pkgdata.cpp
+++ b/pkgdata.cpp
@@ -107,10 +107,13 @@ static const char legalchars[] = 
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghij
 void PackageData::AddTextAsHTML(const std::string &in_text, std::string 
&out_html)
 {
        std::ostringstream os;
-       utf8::html::QuoteHTML(std::cout, in_text.c_str());
+       utf8::html::QuoteHTML(os, in_text.c_str());
+       os << std::ends;
+       os.flush();
        std::cout << os.str() << std::endl;
+       const std::string & tempString(os.str());
+       const char *text = tempString.c_str();
 
-       const char *text = in_text.c_str();
        const char *src = text;
        //out_html.erase();
        while (*src)
@@ -171,12 +174,26 @@ bool PackageData::GetPkgShortDesc(const std::string 
&pkgname, std::string &short
        return true;
 }
 
-bool PackageData::GetPkgHTMLShortDesc(const std::string &pkgname, std::string 
&shortdesc)
+bool PackageData::GetPkgHTMLShortDesc(const std::string &pkgname, std::string 
&html_short)
 {
        std::string shdesc;
        if (!GetPkgShortDesc(pkgname, shdesc))
                return false;
+       html_short.erase();
+       AddTextAsHTML(shdesc, html_short);
+       return true;
+}
 
+bool PackageData::GetPkgLatin1ShortDesc(const std::string &pkgname, 
std::string &desc)
+{
+       std::string shdesc;
+       if (!GetPkgShortDesc(pkgname, shdesc))
+               return false;
+       std::ostringstream os;
+       utf8::html::UTF8ToLatin1(os, shdesc.c_str());
+       os << std::ends;
+       os.flush();
+       desc = os.str();
        return true;
 }
 
diff --git a/pkgdata.h b/pkgdata.h
index 93bfba9..761b819 100644
--- a/pkgdata.h
+++ b/pkgdata.h
@@ -44,7 +44,8 @@ class PackageData : public Engine
        bool AppTemplate(const char *id);
 
        bool GetPkgShortDesc(const std::string &pkgname, std::string 
&shortdesc);
-       bool GetPkgHTMLShortDesc(const std::string &pkgname, std::string 
&shortdesc);
+       bool GetPkgHTMLShortDesc(const std::string &pkgname, std::string 
&html_short);
+       bool GetPkgLatin1ShortDesc(const std::string &pkgname, std::string 
&desc);
        bool GetPkgHTMLDesc(const std::string &pkgname, std::string 
&html_short, std::string &html_long);
 
        char *TagString(const Tag& tag);
diff --git a/utf8/html.cpp b/utf8/html.cpp
index 1e735ad..a02f990 100644
--- a/utf8/html.cpp
+++ b/utf8/html.cpp
@@ -351,7 +351,7 @@ void QuoteHTML(std::ostream &out, const char *in)
                        Char2UTF8Map::iterator it = char2utf8.find(ch);
                        if (ch < 128)
                        {
-                               out.put(*ptr);
+                               out.put(ch);
                        }
                        else if (it != char2utf8.end())
                        {
@@ -369,6 +369,29 @@ void QuoteHTML(std::ostream &out, const char *in)
        }
 }
 
+void UTF8ToLatin1(std::ostream &out, const char *in)
+{
+       const char *ptr = in;
+       int len = strlen(in);
+       while (*ptr)
+       {
+               unsigned long int ch;
+               int adv = utf8::parser::utf8_to_char(&ch, ptr, len);
+               if (adv && len >= adv)
+               {
+                       Char2UTF8Map::iterator it = char2utf8.find(ch);
+                       if (ch < 256)
+                               out.put(ch);
+                       else
+                               out << "?";
+                       len -= adv;
+                       ptr += adv;
+               }
+               else
+                       break;
+       }
+}
+
 } } // Close namespaces
 
 #ifdef UNIT_TEST
diff --git a/utf8/html.h b/utf8/html.h
index 17cab36..be84e54 100644
--- a/utf8/html.h
+++ b/utf8/html.h
@@ -29,6 +29,7 @@ namespace utf8
        {
 
                void QuoteHTML(std::ostream &out, const char *in);
+               void UTF8ToLatin1(std::ostream &out, const char *in);
 
        } // namespace utf8::html
 } // namespace utf8

-- 
Development for GoFind!

_______________________________________________
Pkg-games-commits mailing list
[email protected]
http://lists.alioth.debian.org/mailman/listinfo/pkg-games-commits

Reply via email to