Author: rpmcruz Date: Wed Dec 2 01:49:25 2009 New Revision: 59887 URL: http://svn.opensuse.org/viewcvs/yast?rev=59887&view=rev Log: * src/YGUtils.cc: bug fix 549943: HTML to XHTML conversor was tripping in the breakline. Modified: trunk/gtk/ChangeLog trunk/gtk/src/YGUtils.cc trunk/gtk/src/YGUtils.h trunk/gtk/src/pkg/YGPackageSelector.cc trunk/gtk/src/pkg/ygtkpackageview.cc trunk/gtk/src/pkg/yzyppwrapper.cc trunk/gtk/src/test.cc Modified: trunk/gtk/ChangeLog URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/ChangeLog?rev=59887&r1=59886&r2=59887&view=diff ============================================================================== --- trunk/gtk/ChangeLog (original) +++ trunk/gtk/ChangeLog Wed Dec 2 01:49:25 2009 @@ -1,3 +1,8 @@ +2009-12-02 Ricardo Cruz <rpmcruz@alunos.dcc.fc.up.pt> + + * src/YGUtils.cc: bug fix 549943: HTML to XHTML + conversor was tripping in the breakline. + 2009-12-01 Ricardo Cruz <rpmcruz@alunos.dcc.fc.up.pt> * src/YGUtils.cc: bug fix 559226: Allow '&' to be escaped. Modified: trunk/gtk/src/YGUtils.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/src/YGUtils.cc?rev=59887&r1=59886&r2=59887&view=diff ============================================================================== --- trunk/gtk/src/YGUtils.cc (original) +++ trunk/gtk/src/YGUtils.cc Wed Dec 2 01:49:25 2009 @@ -268,9 +268,12 @@ else { // Normal text if (!pre_mode && g_ascii_isspace (instr[i])) { - if (!was_space) - g_string_append_c (outp, ' '); - was_space = TRUE; + // completely ignore breaklines unlike other whitespace + if (instr[i] != '\n') { + if (!was_space) + g_string_append_c (outp, ' '); + was_space = TRUE; + } } else { was_space = FALSE; @@ -419,42 +422,27 @@ void ygutils_scrollAdj (GtkAdjustment *vadj, gboolean top) { YGUtils::scrollWidget (vadj, top); } -void YGUtils::escapeMarkup (std::string &str) +std::string YGUtils::escapeMarkup (const std::string &ori) { - bool modify = false; - std::string::size_type i; - for (i = 0; i < str.length() && !modify; i++) { - switch (str[i]) { + std::string::size_type length = ori.length(), i; + std::string ret; + ret.reserve (length * 1.5); + for (i = 0; i < length; i++) + switch (ori[i]) { case '<': + ret += "<"; + break; case '>': + ret += ">"; + break; case '&': - modify = true; + ret += "&"; break; default: + ret += ori[i]; break; } - } - if (modify) { - std::string ori (str); - str.clear(); - str.reserve (ori.length()+50); - for (i = 0; i < ori.length(); i++) { - switch (ori[i]) { - case '<': - str += "<"; - break; - case '>': - str += ">"; - break; - case '&': - str += "&"; - break; - default: - str += ori[i]; - break; - } - } - } + return ret; } int YGUtils::getCharsWidth (GtkWidget *widget, int chars_nb) Modified: trunk/gtk/src/YGUtils.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/src/YGUtils.h?rev=59887&r1=59886&r2=59887&view=diff ============================================================================== --- trunk/gtk/src/YGUtils.h (original) +++ trunk/gtk/src/YGUtils.h Wed Dec 2 01:49:25 2009 @@ -29,7 +29,7 @@ std::string truncate (const std::string &str, int length, int pos); /* Escapes markup text (eg. changes '<' by '\<'). */ - void escapeMarkup (std::string &str); + std::string escapeMarkup (const std::string &str); /* Adds functionality to scroll widgets to top or bottom. */ void scrollWidget (GtkAdjustment *vadj, bool top); Modified: trunk/gtk/src/pkg/YGPackageSelector.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/src/pkg/YGPackageSelector.cc?rev=59887&r1=59886&r2=59887&view=diff ============================================================================== --- trunk/gtk/src/pkg/YGPackageSelector.cc (original) +++ trunk/gtk/src/pkg/YGPackageSelector.cc Wed Dec 2 01:49:25 2009 @@ -482,7 +482,7 @@ const Ypp::Repository *repo = Ypp::get()->getRepository (i); gtk_tree_store_append (store, &iter, NULL); std::string text = repo->name, url (repo->url); - YGUtils::escapeMarkup (url); + url = YGUtils::escapeMarkup (url); text += "\n<small>" + url + "</small>"; const gchar *icon; if (repo->url.empty()) Modified: trunk/gtk/src/pkg/ygtkpackageview.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/src/pkg/ygtkpackageview.cc?rev=59887&r1=59886&r2=59887&view=diff ============================================================================== --- trunk/gtk/src/pkg/ygtkpackageview.cc (original) +++ trunk/gtk/src/pkg/ygtkpackageview.cc Wed Dec 2 01:49:25 2009 @@ -458,7 +458,7 @@ std::string str = package->name(); std::string summary = package->summary(); if (!summary.empty()) { - YGUtils::escapeMarkup (summary); + summary = YGUtils::escapeMarkup (summary); str += "\n<small>" + summary + "</small>"; } g_value_set_string (value, g_strdup (str.c_str())); Modified: trunk/gtk/src/pkg/yzyppwrapper.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/src/pkg/yzyppwrapper.cc?rev=59887&r1=59886&r2=59887&view=diff ============================================================================== --- trunk/gtk/src/pkg/yzyppwrapper.cc (original) +++ trunk/gtk/src/pkg/yzyppwrapper.cc Wed Dec 2 01:49:25 2009 @@ -558,7 +558,7 @@ ZyppObject object = m_sel->theObj(); std::string text = object->description(), br = "<br>"; if (markup == GTK_MARKUP && type == Ypp::Package::PACKAGE_TYPE) { - YGUtils::escapeMarkup (text); + text = YGUtils::escapeMarkup (text); text += "\n"; const Ypp::Package::Version *version; version = getInstalledVersion(); @@ -592,7 +592,7 @@ while (text.length() > 0 && text [text.length()-1] == '\n') text.erase (text.length()-1); - YGUtils::escapeMarkup (text); + text = YGUtils::escapeMarkup (text); YGUtils::replace (text, "\n\n", 2, "<br>"); // break every double line text += br; } @@ -772,8 +772,8 @@ it != changelogList.end(); it++) { std::string date (it->date().form ("%d %B %Y")), author (it->author()), changes (it->text()); - YGUtils::escapeMarkup (author); - YGUtils::escapeMarkup (changes); + author = YGUtils::escapeMarkup (author); + changes = YGUtils::escapeMarkup (changes); YGUtils::replace (changes, "\n", 1, "<br>"); if (author.compare (0, 2, "- ", 2) == 0) // zypp returns a lot of author strings as author.erase (0, 2); // "- author". wtf? @@ -790,14 +790,14 @@ ZyppPackage package = tryCastToZyppPkg (object); if (package) { std::string packager = package->packager(), vendor = package->vendor(), authors; - YGUtils::escapeMarkup (packager); - YGUtils::escapeMarkup (vendor); + packager = YGUtils::escapeMarkup (packager); + vendor = YGUtils::escapeMarkup (vendor); const std::list <std::string> &authorsList = package->authors(); for (std::list <std::string>::const_iterator it = authorsList.begin(); it != authorsList.end(); it++) { std::string author (*it); if (markup != NO_MARKUP) - YGUtils::escapeMarkup (author); + author = YGUtils::escapeMarkup (author); if (!authors.empty()) { if (markup == HTML_MARKUP) authors += "<br>"; @@ -828,7 +828,7 @@ if (i != std::string::npos) { std::string str = description.substr (i); if (markup != NO_MARKUP) - YGUtils::escapeMarkup (str); + str = YGUtils::escapeMarkup (str); if (markup == HTML_MARKUP) YGUtils::replace (str, "\n", 1, "<br>"); authors += str; @@ -870,7 +870,7 @@ zypp::VendorSupportOption opt = package->vendorSupport(); std::string str (zypp::asUserStringDescription (opt)); if (markup != HTML_MARKUP) - YGUtils::escapeMarkup (str); + return YGUtils::escapeMarkup (str); return str; } return ""; @@ -975,7 +975,7 @@ text += it->asString(); } if (markup != HTML_MARKUP) - YGUtils::escapeMarkup (text); + return YGUtils::escapeMarkup (text); return text; } @@ -991,7 +991,7 @@ text += it->asString(); } if (markup != NO_MARKUP) - YGUtils::escapeMarkup (text); + return YGUtils::escapeMarkup (text); return text; } Modified: trunk/gtk/src/test.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/src/test.cc?rev=59887&r1=59886&r2=59887&view=diff ============================================================================== --- trunk/gtk/src/test.cc (original) +++ trunk/gtk/src/test.cc Wed Dec 2 01:49:25 2009 @@ -131,8 +131,7 @@ { NULL, NULL } }; for (int i = 0; aTests[i].in; i++) { - string out (aTests[i].in); - YGUtils::escapeMarkup (out); + string out (YGUtils::escapeMarkup (aTests[i].in)); if (out != aTests[i].out) { fprintf (stderr, "Mis-converted entry %d XML '%s' should be '%s'\n", i, out.c_str(), aTests[i].out); -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org