Changeset dce2de164f254dc3594775f54a9c35f31fa331b8
- Timestamp:
- 01/06/07 23:39:25 (6 years ago)
- Author:
- Philipp Kern <phil@…>
- Parents:
- f13160d360e09c0436c3b46d129005c4ce03d34b
- Children:
- 7a86085442974ccd345ab17c16afadb4916ef073
- git-committer:
- Philipp Kern <phil@0x539.de> / 2007-01-06T22:39:25Z+0000
- Message:
-
[project @ Replace all non-ascii characters in UI XML [fixes #44]]
Original author: Armin Burgmeier <armin@…>
Date: 2005-06-15 16:11:54+00:00
- Location:
- src
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r8343ef5
|
rdce2de1
|
|
| 67 | 67 | "</ui>"; |
| 68 | 68 | |
| 69 | | void replace_string(Glib::ustring& string, |
| 70 | | const Glib::ustring& find, |
| 71 | | const Glib::ustring& replace) |
| | 69 | /** Replaces dangerous characters for an XML attribute by their |
| | 70 | * Unicode value. |
| | 71 | */ |
| | 72 | void remove_dangerous_xml(Glib::ustring& string) |
| 72 | 73 | { |
| 73 | | Glib::ustring::size_type pos = 0; |
| 74 | | while((pos = string.find(find, pos)) != Glib::ustring::npos) |
| | 74 | for(Glib::ustring::iterator iter = string.begin(); |
| | 75 | iter != string.end(); |
| | 76 | ++ iter) |
| 75 | 77 | { |
| 76 | | string.replace(pos, find.length(), replace); |
| 77 | | pos += replace.length(); |
| | 78 | // Get current character |
| | 79 | gunichar c = *iter; |
| | 80 | |
| | 81 | // Not an ASCII character, or a dangerous one? |
| | 82 | if(c == '<' || c == '>' || c == '\"' || c > 0x7f) |
| | 83 | { |
| | 84 | // Get next iter to find the end position |
| | 85 | Glib::ustring::iterator next = iter; |
| | 86 | ++ next; |
| | 87 | |
| | 88 | // Build value string |
| | 89 | std::stringstream value_stream; |
| | 90 | value_stream << c; |
| | 91 | |
| | 92 | // Erase dangerous character |
| | 93 | iter = string.erase(iter, next); |
| | 94 | |
| | 95 | // Insert string char by char to keep the |
| | 96 | // iterator valid. |
| | 97 | char cval; |
| | 98 | while(value_stream >> cval) |
| | 99 | iter = string.insert(iter, cval); |
| | 100 | } |
| 78 | 101 | } |
| 79 | | } |
| 80 | | |
| 81 | | void remove_entities(Glib::ustring& string) |
| 82 | | { |
| 83 | | // Note that this file needs to be UTF-8 encoded! |
| 84 | | replace_string(string, "À", "auml"); |
| 85 | | replace_string(string, "Ã", "Auml"); |
| 86 | | replace_string(string, "ö", "ouml"); |
| 87 | | replace_string(string, "Ã", "Ouml"); |
| 88 | | replace_string(string, "Ì", "uuml"); |
| 89 | | replace_string(string, "Ã", "Uuml"); |
| 90 | | replace_string(string, "Ã", "szlig"); |
| 91 | | replace_string(string, "<", "lt"); |
| 92 | | replace_string(string, ">", "gt"); |
| 93 | | replace_string(string, "\"", "quot"); |
| 94 | | |
| 95 | | // TODO: Remove some more dangerous characters |
| 96 | 102 | } |
| 97 | 103 | } |
| … |
… |
|
| 298 | 304 | // Build description string |
| 299 | 305 | obby::format_string str(_("Selects %0 as language") ); |
| 300 | | str << language->get_name(); |
| | 306 | str << language->get_name().raw(); |
| 301 | 307 | |
| 302 | 308 | // Add language to action group |
| 303 | | remove_entities(language_xml_name); |
| | 309 | remove_dangerous_xml(language_xml_name); |
| 304 | 310 | m_group_app->add( |
| 305 | 311 | Gtk::RadioAction::create( |
| … |
… |
|
| 622 | 628 | Glib::ustring langname = document.get_language() ? |
| 623 | 629 | document.get_language()->get_name() : "None"; |
| 624 | | remove_entities(langname); |
| | 630 | remove_dangerous_xml(langname); |
| 625 | 631 | Glib::RefPtr<Gtk::RadioAction>::cast_static<Gtk::Action>( |
| 626 | 632 | m_group_app->get_action("ViewLanguage" + langname) |
-
|
re0f11d9
|
rdce2de1
|
|
| 52 | 52 | cur_time = localtime(&cur_time_t); |
| 53 | 53 | |
| | 54 | // TODO: Use strftime |
| 54 | 55 | std::stringstream timestream; |
| 55 | 56 | timestream << "["; |
-
|
r8343ef5
|
rdce2de1
|
|
| 58 | 58 | |
| 59 | 59 | #ifdef WITH_GTKSOURCEVIEW |
| | 60 | #include <iostream> |
| 60 | 61 | void Gobby::StatusBar::update_language(Document& document) |
| 61 | 62 | { |
| … |
… |
|
| 64 | 65 | { |
| 65 | 66 | obby::format_string str(_("Selected language: %0") ); |
| 66 | | str << document.get_language()->get_name(); |
| | 67 | str << document.get_language()->get_name().raw(); |
| 67 | 68 | m_language.set_text(str.str() ); |
| 68 | 69 | } |