/** * seahorse_util_string_up_first: * @orig: The utf8 string to work with * * Upper case the first char in the UTF8 string * * Returns: a new string, with the first char upper cased. The returned string * should be freed with #g_free when no longer needed. */ gchar* seahorse_util_string_up_first (const gchar *orig) { gchar *t, *t2, *ret; if (g_utf8_validate (orig, -1, NULL)) { t = g_utf8_find_next_char (orig, NULL); if (t != NULL) { t2 = g_utf8_strup (orig, t - orig); ret = g_strdup_printf ("%s%s", t2, t); g_free (t2); /* Can't find first UTF8 char */ } else { ret = g_strdup (orig); } /* Just use ASCII functions when not UTF8 */ } else { ret = g_strdup (orig); ret[0] = g_ascii_toupper (ret[0]); } return ret; }
void oio_log_init_level_from_env(const gchar *k) { const gchar *v = g_getenv(k); if (v) { switch (g_ascii_toupper(*v)) { case 'T': oio_log_init_level(GRID_LOGLVL_TRACE2); return; case 'D': oio_log_init_level(GRID_LOGLVL_DEBUG); return; case 'I': oio_log_init_level(GRID_LOGLVL_INFO); return; case 'N': oio_log_init_level(GRID_LOGLVL_NOTICE); return; case 'W': oio_log_init_level(GRID_LOGLVL_WARN); return; case 'E': oio_log_init_level(GRID_LOGLVL_ERROR); return; } } }
/* Returns the option name for the param spec, used by thunarx_renamer_real_load/save() */ gchar* thunarx_param_spec_get_option_name (GParamSpec *pspec) { const gchar *s; gboolean upper = TRUE; gchar *name; gchar *t; name = g_new (gchar, strlen (pspec->name) + 1); for (s = pspec->name, t = name; *s != '\0'; ++s) { if (*s == '-') { upper = TRUE; } else if (upper) { *t++ = g_ascii_toupper (*s); upper = FALSE; } else { *t++ = *s; } } *t = '\0'; return name; }
/* allocates space and returns the index part of a string */ static char * _new_get_index(const char *_string) { if (!_string) return NULL; size_t size; gunichar u; char *string = NULL; if (g_ascii_isalnum(_string[0])) { size = sizeof(char); string = malloc(size+1); string[0] = g_ascii_toupper(_string[0]); } else { u = g_utf8_get_char_validated(_string, -1); if ((u != (gunichar)-1 || u != (gunichar)-2) && g_unichar_isalnum(u)) { u = g_unichar_toupper(u); size = g_unichar_to_utf8(u, NULL); string = malloc(size+1); g_unichar_to_utf8(u, string); } } if (string) string[size] = '\0'; return string; }
static gchar * gimp_file_proc_view_pattern_from_extension (const gchar *extension) { gchar *pattern; gchar *p; gint len, i; g_return_val_if_fail (extension != NULL, NULL); /* This function assumes that file extensions are 7bit ASCII. It * could certainly be rewritten to handle UTF-8 if this assumption * turns out to be incorrect. */ len = strlen (extension); pattern = g_new (gchar, 4 + 4 * len); strcpy (pattern, "*."); for (i = 0, p = pattern + 2; i < len; i++, p+= 4) { p[0] = '['; p[1] = g_ascii_tolower (extension[i]); p[2] = g_ascii_toupper (extension[i]); p[3] = ']'; } *p = '\0'; return pattern; }
gchar * mousepad_util_config_name (const gchar *name) { const gchar *s; gchar *config, *t; gboolean upper = TRUE; /* allocate string */ config = g_new (gchar, strlen (name) + 1); /* convert name */ for (s = name, t = config; *s != '\0'; ++s) { if (*s == '-') { upper = TRUE; } else if (upper) { *t++ = g_ascii_toupper (*s); upper = FALSE; } else { *t++ = g_ascii_tolower (*s); } } /* zerro terminate string */ *t = '\0'; return config; }
static void uuid_randomize(gchar *d, gsize dl) { static guint32 seq = 0; struct { int pid, ppid; GTimeVal now; guint32 seq; gpointer p0, p1, p2; gchar h[512]; } bulk; memset(&bulk, 0, sizeof(bulk)); bulk.pid = getpid(); bulk.ppid = getppid(); g_get_current_time(&(bulk.now)); bulk.seq = ++seq; bulk.p0 = &bulk; bulk.p1 = d; bulk.p2 = &d; gethostname(bulk.h, sizeof(bulk.h)); GChecksum *cs = g_checksum_new(G_CHECKSUM_SHA256); g_checksum_update(cs, (guint8*) &bulk, sizeof(bulk)); g_strlcpy(d, g_checksum_get_string(cs), dl); g_checksum_free(cs); for (; dl ;--dl) d[dl-1] = g_ascii_toupper(d[dl-1]); }
static char* uscore_to_wincaps (const char *uscore) { const char *p; GString *str; gboolean last_was_uscore; last_was_uscore = TRUE; str = g_string_new (NULL); p = uscore; while (p && *p) { if (*p == '-' || *p == '_') last_was_uscore = TRUE; else { if (last_was_uscore) { g_string_append_c (str, g_ascii_toupper (*p)); last_was_uscore = FALSE; } else g_string_append_c (str, *p); } ++p; } return g_string_free (str, FALSE); }
static gchar* property_name_to_option_name (const gchar *property_name) { const gchar *s; gboolean upper = TRUE; gchar *option; gchar *t; option = g_new (gchar, strlen (property_name) + 1); for (s = property_name, t = option; *s != '\0'; ++s) { if (*s == '-') { upper = TRUE; } else if (upper) { *t++ = g_ascii_toupper (*s); upper = FALSE; } else { *t++ = *s; } } *t = '\0'; return option; }
static char * camel_case (const char *s) { int si, ri; char *r = g_malloc (strlen (s) + 1); gboolean upper = FALSE; for (ri = si = 0; s[si]; si++) { switch (s[si]) { case '-': case '_': upper = TRUE; break; default: if (upper) { r[ri++] = g_ascii_toupper (s[si]); upper = FALSE; } else { r[ri++] = s[si]; } break; } } r[ri] = s[si]; /*g_print ("%s:%d:%s: %s -> %s\n", __FILE__, __LINE__, __FUNCTION__, s, r);*/ return r; }
static gchar* unisoku_find_data_name(const gchar *header_name) { GString *data_name; gchar *retval; gboolean ok = FALSE; data_name = g_string_new(header_name); g_string_truncate(data_name, data_name->len - (sizeof(EXTENSION_HEADER) - 1)); g_string_append(data_name, EXTENSION_DATA); if (g_file_test(data_name->str, G_FILE_TEST_IS_REGULAR)) ok = TRUE; else { guint i; for (i = 0; i < sizeof(EXTENSION_DATA); i++) data_name->str[data_name->len-1 - i] = g_ascii_toupper(data_name->str[data_name->len-1 - i]); if (g_file_test(data_name->str, G_FILE_TEST_IS_REGULAR)) ok = TRUE; } retval = data_name->str; g_string_free(data_name, !ok); return ok ? retval : NULL; }
static gchar* id_to_macro (const gchar *id) { GString *macro = NULL; const gchar *cp; /* gtk-foo-bar -> GTK_STOCK_FOO_BAR */ macro = g_string_new (NULL); cp = id; if (strncmp (cp, "gtk-", 4) == 0) { g_string_append (macro, "GTK_STOCK_"); cp += 4; } while (*cp) { if (*cp == '-') g_string_append_c (macro, '_'); else if (g_ascii_islower (*cp)) g_string_append_c (macro, g_ascii_toupper (*cp)); else g_string_append_c (macro, *cp); cp++; } return g_string_free (macro, FALSE); }
static nsCAutoString MakeCaseInsensitiveShellGlob(const char* aPattern) { // aPattern is UTF8 nsCAutoString result; unsigned int len = strlen(aPattern); for (unsigned int i = 0; i < len; i++) { if (!g_ascii_isalpha(aPattern[i])) { // non-ASCII characters will also trigger this path, so unicode // is safely handled albeit case-sensitively result.Append(aPattern[i]); continue; } // add the lowercase and uppercase version of a character to a bracket // match, so it matches either the lowercase or uppercase char. result.Append('['); result.Append(g_ascii_tolower(aPattern[i])); result.Append(g_ascii_toupper(aPattern[i])); result.Append(']'); } return result; }
static PyObject *kb_manager_send_command(PyObject *module, PyObject *args, PyObject *kwargs) { gchar *key; static gchar *kwlist[] = { "key", NULL }; if (PyArg_ParseTupleAndKeywords(args, kwargs, "s", kwlist, &key)) { if (key) { KeyCmdHashEntry*he = NULL; gchar cmdbuf[64]; gchar *cmdname; gint i; memset(cmdbuf, '\0', sizeof(cmdbuf)); strncpy(cmdbuf, key, sizeof(cmdbuf) - 1); for (i = 0; cmdbuf[i]; i++) { cmdbuf[i] = g_ascii_toupper(cmdbuf[i]); } cmdname = cmdbuf; if (strncmp(cmdname, "GEANY_", 6) == 0) { cmdname += 6; if (strncmp(cmdname, "KEYS_", 5) == 0) { cmdname += 5; } } he = lookup_key_cmd_str(cmdname) ; keybindings_send_command(he->group, he->key_id); } } Py_RETURN_NONE; }
/* Takes runs of hexadecimal digits, possibly with whitespace among them, and * formats them nicely in groups of four digits. */ gchar* seahorse_pgp_subkey_calc_fingerprint (const gchar *raw_fingerprint) { const gchar *raw; GString *string; guint i, len; guint num_digits; gchar *fpr; raw = raw_fingerprint; g_return_val_if_fail (raw != NULL, NULL); string = g_string_new (""); len = strlen (raw); num_digits = 0; for (i = 0; i < len; i++) { if (g_ascii_isxdigit (raw[i])) { g_string_append_c (string, g_ascii_toupper (raw[i])); num_digits++; if (num_digits > 0 && num_digits % 4 == 0) g_string_append (string, " "); } } fpr = string->str; g_string_free (string, FALSE); g_strchomp (fpr); return fpr; }
/*--------------------------------------------------------------------------*/ static gchar * code39_encode (const gchar *data, gboolean checksum_flag) { gchar *p, c; gint c_value, sum; GString *code; /* Left frame symbol */ code = g_string_new( frame_symbol ); code = g_string_append( code, "i" ); sum = 0; for ( p=(gchar *)data; *p != 0; p++ ) { c = g_ascii_toupper( *p ); c_value = strchr(alphabet, c) - alphabet; code = g_string_append (code, symbols[c_value]); code = g_string_append (code, "i"); sum += c_value; } if ( checksum_flag ) { code = g_string_append (code, symbols[sum % 43]); code = g_string_append (code, "i"); } /* Right frame bar */ code = g_string_append (code, frame_symbol); return g_string_free (code, FALSE); }
static void print_factory_details_info (GstElementFactory * factory) { gchar **keys, **k; GstRank rank; char s[20]; rank = gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory)); n_print ("Factory Details:\n"); n_print (" %-25s%s (%d)\n", "Rank", get_rank_name (s, rank), rank); keys = gst_element_factory_get_metadata_keys (factory); if (keys != NULL) { for (k = keys; *k != NULL; ++k) { const gchar *val; gchar *key = *k; val = gst_element_factory_get_metadata (factory, key); key[0] = g_ascii_toupper (key[0]); n_print (" %-25s%s\n", key, val); } g_strfreev (keys); } n_print ("\n"); }
void rbgobj_init_flags_class(VALUE klass) { GFlagsClass* gclass = g_type_class_ref(CLASS2GTYPE(klass)); GString* source = g_string_new(NULL); guint i; for (i = 0; i < gclass->n_values; i++) { GFlagsValue* entry = &(gclass->values[i]); gchar* nick; gchar* p; gchar* replace_nick; replace_nick = rg_obj_constant_lookup(entry->value_nick); if (replace_nick){ nick = g_strdup(replace_nick); } else { nick = g_strdup(entry->value_nick); } for (p = nick; *p; p++) if (*p == '-' || *p == ' ') *p = '_'; else *p = tolower(*p); g_string_append_printf( source, "def %s%s?; self >= self.class.new(%d); end\n", g_ascii_isdigit(nick[0]) ? "_" : "", nick, entry->value); for (p = nick; *p; p++) *p = g_ascii_toupper(*p); #if 0 { ID id = rb_intern(nick); if (rb_is_const_id(id)) { rb_define_const(klass, nick, make_flags(entry->value, klass)); } } #else { rbgobj_define_const(klass, nick, make_flags(entry->value, klass)); } #endif g_free(nick); } rb_funcall(klass, id_module_eval, 3, rb_str_new2(source->str), rb_str_new2(__FILE__), INT2NUM(__LINE__)); g_string_free(source, TRUE); g_type_class_unref(gclass); }
/* compares two encoding names in a permissive fashion. * e.g. "utf8" matches "UTF-8", "iso8859_1" matches "ISO-8859-1", etc. */ static gboolean encodings_charset_equals(const gchar *a, const gchar *b) { gboolean was_alpha = FALSE; /* whether last character of previous word was a letter */ gboolean need_sep = FALSE; /* whether we're expecting an implicit separator */ while (*a && *b) { gboolean is_alpha; if (g_ascii_toupper(*a) == g_ascii_toupper(*b) && ((is_alpha = g_ascii_isalpha(*a)) || g_ascii_isdigit(*a))) { /* either there was a real separator, or we need a implicit one (a chage from alpha to * numeric or so) */ if (! need_sep || (was_alpha != is_alpha)) { a++; b++; was_alpha = is_alpha; need_sep = FALSE; } else return FALSE; } else { guint n_sep = 0; if (! g_ascii_isalnum(*a)) { a++; n_sep++; } if (! g_ascii_isalnum(*b)) { b++; n_sep++; } if (n_sep < 1) return FALSE; else if (n_sep < 2) need_sep = TRUE; } } return *a == *b; }
gchar* utils_str_capitalise(const gchar* str) { g_assert_false(utils_str_empty(str)); gchar* ret = g_strdup_printf("%c%s", g_ascii_toupper(*str), str+1); return ret; }
/* Convert all ASCII letters to upper case, in place. */ gchar * ascii_strup_inplace(gchar *str) { gchar *s; for (s = str; *s; s++) *s = g_ascii_toupper (*s); return (str); }
GType ibus_m17n_engine_get_type_for_name (const gchar *engine_name) { GType type; gchar *type_name, *lang = NULL, *name = NULL; GTypeInfo type_info = { sizeof (IBusM17NEngineClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ibus_m17n_engine_class_init, (GClassFinalizeFunc)ibus_m17n_engine_class_finalize, NULL, sizeof (IBusM17NEngine), 0, (GInstanceInitFunc) ibus_m17n_engine_init, }; if (!ibus_m17n_scan_engine_name (engine_name, &lang, &name)) { g_free (lang); g_free (name); return G_TYPE_INVALID; } lang[0] = g_ascii_toupper (lang[0]); name[0] = g_ascii_toupper (name[0]); type_name = g_strdup_printf ("IBusM17N%s%sEngine", lang, name); g_free (lang); g_free (name); type = g_type_from_name (type_name); g_assert (type == 0 || g_type_is_a (type, IBUS_TYPE_ENGINE)); if (type == 0) { type = g_type_module_register_type (G_TYPE_MODULE (module), IBUS_TYPE_ENGINE, type_name, &type_info, (GTypeFlags) 0); } g_free (type_name); return type; }
static int str_ascii_toupper (const char *text, char **out, size_t * remain) { if (*remain <= 1) return 0; (*out)[0] = (char) g_ascii_toupper ((gchar) text[0]); (*out)++; (*remain)--; return 1; }
static void fix_header_name(GString *str) { guint i, len = str->len; gchar *s = str->str; for (i = 0; i < len; i++) { if (g_ascii_isalpha(s[i])) { s[i] = g_ascii_toupper(s[i]); } else if (!g_ascii_isdigit(s[i])) { s[i] = '_'; } } }
/** * hash function for case-insensitive strings */ guint g_istr_hash(gconstpointer v) { /* djb2 */ const unsigned char *p = v; unsigned char c; guint32 h = 5381; while ((c = *p++)) { h = ((h << 5) + h) + g_ascii_toupper(c); } return h; }
/** * pk_cnf_find_alternatives_case: * * Remove double chars, e.g. Lshal -> lshal **/ static void pk_cnf_find_alternatives_case (const gchar *cmd, guint len, GPtrArray *array) { guint i; gchar *possible; gchar temp; for (i = 0; i < len; i++) { temp = g_ascii_tolower (cmd[i]); if (temp != cmd[i]) { possible = g_strdup (cmd); possible[i] = temp; g_ptr_array_add (array, possible); } temp = g_ascii_toupper (cmd[i]); if (temp != cmd[i]) { possible = g_strdup (cmd); possible[i] = temp; g_ptr_array_add (array, possible); } } /* all lower */ possible = g_strdup (cmd); for (i = 0; i < len; i++) possible[i] = g_ascii_tolower (cmd[i]); if (strcmp (possible, cmd) != 0) g_ptr_array_add (array, possible); else g_free (possible); /* all upper */ possible = g_strdup (cmd); for (i = 0; i < len; i++) possible[i] = g_ascii_toupper (cmd[i]); if (strcmp (possible, cmd) != 0) g_ptr_array_add (array, possible); else g_free (possible); }
static gint compare_name (const gchar *id, const gchar *name) { const gchar *ptr; gboolean next = FALSE; gint miss = 0; for (ptr = name; *ptr != '\0'; ptr++) { if (!next && (*id != '\0') && (g_ascii_toupper (*ptr) == g_ascii_toupper (*id))) { id++; } else { miss++; next = !g_ascii_isspace (*ptr); } } return (*id == '\0') ? miss : -1; }
static void append_key_capabilities (GString *string, const gchar *caps) { guint i; gchar cap; for (i = 0; caps[i] != 0; i++) { cap = g_ascii_toupper (caps[i]); if (!strchr (string->str, cap)) g_string_append_c (string, cap); } }
/** * gst_pb_utils_get_element_description: * @factory_name: the name of the element, e.g. "gnomevfssrc" * * Returns a localised string describing the given element, for use in * error dialogs or other messages to be seen by the user. Should never * return NULL unless @factory_name is invalid. * * This function is mainly for internal use, applications would typically * use gst_missing_plugin_message_get_description() to get a description of * a missing feature from a missing-plugin message. * * Returns: a newly-allocated description string, or NULL on error. Free * string with g_free() when not needed any longer. */ gchar * gst_pb_utils_get_element_description (const gchar * factory_name) { gchar *ret; g_return_val_if_fail (factory_name != NULL, NULL); ret = g_strdup_printf (_("GStreamer element %s"), factory_name); if (ret && g_str_has_prefix (ret, factory_name)) *ret = g_ascii_toupper (*ret); return ret; }
static gboolean print_factory_details_meta_data (GQuark field_id, const GValue * value, gpointer user_data) { gchar *val = g_strdup_value_contents (value); gchar *key = g_strdup (g_quark_to_string (field_id)); key[0] = g_ascii_toupper (key[0]); n_print (" %s:\t\t%s\n", key, val); g_free (val); g_free (key); return TRUE; }