static JSBool gjs_locale_to_lower_case (JSContext *context, JSString *src, jsval *retval) { JSBool success = JS_FALSE; char *utf8 = NULL; char *lower_case_utf8 = NULL; if (!gjs_string_to_utf8(context, STRING_TO_JSVAL(src), &utf8)) goto out; lower_case_utf8 = g_utf8_strdown (utf8, -1); if (!gjs_string_from_utf8(context, lower_case_utf8, -1, retval)) goto out; success = JS_TRUE; out: g_free(utf8); g_free(lower_case_utf8); return success; }
int enchant_pwl_check(EnchantPWL *pwl, const char *const word, size_t len) { int exists = 0; int isAllCaps = 0; enchant_pwl_refresh_from_file(pwl); exists = enchant_pwl_contains(pwl, word, len); if(exists) return 0; if(enchant_is_title_case(word, len) || (isAllCaps = enchant_is_all_caps(word, len))) { char * lower_case_word = g_utf8_strdown(word, len); exists = enchant_pwl_contains(pwl, lower_case_word, strlen(lower_case_word)); g_free(lower_case_word); if(exists) return 0; if(isAllCaps) { char * title_case_word = enchant_utf8_strtitle(word, len); exists = enchant_pwl_contains(pwl, title_case_word, strlen(title_case_word)); g_free(title_case_word); if(exists) return 0; } } return 1; /* not found */ }
static gchar *format_user(ParserVars *vars, const gchar *ts, const gchar *inner) { const gchar *url_pattern = "<a href=\"http://www.f-list.net/c/%s\">%s</a>"; gchar *lower = g_utf8_strdown(inner, -1); gchar *ret = g_strdup_printf(url_pattern, purple_url_encode(lower), inner); g_free(lower); return ret; }
static GSList *sort_entries(GSList *l, uint8_t order, uint8_t search_attrib, const char *value) { GSList *sorted = NULL; cache_entry_find_f find; GCompareFunc sort; char *searchval; /* * Default sorter is "Indexed". Some backends doesn't inform the index, * for this case a sequential internal index is assigned. * 0x00 = indexed * 0x01 = alphanumeric * 0x02 = phonetic */ switch (order) { case 0x01: sort = alpha_sort; break; case 0x02: sort = phonetical_sort; break; default: sort = indexed_sort; break; } /* * This implementation checks if the given field CONTAINS the * search value(case insensitive). Name is the default field * when the attribute is not provided. */ switch (search_attrib) { /* Number */ case 1: find = entry_tel_find; break; /* Sound */ case 2: find = entry_sound_find; break; default: find = entry_name_find; break; } searchval = value ? g_utf8_strdown(value, -1) : NULL; for (; l; l = l->next) { struct cache_entry *entry = l->data; if (searchval && !find(entry, (const char *) searchval)) continue; sorted = g_slist_insert_sorted(sorted, entry, sort); } g_free(searchval); return sorted; }
static gchar* enchant_utf8_strtitle(const gchar*str, gssize len) { gunichar title_case_char; gchar* result; gchar* upperStr, * upperTail, * lowerTail; gchar title_case_utf8[7]; gint utf8len; upperStr = g_utf8_strup(str, len); /* for locale sensitive casing */ title_case_char = g_unichar_totitle(g_utf8_get_char(upperStr)); utf8len = g_unichar_to_utf8(title_case_char, title_case_utf8); title_case_utf8[utf8len] = '\0'; upperTail = g_utf8_next_char(upperStr); lowerTail = g_utf8_strdown(upperTail, -1); result = g_strconcat(title_case_utf8, lowerTail, NULL); g_free(upperStr); g_free(lowerTail); return result; }
/* check for the clues */ static gboolean check_for_attachment_clues (gchar *msg) { /* TODO : Add more strings. RegEx ??? */ GConfClient *gconf; GSList *clue_list = NULL, *list; gboolean ret_val = FALSE; guint msg_length; gconf = gconf_client_get_default (); /* Get the list from gconf */ clue_list = gconf_client_get_list ( gconf, GCONF_KEY_ATTACH_REMINDER_CLUES, GCONF_VALUE_STRING, NULL ); g_object_unref (gconf); msg_length = strlen (msg); for (list = clue_list;list && !ret_val;list=g_slist_next(list)) { gchar *needle = g_utf8_strdown (list->data, -1); if (g_strstr_len (msg, msg_length, needle)) { ret_val = TRUE; } g_free (needle); } if (clue_list) { g_slist_foreach (clue_list, (GFunc) g_free, NULL); g_slist_free (clue_list); } return ret_val; }
static gchar* strip_text_msg (gchar *msg) { gchar **lines = g_strsplit ( msg, "\n", -1); gchar *stripped_msg = g_strdup (" "); guint i=0; gchar *temp; /* Note : HTML Signatures won't work. Depends on Bug #522784 */ while (lines [i] && g_strcmp0 (lines[i], SIGNATURE)){ if (!g_str_has_prefix (g_strstrip(lines[i]), ">")){ temp = stripped_msg; stripped_msg = g_strconcat (" ", stripped_msg, lines[i], NULL); g_free (temp); } i++; } g_strfreev (lines); temp = g_utf8_strdown (stripped_msg, -1); g_free (stripped_msg); return temp; }
static void gnac_playlist_parse_xspf(GFile *file) { GFile *parent = g_file_get_parent(file); gchar *contents = gnac_playlist_read_file(file); if (!contents) return; gchar **lines = g_strsplit(contents, "\n", -1); guint i; for (i = 0; lines[i]; i++) { /* skip empty lines */ if (!*lines[i]) continue; gchar *line = g_strstrip(lines[i]); gchar *lc_line = g_utf8_strdown(lines[i], -1); if (g_str_has_prefix(lc_line, "<location>")) { gchar **tmp1 = g_strsplit(line, ">", 2); gchar **tmp2 = g_strsplit(tmp1[1], "<", 2); g_strfreev(tmp1); line = tmp2[0]; gnac_playlist_resolve_uri_and_add(parent, line); g_strfreev(tmp2); } g_free(lc_line); } g_strfreev(lines); g_free(contents); }
/* ==================================== */ static gint item_event(GooCanvasItem *item, GooCanvasItem *target, GdkEvent *event, gpointer data) { if(board_paused) return FALSE; gchar *answer = g_utf8_strdown ( (gchar*)data , -1 ); switch (event->type) { case GDK_BUTTON_PRESS: /* We really don't want the user to change his/her mind */ board_paused = TRUE; if ( strcmp(answer, right_letter) == 0 ) { gamewon = TRUE; } else { gamewon = FALSE; } highlight_selected(item); process_ok(); break; default: break; } g_free(answer); return FALSE; }
static void gnac_playlist_parse_pls(GFile *file) { GFile *parent = g_file_get_parent(file); gchar *contents = gnac_playlist_read_file(file); if (!contents) return; gchar **lines = g_strsplit(contents, "\n", -1); guint i; for (i = 0; lines[i]; i++) { /* skip empty lines */ if (!*lines[i]) continue; gchar **pair = g_strsplit(lines[i], "=", 2); gchar *key = g_utf8_strdown(pair[0], -1); if (pair[1] && g_str_has_prefix(key, "file")) { gnac_playlist_resolve_uri_and_add(parent, pair[1]); } g_free(key); g_strfreev(pair); } g_strfreev(lines); g_free(contents); }
static gchar * get_avatar (const gchar *field) { GMatchInfo *match_info = NULL; gchar *avatar = NULL; gchar *email; gchar *email_hash; gchar *lowercased_field; static GRegex *email_regex = NULL; if (!field) { return NULL; } lowercased_field = g_utf8_strdown (field, -1); if (!email_regex) { email_regex = g_regex_new ("[\\w-]+@([\\w-]+\\.)+[\\w-]+", G_REGEX_OPTIMIZE, 0, NULL); } if (g_regex_match (email_regex, lowercased_field, 0, &match_info)) { email = g_match_info_fetch (match_info, 0); g_match_info_free (match_info); email_hash = g_compute_checksum_for_string (G_CHECKSUM_MD5, email, -1); avatar = g_strdup_printf (GRAVATAR_URL, email_hash); g_free (email); g_free (email_hash); } return avatar; }
/** * ppg_add_instrument_dialog_filter_func: * @filter: (in): A #GtkTreeModel. * @iter: (in): A #GtkTreeIter. * @user_data: (in): A #PpgAddInstrumentDialog. * * A #GtkTreeModelFilterVisibleFunc to check to see if the row matches the * current search text. * * Returns: %TRUE if the search text matches; otherwise %FALSE. * Side effects: None. */ static gboolean ppg_add_instrument_dialog_filter_func (GtkTreeModel *filter, GtkTreeIter *iter, gpointer user_data) { PpgAddInstrumentDialog *dialog = (PpgAddInstrumentDialog *)user_data; PpgAddInstrumentDialogPrivate *priv = dialog->priv; const gchar *text = gtk_entry_get_text((GtkEntry *)priv->entry); gchar *lower; gchar *fulltext; gboolean ret; if (!text || !text[0]) { return TRUE; } gtk_tree_model_get(filter, iter, PPG_INSTRUMENTS_STORE_COLUMN_FULLTEXT, &fulltext, -1); lower = g_utf8_strdown(text, -1); ret = !!strstr(fulltext, lower); g_free(fulltext); g_free(lower); return ret; }
static gboolean filter_tag(tagEntry *entry, GPatternSpec *name, gboolean declaration, gboolean case_sensitive) { gboolean filter = TRUE; gchar *entry_name; if (!EMPTY(entry->kind)) { gboolean is_prototype; is_prototype = g_strcmp0(entry->kind, "prototype") == 0; filter = (declaration && !is_prototype) || (!declaration && is_prototype); if (filter) return TRUE; } if (case_sensitive) entry_name = g_strdup(entry->name); else entry_name = g_utf8_strdown(entry->name, -1); filter = !g_pattern_match_string(name, entry_name); g_free(entry_name); return filter; }
static gboolean simple_filter_search_keyrelease_handler(GtkEntry *entry, PraghaFilterDialog *fdialog) { gchar *text = NULL; gchar *u_str = NULL; gboolean has_text; if (fdialog->filter_string != NULL) { g_free (fdialog->filter_string); fdialog->filter_string = NULL; } has_text = gtk_entry_get_text_length (GTK_ENTRY(entry)) > 0; if (has_text) { text = gtk_editable_get_chars (GTK_EDITABLE(entry), 0, -1); u_str = g_utf8_strdown (text, -1); fdialog->filter_string = u_str; } gtk_entry_set_icon_sensitive (GTK_ENTRY(entry), GTK_ENTRY_ICON_SECONDARY, has_text); if (!pragha_preferences_get_instant_search(fdialog->preferences)) return FALSE; queue_filter_dialog_refilter(fdialog); return FALSE; }
/* Setup the fileitem, depending uri's scheme * Return a string to search in. */ static gchar * fileitem_setup (FileItem *item) { gchar *scheme; gchar *filename; gchar *candidate = NULL; gchar *path; gchar *name; scheme = g_uri_parse_scheme (item->uri); if (g_strcmp0 (scheme, "file") == 0) { filename = g_filename_from_uri ((const gchar *)item->uri, NULL, NULL); if (filename) { path = g_path_get_dirname (filename); item->path = g_filename_to_utf8 (path, -1, NULL, NULL, NULL); g_free (path); name = g_path_get_basename (filename); item->name = g_filename_to_utf8 (name, -1, NULL, NULL, NULL); g_free (name); candidate = g_utf8_strdown (filename, -1); g_free (filename); } } g_free (scheme); return candidate; }
gchar * gebr_geoxml_line_create_key(const gchar *title) { gchar *lower_no_accents = g_utf8_strdown(title, -1); lower_no_accents = gebr_g_string_remove_accents(lower_no_accents); GString *buffer = g_string_new(NULL); gchar *tmp = lower_no_accents; gunichar c; for (; tmp && *tmp; tmp = g_utf8_next_char(tmp)) { c = g_utf8_get_char(tmp); if (c == ' ' || !g_ascii_isalnum((char)c)) { g_string_append_c(buffer, '_'); } else { gchar str[7]; gint len = g_unichar_to_utf8(c, str); g_string_append_len(buffer, str, len); } } g_string_append_c(buffer, '\0'); g_free(lower_no_accents); return g_string_free(buffer, FALSE); }
static void doc_code_selection(Tdocument * doc, Treplace_mode mode) { gint start, end; if (doc_get_selection(doc, &start, &end)) { gchar *inbuf, *outbuf = NULL; inbuf = doc_get_chars(doc, start, end); switch (mode) { case mode_urlencode: outbuf = g_uri_escape_string(inbuf, NULL, FALSE); break; case mode_urldecode: outbuf = g_uri_unescape_string(inbuf, NULL); break; case mode_tolowercase: if (inbuf) outbuf = g_utf8_strdown(inbuf, -1); break; case mode_touppercase: if (inbuf) outbuf = g_utf8_strup(inbuf, -1); break; } g_free(inbuf); if (outbuf) { doc_replace_text(doc, outbuf, start, end); g_free(outbuf); } } }
static gboolean simple_filter_search_activate_handler(GtkEntry *entry, PraghaFilterDialog *fdialog) { const gchar *text = NULL; gchar *u_str = NULL; gboolean has_text; has_text = gtk_entry_get_text_length (GTK_ENTRY(entry)) > 0; if (fdialog->filter_string != NULL) { g_free (fdialog->filter_string); fdialog->filter_string = NULL; } if (has_text) { text = gtk_entry_get_text (entry); u_str = g_utf8_strdown (text, -1); fdialog->filter_string = u_str; } gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER(fdialog->filter_model)); return FALSE; }
static gpointer filetype_search(GTree *tree, const gchar *filename, gint *priority, const RSLoaderFlags flags) { gpointer func = NULL; const gchar *extension; extension = g_strrstr(filename, "."); if (extension) { struct search_needle needle; needle.extension = g_utf8_strdown(extension, -1); needle.priority = priority; needle.func = NULL; needle.flags = flags; g_static_mutex_lock(&lock); g_tree_foreach(tree, filetype_search_traverse, &needle); g_static_mutex_unlock(&lock); g_free(needle.extension); func = needle.func; } return func; }
static void simple_filter_search_keyrelease_handler (GtkEntry *entry, PraghaFilterDialog *fdialog) { const gchar *text = NULL; gchar *u_str = NULL; gboolean has_text; if (fdialog->filter_string != NULL) { g_free (fdialog->filter_string); fdialog->filter_string = NULL; } has_text = gtk_entry_get_text_length (GTK_ENTRY(entry)) > 0; if (has_text) { text = gtk_entry_get_text (entry); u_str = g_utf8_strdown (text, -1); fdialog->filter_string = u_str; } if (!pragha_preferences_get_instant_search(fdialog->preferences)) return; queue_filter_dialog_refilter(fdialog); }
static gboolean filter_model_visible_func (GtkTreeModel *model, GtkTreeIter *iter, PraghaFilterDialog *fdialog) { gchar *haystack = NULL, *haystackd = NULL, *needle = NULL; gboolean approximate, visible = FALSE; if(!fdialog->filter_string) return TRUE; gtk_tree_model_get(model, iter, 1, &haystack, -1); needle = fdialog->filter_string; haystackd = g_utf8_strdown (haystack, -1); approximate = pragha_preferences_get_approximate_search(fdialog->preferences); if(g_strstr_lv(haystackd, needle, approximate ? 1 : 0)) visible = TRUE; g_free(haystack); g_free(haystackd); return visible; }
/* this implementation should work for _all_ locales. */ static char* mu_str_normalize_in_place_generic (char *str, gboolean downcase, GStringChunk *strchunk) { char *norm; size_t len; /* FIXME: add accent-folding etc. */ if (!downcase) return str; /* nothing to do */ len = strlen (str); norm = g_utf8_strdown (str, len); if (strlen (norm) > len) { /* this case is rare, but does happen */ char *copy; if (!strchunk) return norm; copy = g_string_chunk_insert (strchunk, norm); g_free (norm); return copy; } memcpy (str, norm, len); return str; }
const gchar * ide_get_system_type (void) { static gchar *system_type; g_autofree gchar *os_lower = NULL; const gchar *machine = NULL; struct utsname u; if (system_type != NULL) return system_type; if (uname (&u) < 0) return g_strdup ("unknown"); os_lower = g_utf8_strdown (u.sysname, -1); /* config.sub doesn't accept amd64-OS */ machine = strcmp (u.machine, "amd64") ? u.machine : "x86_64"; /* * TODO: Clearly we want to discover "gnu", but that should be just fine * for a default until we try to actually run on something non-gnu. * Which seems unlikely at the moment. If you run FreeBSD, you can * probably fix this for me :-) And while you're at it, make the * uname() call more portable. */ #ifdef __GLIBC__ system_type = g_strdup_printf ("%s-%s-%s", machine, os_lower, "gnu"); #else system_type = g_strdup_printf ("%s-%s", machine, os_lower); #endif return system_type; }
static void find_file(GtkTreeIter *iter) { gchar *pattern_str = NULL; gboolean case_sensitive, full_path; gchar *path; path = build_path(iter); if (show_dialog_find_file(iter ? path : NULL, &pattern_str, &case_sensitive, &full_path) == GTK_RESPONSE_ACCEPT) { GPatternSpec *pattern; if (!case_sensitive) SETPTR(pattern_str, g_utf8_strdown(pattern_str, -1)); pattern = g_pattern_spec_new(pattern_str); msgwin_clear_tab(MSG_MESSAGE); msgwin_set_messages_dir(get_project_base_path()); find_file_recursive(iter, case_sensitive, full_path, pattern); msgwin_switch_tab(MSG_MESSAGE, TRUE); } g_free(pattern_str); g_free(path); }
static gboolean plank_drawing_drawing_service_icon_is_file (const gchar* name) { gboolean result = FALSE; gboolean _tmp0_ = FALSE; gboolean _tmp1_ = FALSE; const gchar* _tmp2_ = NULL; gboolean _tmp3_ = FALSE; g_return_val_if_fail (name != NULL, FALSE); _tmp2_ = name; _tmp3_ = g_str_has_prefix (_tmp2_, "/"); if (_tmp3_) { _tmp1_ = TRUE; } else { const gchar* _tmp4_ = NULL; gboolean _tmp5_ = FALSE; _tmp4_ = name; _tmp5_ = g_str_has_prefix (_tmp4_, "~/"); _tmp1_ = _tmp5_; } if (_tmp1_) { _tmp0_ = TRUE; } else { const gchar* _tmp6_ = NULL; gchar* _tmp7_ = NULL; gchar* _tmp8_ = NULL; gboolean _tmp9_ = FALSE; _tmp6_ = name; _tmp7_ = g_utf8_strdown (_tmp6_, (gssize) (-1)); _tmp8_ = _tmp7_; _tmp9_ = g_str_has_prefix (_tmp8_, "file://"); _tmp0_ = _tmp9_; _g_free0 (_tmp8_); } result = _tmp0_; return result; }
gint _check_for_distribution_license(gchar *mod_name) { gchar *distributionlicense; gchar *conf_file; conf_file = g_strdup_printf("%s/" DOTSWORD "/mods.d/%s.conf", settings.homedir, g_utf8_strdown(mod_name, -1)); if (g_file_test(conf_file, G_FILE_TEST_EXISTS)) distributionlicense = get_conf_file_item(conf_file, mod_name, "DistributionLicense"); else distributionlicense = main_get_mod_config_entry(mod_name, "DistributionLicense"); g_free(conf_file); XI_message(("DistributionLicense: %s", distributionlicense)); if (!distributionlicense || (distributionlicense && g_strstr_len(distributionlicense, strlen(distributionlicense), "Copyright"))) { if (main_get_one_option(mod_name, OP_NAME) == 0) { gui_generic_warning(_("Please check copyright before exporting!")); main_save_module_options(mod_name, OP_NAME, 1); } return 1; } return 0; }
/* Process a chat message that is being received. * Check the contents of *buffer to see if it contains any of my aliases. * If it does, make *flags include the PURPLE_MESSAGE_NICK flag. * When done, return FALSE to indicate the message should *not* be ignored. */ static gboolean receiving_chat_msg_cb(PurpleAccount *account, char **sender, char **buffer, PurpleConversation *chat, PurpleMessageFlags *flags, void *data) { /* pointer into the aliases list */ GSList *alias_ptr = aliases_list ; /* a copy of the [utf8] message transformed to lowercase */ gchar *lcmsg = g_utf8_strdown( *buffer, -1 ) ; purple_debug_info(PLUGIN_ID, "AKA Plugin checking message \"%s\".\n", lcmsg) ; /* loop through each alias and check to see if it exists in the message */ while (alias_ptr != NULL) { purple_debug_info(PLUGIN_ID, "AKA Plugin checking against \"%s\".\n", (char*)alias_ptr->data) ; if (find_utf8_substr(lcmsg, alias_ptr->data) != NULL) { purple_debug_info(PLUGIN_ID, "AKA Plugin found a match!\n") ; /* The alias exists; set the NICK flag to indicate this * message was directed at us, and break out of the alias * loop. */ *flags |= PURPLE_MESSAGE_NICK ; break ; /* out of while (alias_ptr != NULL) loop */ } /* remember to not infinite loop on the same alias pointer... */ alias_ptr = alias_ptr->next ; } /* free our lowercase copy of the message */ free(lcmsg) ; /* return FALSE says the message should not be ignored. */ return FALSE ; }
static GType gst_aasink_drivers_get_type (void) { static GType driver_type = 0; if (!driver_type) { GEnumValue *drivers; const struct aa_driver *driver; gint n_drivers; gint i; for (n_drivers = 0; aa_drivers[n_drivers]; n_drivers++) { /* count number of drivers */ } drivers = g_new0 (GEnumValue, n_drivers + 1); for (i = 0; i < n_drivers; i++) { driver = aa_drivers[i]; drivers[i].value = i; drivers[i].value_name = g_strdup (driver->name); drivers[i].value_nick = g_utf8_strdown (driver->shortname, -1); } drivers[i].value = 0; drivers[i].value_name = NULL; drivers[i].value_nick = NULL; driver_type = g_enum_register_static ("GstAASinkDrivers", drivers); } return driver_type; }
static gboolean simple_filter_search_activate_handler(GtkEntry *entry, PraghaFilterDialog *fdialog) { gchar *text = NULL; gchar *u_str = NULL; gboolean has_text; has_text = gtk_entry_get_text_length (GTK_ENTRY(entry)) > 0; if (fdialog->filter_string != NULL) { g_free (fdialog->filter_string); fdialog->filter_string = NULL; } if (has_text) { text = gtk_editable_get_chars (GTK_EDITABLE(entry), 0, -1); u_str = g_utf8_strdown (text, -1); fdialog->filter_string = u_str; } gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER(fdialog->filter_model)); gtk_entry_set_icon_sensitive (GTK_ENTRY(entry), GTK_ENTRY_ICON_SECONDARY, has_text); g_free (text); return FALSE; }
static void update_words (ExampleAppWindow *win) { ExampleAppWindowPrivate *priv; GHashTable *strings; GHashTableIter iter; GtkWidget *tab, *view, *row; GtkTextBuffer *buffer; GtkTextIter start, end; GList *children, *l; gchar *word, *key; priv = example_app_window_get_instance_private (win); tab = gtk_stack_get_visible_child (GTK_STACK (priv->stack)); if (tab == NULL) return; view = gtk_bin_get_child (GTK_BIN (tab)); buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); strings = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); gtk_text_buffer_get_start_iter (buffer, &start); while (!gtk_text_iter_is_end (&start)) { while (!gtk_text_iter_starts_word (&start)) { if (!gtk_text_iter_forward_char (&start)) goto done; } end = start; if (!gtk_text_iter_forward_word_end (&end)) goto done; word = gtk_text_buffer_get_text (buffer, &start, &end, FALSE); g_hash_table_add (strings, g_utf8_strdown (word, -1)); g_free (word); start = end; } done: children = gtk_container_get_children (GTK_CONTAINER (priv->words)); for (l = children; l; l = l->next) gtk_container_remove (GTK_CONTAINER (priv->words), GTK_WIDGET (l->data)); g_list_free (children); g_hash_table_iter_init (&iter, strings); while (g_hash_table_iter_next (&iter, (gpointer *)&key, NULL)) { row = gtk_button_new_with_label (key); g_signal_connect (row, "clicked", G_CALLBACK (find_word), win); gtk_widget_show (row); gtk_container_add (GTK_CONTAINER (priv->words), row); } g_hash_table_unref (strings); }