MySpellChecker::~MySpellChecker() { delete myspell; if (g_iconv_is_valid (m_translate_in )) g_iconv_close(m_translate_in); if (g_iconv_is_valid(m_translate_out)) g_iconv_close(m_translate_out); }
char * init_translation_table (int cpsource, int cpdisplay) { int i; GIConv cd; /* Fill inpit <-> display tables */ if (cpsource < 0 || cpdisplay < 0 || cpsource == cpdisplay) { for (i = 0; i <= 255; ++i) { conv_displ[i] = i; conv_input[i] = i; cp_source = cp_display; } return NULL; } for (i = 0; i <= 127; ++i) { conv_displ[i] = i; conv_input[i] = i; } cp_source = ((codepage_desc *) g_ptr_array_index (codepages, cpsource))->id; cp_display = ((codepage_desc *) g_ptr_array_index (codepages, cpdisplay))->id; /* display <- inpit table */ cd = g_iconv_open (cp_display, cp_source); if (cd == INVALID_CONV) return g_strdup_printf (_("Cannot translate from %s to %s"), cp_source, cp_display); for (i = 128; i <= 255; ++i) conv_displ[i] = translate_character (cd, i); g_iconv_close (cd); /* inpit <- display table */ cd = g_iconv_open (cp_source, cp_display); if (cd == INVALID_CONV) return g_strdup_printf (_("Cannot translate from %s to %s"), cp_display, cp_source); for (i = 128; i <= 255; ++i) { unsigned char ch; ch = translate_character (cd, i); conv_input[i] = (ch == UNKNCHAR) ? i : ch; } g_iconv_close (cd); return NULL; }
TextCodecGtk::~TextCodecGtk() { if (m_iconvDecoder != reinterpret_cast<GIConv>(-1)) { g_iconv_close(m_iconvDecoder); m_iconvDecoder = reinterpret_cast<GIConv>(-1); } if (m_iconvEncoder != reinterpret_cast<GIConv>(-1)) { g_iconv_close(m_iconvEncoder); m_iconvEncoder = reinterpret_cast<GIConv>(-1); } }
void str_uninit_strings (void) { if (str_cnv_not_convert != INVALID_CONV) g_iconv_close (str_cnv_not_convert); g_free (codeset); }
gchar * mc_search__recode_str (const char *str, gsize str_len, const char *charset_from, const char *charset_to, gsize * bytes_written) { gchar *ret; gsize bytes_read; GIConv conv; if (charset_from == NULL || charset_to == NULL || !strcmp (charset_to, charset_from)) { *bytes_written = str_len; return g_strndup (str, str_len); } conv = g_iconv_open (charset_to, charset_from); if (conv == INVALID_CONV) { *bytes_written = str_len; return g_strndup (str, str_len); } ret = g_convert_with_iconv (str, str_len, conv, &bytes_read, bytes_written, NULL); g_iconv_close (conv); if (ret == NULL) { *bytes_written = str_len; return g_strndup (str, str_len); } return ret; }
char *gnc_hbci_getremotename (const AB_TRANSACTION *h_trans) { /* Description */ char *othername = NULL; char *result; const GWEN_STRINGLIST *h_remotename = AB_Transaction_GetRemoteName (h_trans); struct cb_struct cb_object; cb_object.gnc_iconv_handler = g_iconv_open(gnc_hbci_book_encoding(), gnc_hbci_AQBANKING_encoding()); g_assert(cb_object.gnc_iconv_handler != (GIConv)(-1)); /* Get othername */ cb_object.result = &othername; if (h_remotename) GWEN_StringList_ForEach (h_remotename, &gnc_list_string_cb, &cb_object); /*DEBUG("HBCI Description '%s'", h_descr);*/ if (othername && (strlen (othername) > 0)) result = g_strdup (othername); else result = NULL; g_iconv_close(cb_object.gnc_iconv_handler); g_free (othername); return result; }
/* check if a charset is known by Iconv */ int servlist_check_encoding (char *charset) { GIConv gic; char *c; c = strchr (charset, ' '); if (c) c[0] = 0; if (!g_ascii_strcasecmp (charset, "IRC")) /* special case */ { if (c) c[0] = ' '; return TRUE; } gic = g_iconv_open (charset, "UTF-8"); if (c) c[0] = ' '; if (gic != (GIConv)-1) { g_iconv_close (gic); return TRUE; } return FALSE; }
static gboolean gedit_document_output_stream_close (GOutputStream *stream, GCancellable *cancellable, GError **error) { GeditDocumentOutputStream *ostream = GEDIT_DOCUMENT_OUTPUT_STREAM (stream); if (!ostream->priv->is_closed && ostream->priv->is_initialized) { end_append_text_to_document (ostream); if (ostream->priv->iconv != NULL) { g_iconv_close (ostream->priv->iconv); } ostream->priv->is_closed = TRUE; } if (ostream->priv->buflen > 0 || ostream->priv->iconv_buflen > 0) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA, _("Incomplete UTF-8 sequence in input")); return FALSE; } return TRUE; }
static void hildon_touch_selector_entry_finalize (GObject *object) { HildonTouchSelectorEntryPrivate *priv; priv = HILDON_TOUCH_SELECTOR_ENTRY_GET_PRIVATE (object); g_iconv_close (priv->converter); G_OBJECT_CLASS (hildon_touch_selector_entry_parent_class)->finalize (object); }
static void gxi_add_encoding (GncXmlImportData *data, gpointer encoding_ptr) { GIConv iconv; const gchar *message; gchar *enc_string; GtkListStore *store; GtkTreeIter iter; enc_string = g_ascii_strup ( g_quark_to_string (GPOINTER_TO_UINT (encoding_ptr)), -1); encoding_ptr = GUINT_TO_POINTER (g_quark_from_string (enc_string)); if (g_list_find (data->encodings, encoding_ptr)) { message = _("This encoding has been added to the list already."); gnc_error_dialog (data->encodings_dialog, "%s", message); return; } /* test whether we like this encoding */ iconv = g_iconv_open ("UTF-8", enc_string); if (iconv == (GIConv) - 1) { g_iconv_close (iconv); g_free (enc_string); message = _("This is an invalid encoding."); gnc_error_dialog (data->encodings_dialog, "%s", message); return; } g_iconv_close (iconv); /* add to the list */ data->encodings = g_list_append (data->encodings, encoding_ptr); store = GTK_LIST_STORE (gtk_tree_view_get_model (data->selected_encs_view)); gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, ENC_COL_STRING, enc_string, ENC_COL_QUARK, encoding_ptr, -1); g_free (enc_string); if (!data->encodings->next) gtk_dialog_set_response_sensitive (GTK_DIALOG (data->encodings_dialog), GTK_RESPONSE_OK, TRUE); }
static gboolean check_locale (const char *locale) { GIConv cd = g_iconv_open ("UTF-8", locale); if ((GIConv)-1 == cd) return FALSE; g_iconv_close (cd); return TRUE; }
static gboolean iconv_supported(const char *to, const char *from) { GIConv ic = g_iconv_open(to, from); if (ic == NULL || ic == (GIConv) -1) return FALSE; g_iconv_close(ic); return TRUE; }
void str_uninit_strings (void) { if (str_cnv_not_convert != INVALID_CONV) g_iconv_close (str_cnv_not_convert); /* NULL-ize pointers to avoid double free in unit tests */ MC_PTR_FREE (term_encoding); MC_PTR_FREE (codeset); }
gboolean TextCodecGtk::isEncodingAvailable(const gchar* encName) { GIConv tester; // test decoding tester = g_iconv_open(m_internalEncodingName, encName); if (tester == reinterpret_cast<GIConv>(-1)) { return false; } else { g_iconv_close(tester); // test encoding tester = g_iconv_open(encName, m_internalEncodingName); if (tester == reinterpret_cast<GIConv>(-1)) { return false; } else { g_iconv_close(tester); return true; } } }
static bool isEncodingAvailable(const gchar* encodingName) { GIConv tester; // test decoding tester = g_iconv_open(internalEncodingName, encodingName); if (tester == reinterpret_cast<GIConv>(-1)) { return false; } else { g_iconv_close(tester); // test encoding tester = g_iconv_open(encodingName, internalEncodingName); if (tester == reinterpret_cast<GIConv>(-1)) { return false; } else { g_iconv_close(tester); return true; } } }
TextStream::~TextStream () { if (fd != -1) close (fd); if (cd != (GIConv) -1) { g_iconv_close (cd); cd = (GIConv) -1; } }
static tvbuff_t * dissect_cbs_data(guint8 sms_encoding, tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, guint16 offset ) { tvbuff_t * tvb_out = NULL; guint8 out_len; int length = tvb_length(tvb) - offset; gchar *utf8_text = NULL; static unsigned char msgbuf[1024]; guint8 * input_string = tvb_get_ephemeral_string(tvb, offset, length); GIConv cd; GError *l_conv_error = NULL; switch(sms_encoding){ case SMS_ENCODING_7BIT: case SMS_ENCODING_7BIT_LANG: out_len = gsm_sms_char_7bit_unpack(0, length, sizeof(msgbuf), input_string, msgbuf); msgbuf[out_len] = '\0'; utf8_text = gsm_sms_chars_to_utf8(msgbuf, out_len); tvb_out = tvb_new_child_real_data(tvb, utf8_text, out_len, out_len); add_new_data_source(pinfo, tvb_out, "unpacked 7 bit data"); break; case SMS_ENCODING_8BIT: tvb_out = tvb_new_subset(tvb, offset, length, length); break; case SMS_ENCODING_UCS2: case SMS_ENCODING_UCS2_LANG: if ((cd = g_iconv_open("UTF-8","UCS-2BE")) != (GIConv) -1) { utf8_text = g_convert_with_iconv(input_string, length, cd, NULL, NULL, &l_conv_error); if(!l_conv_error) { tvb_out = tvb_new_subset(tvb, offset, length, length); } else proto_tree_add_text(tree, tvb, offset, length, "CBS String: g_convert_with_iconv FAILED"); g_free(utf8_text); g_iconv_close(cd); } else { proto_tree_add_text(tree, tvb, offset, length, "CBS String: g_iconv_open FAILED contact wireshark"); } break; default: proto_tree_add_text(tree, tvb, offset, length, "Unhandled encoding %d of CBS String", sms_encoding); break; } return tvb_out; }
ISpellChecker::~ISpellChecker() { if (m_bSuccessfulInit) { // only cleanup our mess if we were successfully initialized clearindex (m_pflagindex); clearindex (m_sflagindex); } FREEP(m_hashtbl); FREEP(m_hashstrings); FREEP(m_sflaglist); FREEP(m_chartypes); if (g_iconv_is_valid (m_translate_in )) g_iconv_close(m_translate_in); m_translate_in = G_ICONV_INVALID; if (g_iconv_is_valid(m_translate_out)) g_iconv_close(m_translate_out); m_translate_out = G_ICONV_INVALID; }
tvbuff_t * dissect_cbs_data(guint8 sms_encoding, tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, guint16 offset ) { tvbuff_t * tvb_out = NULL; int length = tvb_length(tvb) - offset; gchar *utf8_text = NULL, *utf8_out; guint8 * input_string; GIConv cd; GError *l_conv_error = NULL; switch(sms_encoding){ case SMS_ENCODING_7BIT: case SMS_ENCODING_7BIT_LANG: utf8_text = tvb_get_ts_23_038_7bits_string(wmem_packet_scope(), tvb, offset<<3, (length*8)/7); utf8_out = g_strdup(utf8_text); tvb_out = tvb_new_child_real_data(tvb, utf8_out, (guint)strlen(utf8_out), (guint)strlen(utf8_out)); tvb_set_free_cb(tvb_out, g_free); add_new_data_source(pinfo, tvb_out, "unpacked 7 bit data"); break; case SMS_ENCODING_8BIT: tvb_out = tvb_new_subset(tvb, offset, length, length); break; case SMS_ENCODING_UCS2: case SMS_ENCODING_UCS2_LANG: input_string = tvb_get_string(wmem_packet_scope(), tvb, offset, length); if ((cd = g_iconv_open("UTF-8","UCS-2BE")) != (GIConv) -1) { utf8_text = g_convert_with_iconv(input_string, length, cd, NULL, NULL, &l_conv_error); if(!l_conv_error) { tvb_out = tvb_new_subset(tvb, offset, length, length); } else proto_tree_add_text(tree, tvb, offset, length, "CBS String: g_convert_with_iconv FAILED"); g_free(utf8_text); g_iconv_close(cd); } else { proto_tree_add_text(tree, tvb, offset, length, "CBS String: g_iconv_open FAILED contact wireshark"); } break; default: proto_tree_add_text(tree, tvb, offset, length, "Unhandled encoding %d of CBS String", sms_encoding); break; } return tvb_out; }
void gftp_disconnect (gftp_request * request) { g_return_if_fail (request != NULL); #ifdef USE_SSL if (request->ssl != NULL) { SSL_free (request->ssl); request->ssl = NULL; } #endif #if GLIB_MAJOR_VERSION > 1 if (request->iconv_from_initialized) { g_iconv_close (request->iconv_from); request->iconv_from_initialized = 0; } if (request->iconv_to_initialized) { g_iconv_close (request->iconv_to); request->iconv_to_initialized = 0; } if (request->iconv_charset) { g_free (request->iconv_charset); request->iconv_charset = NULL; } #endif request->cached = 0; if (request->disconnect == NULL) return; request->disconnect (request); }
gboolean log_proto_server_options_set_encoding(LogProtoServerOptions *self, const gchar *encoding) { GIConv convert; g_free(self->encoding); self->encoding = g_strdup(encoding); /* validate encoding */ convert = g_iconv_open("utf8", encoding); if (convert == (GIConv) -1) return FALSE; g_iconv_close(convert); return TRUE; }
static gboolean is_valid_encoding(const char* encoding) { GIConv cd; if (encoding == NULL || encoding[0] == '\0') return FALSE; cd = g_iconv_open("UTF-8", encoding); if (cd == (GIConv)-1) { return FALSE; } g_iconv_close(cd); return TRUE; }
void log_proto_buffered_server_free_method(LogProtoServer *s) { LogProtoBufferedServer *self = (LogProtoBufferedServer *) s; log_transport_aux_data_destroy(&self->buffer_aux); g_free(self->buffer); if (self->state1) { g_free(self->state1); } if (self->convert != (GIConv) -1) g_iconv_close(self->convert); log_proto_server_free_method(s); }
void TextStream::Close () { if (fd != -1) { close (fd); fd = -1; } if (cd != (GIConv) -1) { g_iconv_close (cd); cd = (GIConv) -1; } bufptr = buffer; buflen = 0; eof = true; }
gchar * html_embedded_encode_string (const gchar *before, const gchar *codepage) { const gchar * str = before; static const gchar *safe = "$-._!*(),"; /* RFC 1738 */ unsigned pos = 0; GString *encoded = g_string_new (""); gchar buffer[5], *ptr; guchar c; GIConv iconv_cd = generate_iconv_to (codepage); if (is_valid_g_iconv (iconv_cd)) { str= convert_text_encoding (iconv_cd, before); g_iconv_close (iconv_cd); } while (pos < strlen (str)) { c = (guchar) str[pos]; if ((( c >= 'A') && (c <= 'Z')) || (( c >= 'a') && (c <= 'z')) || (( c >= '0') && (c <= '9')) || (strchr (safe, c))) { encoded = g_string_append_c (encoded, c); } else if (c == ' ') { encoded = g_string_append_c (encoded, '+'); } else if (c == '\n') { encoded = g_string_append (encoded, "%0D%0A"); } else if (c != '\r') { sprintf (buffer, "%%%02X", (gint) c); encoded = g_string_append (encoded, buffer); } pos++; } ptr = encoded->str; g_string_free (encoded, FALSE); return ptr; }
static gchar * mc_args__convert_help_to_syscharset (const gchar * charset, const gchar * error_message_str, const gchar * help_str) { GString *buffer; GIConv conv; gchar *full_help_str; buffer = g_string_new (""); conv = g_iconv_open (charset, "UTF-8"); full_help_str = g_strdup_printf ("%s\n\n%s\n", error_message_str, help_str); str_convert (conv, full_help_str, buffer); g_free (full_help_str); g_iconv_close (conv); return g_string_free (buffer, FALSE); }
gchar* g_convert (const gchar *str, gssize len, const gchar *to_codeset, const gchar *from_codeset, gsize *bytes_read, gsize *bytes_written, GError **error) { gchar *res; #ifdef HAVE_ICONV_H GIConv cd; g_return_val_if_fail (str != NULL, NULL); g_return_val_if_fail (to_codeset != NULL, NULL); g_return_val_if_fail (from_codeset != NULL, NULL); cd = open_converter (to_codeset, from_codeset, error); if (cd == (GIConv) -1) { if (bytes_read) *bytes_read = 0; if (bytes_written) *bytes_written = 0; return NULL; } res = g_convert_with_iconv (str, len, cd, bytes_read, bytes_written, error); g_iconv_close (cd); #else res = g_strdup(str); #endif return res; }
/* check if a charset is known by Iconv */ bool servlist_check_encoding(std::string charset) { auto space = charset.find_first_of(' '); if (space != std::string::npos) charset.resize(space); if (!g_ascii_strcasecmp (charset.c_str(), "IRC")) /* special case */ { return true; } auto gic = g_iconv_open (charset.c_str(), "UTF-8"); if (gic != (GIConv)-1) { g_iconv_close (gic); return true; } return false; }
/* check if a charset is known by Iconv */ int servlist_check_encoding (char *charset) { GIConv gic; char *c; c = strchr (charset, ' '); if (c) c[0] = 0; gic = g_iconv_open (charset, "UTF-8"); if (c) c[0] = ' '; if (gic != (GIConv)-1) { g_iconv_close (gic); return TRUE; } return FALSE; }
char *gnc_hbci_getpurpose (const AB_TRANSACTION *h_trans) { /* Description */ char *h_descr = NULL; char *g_descr; const GWEN_STRINGLIST *h_purpose = AB_Transaction_GetPurpose (h_trans); struct cb_struct cb_object; cb_object.gnc_iconv_handler = g_iconv_open(gnc_hbci_book_encoding(), gnc_hbci_AQBANKING_encoding()); g_assert(cb_object.gnc_iconv_handler != (GIConv)(-1)); cb_object.result = &h_descr; if (h_purpose) GWEN_StringList_ForEach (h_purpose, &gnc_list_string_cb, &cb_object); g_descr = g_strdup (h_descr ? h_descr : ""); g_iconv_close(cb_object.gnc_iconv_handler); g_free (h_descr); return g_descr; }