/* compressed utf-8 table */ 0x20ac, /* 80 Euro. CP1252 from here on... */ 0x81, /* 81 NA */ 0x201a, /* 82 */ 0x192, /* 83 */ 0x201e, /* 84 */ 0x2026, /* 85 */ 0x2020, /* 86 */ 0x2021, /* 87 */ 0x2c6, /* 88 */ 0x2030, /* 89 */ 0x160, /* 8a */ 0x2039, /* 8b */ 0x152, /* 8c */ 0x8d, /* 8d NA */ 0x17d, /* 8e */ 0x8f, /* 8f NA */ 0x90, /* 90 NA */ 0x2018, /* 91 */ 0x2019, /* 92 */ 0x201c, /* 93 */ 0x201d, /* 94 */ 0x2022, /* 95 */ 0x2013, /* 96 */ 0x2014, /* 97 */ 0x2dc, /* 98 */ 0x2122, /* 99 */ 0x161, /* 9a */ 0x203a, /* 9b */ 0x153, /* 9c */ 0x9d, /* 9d NA */ 0x17e, /* 9e */ 0x178, /* 9f */ 0xa0, /* a0 */ 0xa1, /* a1 */ 0xa2, /* a2 */ 0xa3, /* a3 */ 0x20ac /* a4 ISO-8859-15 Euro. */ }; while (len) { if (G_UNLIKELY(*text >= 0x80) && G_UNLIKELY(*text <= 0xa4)) { int idx = *text - 0x80; output += lowtable[idx]; } else { output += (gunichar)*text; /* ascii/iso88591 maps directly */ } text++; len--; } return output; }/*}}}*/ void set_charset(Glib::ustring charset) {/*{{{*/ charset = charset.uppercase(); if (charset.find(' ') != Glib::ustring::npos) charset = charset.erase(charset.find(' ')); if (charset.empty() || !charset.compare("SYSTEM")) { charset.clear(); } else { try { Glib::IConv test("UTF-8", charset); } catch (...) { fprintf(stderr, "Charset '%s' isn't supported by your system - using system locale\n", charset.c_str()); charset.clear(); } } serverCharset = charset; }/*}}}*/ std::string ustring_to_c(Glib::ustring input) {/*{{{*/ std::string to_charset, converted; // check if input is already 7-bit if (input.is_ascii()) return input; // try encoding using the selected charset, unless its some utf-8 if (!serverCharset.empty() && serverCharset.find("UTF-8") == Glib::ustring::npos) { try { return Glib::convert(input, serverCharset, "UTF-8"); } catch (...) {} } // try encoding using the locale charset, unless its some utf-8 if (Glib::get_charset(to_charset) == true) to_charset = "ISO-8859-1"; try { converted = Glib::convert_with_fallback(input, to_charset, "UTF-8", "?"); } catch (...) { converted = input; } return converted; }/*}}}*/
/* Callback for receiving data from modem */ void Terminal::update_read(Glib::ustring data) { size_t iReplyOem; size_t iddot; size_t replyOemLen = strlen(this->modem->REPLY_OEM().c_str()); if(!data.is_ascii()) REMOVE_NON_ASCII(data); inputPortBuffer += data; while(!inputPortBuffer.empty()) { iReplyOem = inputPortBuffer.find(this->modem->REPLY_OEM()); iddot = inputPortBuffer.find(":"); if(iReplyOem == std::string::npos && iddot == std::string::npos) return; if(iReplyOem < iddot) { input.push(inputPortBuffer.substr(0, iReplyOem)); inputPortBuffer.erase(0, iReplyOem + replyOemLen); } else { input.push(inputPortBuffer.substr(0, iddot+1)); /* 1 == strlen(":") */ inputPortBuffer.erase(0, iddot + 1); /* 1 == strlen(":") */ } } }