/** * used for now only while loading a file before the 0.6.0 version * reduce the exponant IN THE STRING of the amount because before the 0.6.0 * all the gdouble where saved with an exponent very big * ie : in the file we have "12.340000" * and that fonction return "12.34" wich will be nicely imported * with gsb_data_transaction_set_amount_from_string * * \param amount_string * \param exponent the exponent we want at the end (normally always 2, but if ever...) * * \return a newly allocated string with only 'exponent' digits after the separator (need to be freed). This function returns NULL if the amount_string parameter is NULL. * */ gchar *utils_str_reduce_exponant_from_string ( const gchar *amount_string, gint exponent ) { gchar *return_string; gchar *p; gchar *mon_decimal_point; gunichar decimal_point = (gunichar )-2; struct lconv *conv = localeconv ( ); if ( !amount_string ) return NULL; mon_decimal_point = g_locale_to_utf8 ( conv->mon_decimal_point, -1, NULL, NULL, NULL ); if ( mon_decimal_point ) decimal_point = g_utf8_get_char_validated ( mon_decimal_point, -1 ); return_string = my_strdup ( amount_string ); if ( ( p = g_utf8_strrchr ( (const gchar *) return_string, -1, '.' ) ) ) { if ( g_unichar_isdefined ( decimal_point ) && g_utf8_strchr ( p, 1, decimal_point ) == NULL ) { gchar **tab; tab = g_strsplit ( return_string, ".", 2 ); return_string = g_strjoinv ( mon_decimal_point, tab ); g_strfreev ( tab ); p = g_utf8_strrchr ( (const gchar *) return_string, -1, decimal_point ); } } else if ( ( p = g_utf8_strrchr ( (const gchar *) return_string, -1, ',' ) ) ) { if ( g_unichar_isdefined ( decimal_point ) && g_utf8_strchr ( p, 1, decimal_point ) == NULL ) { gchar **tab; tab = g_strsplit ( return_string, ",", 2 ); return_string = g_strjoinv ( mon_decimal_point, tab ); g_strfreev ( tab ); p = g_utf8_strrchr ( (const gchar *) return_string, -1, decimal_point ); } } else return NULL; p[exponent + 1] = '\0'; return return_string; }
/* * extrait un nombre d'une chaine * * \param chaine * * \return guint */ gchar *gsb_string_extract_int ( const gchar *chaine ) { gchar *ptr; gchar *tmpstr; gunichar ch; gint i = 0; gint long_nbre = 64; tmpstr = g_malloc0 ( long_nbre * sizeof (gchar) ); ptr = g_strdup ( chaine ); while ( g_utf8_strlen (ptr, -1) > 0 ) { ch = g_utf8_get_char_validated (ptr, -1); if ( g_unichar_isdefined ( ch ) && g_ascii_isdigit ( ch ) ) { if ( i == long_nbre ) break; tmpstr[i] = ptr[0]; i++; } ptr = g_utf8_next_char (ptr); } return tmpstr; }
gchar *mrim_package_read_LPS(MrimPackage *pack) { gsize str_len = mrim_package_read_UL(pack); if (str_len) { gpointer str = g_new(gchar, str_len); mrim_package_read_raw(pack, str, str_len); gboolean valid_utf16 = TRUE; { gunichar2 *string = str; glong i; for (i = 0; i < (str_len / 2); i++) { gunichar ch = string[i]; purple_debug_info("mrim-prpl", "[%s] Is char 0x%x defined??\n", __func__, ch); if ((!g_unichar_isdefined(ch)) || (ch >= 0xE000) && (ch < 0xF900)) { valid_utf16 = FALSE; break; } } } gchar *string; if (valid_utf16) { string = g_utf16_to_utf8(str, str_len / 2, NULL, NULL, NULL); } else { string = g_convert(str, str_len, "UTF8" , "CP1251", NULL, NULL, NULL); } g_free(str); return string; } else { return NULL; } }
inline static int keypress(Entry *e, gunichar uc) { if (!uc || !g_unichar_isdefined(uc)) return 0; /* Filter invalid characters, hopefully. XXX: is this enough to deny the PUA? */ if (e->bufused + 1 > e->bufsize) { /* If e->bufused * sizeof(e->buffer[0]) > 2**32, then there's a theoretical heap overflow on Really Big Systems. * Let's just clamp it to something nice and sane like 16kilochars */ if (e->bufsize >= 16384) return 0; /* We assume most lines will be relatively small, so just increase by 128 each time */ e->bufsize += 128; e->buffer = g_renew(gunichar, e->buffer, e->bufsize); } memmove(e->buffer + e->curs_off + 1, e->buffer + e->curs_off, sizeof(e->buffer[0]) * (e->bufused - e->curs_off)); e->buffer[e->curs_off] = uc; e->bufused++; e->curs_off++; e->dirty = TRUE; return 0; }