/** * seed_make_exception_from_gerror: * @ctx: A #SeedContext. * @exception: A reference to a #SeedException in which to store the exception. * @error: A #GError* from which to copy the properties of the exception. * * Generates @exception with the name and description of @error. * */ void seed_make_exception_from_gerror (JSContextRef ctx, JSValueRef * exception, GError * error) { const gchar *domain = g_quark_to_string (error->domain); GString *string = g_string_new (domain); guint i; gsize len = string->len; *(string->str) = g_unichar_toupper (*(string->str)); for (i = 0; i < len; i++) { if (*(string->str + i) == '-') { *(string->str + i + 1) = g_unichar_toupper (*(string->str + i + 1)); g_string_erase (string, i, 1); } else if (!g_strcmp0 (string->str + i - 1, "Quark")) g_string_truncate (string, i - 1); } seed_make_exception (ctx, exception, string->str, error->message, NULL); g_string_free (string, TRUE); }
static char *convert_title_case(const char *str) { int result_size = strlen(str) + 12; char *result = malloc(result_size); const char *r = str; char *w = result; gboolean upcase_next = TRUE; while (*r) { int len; gunichar c = g_utf8_get_char(r); /* ensure there is room for at least 1 more character */ if (w - result + 7 > result_size) { int offset = w - result; result_size += max(6, 0.5 * result_size); result = realloc(result, result_size); w = result + offset; } if (upcase_next) len = g_unichar_to_utf8(g_unichar_toupper(c), w); else len = g_unichar_to_utf8(g_unichar_tolower(c), w); w += len; upcase_next = !g_unichar_isalnum(c) && c != '\''; r = g_utf8_next_char(r); } *w = 0; return result; }
static char *convert_sentence_case(const char *str) { int result_size = strlen(str) + 12; char *result = malloc(result_size); const char *r = str; char *w = result; while (*r) { int len; gunichar c = g_utf8_get_char(r); /* ensure there is room for at least 1 more character */ if (w - result + 7 > result_size) { int offset = w - result; result_size += max(6, 0.5 * result_size); result = realloc(result, result_size); w = result + offset; } if (r == str) len = g_unichar_to_utf8(g_unichar_toupper(c), w); else len = g_unichar_to_utf8(g_unichar_tolower(c), w); w += len; r = g_utf8_next_char(r); } *w = 0; return result; }
/* 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 void do_invert_case (GtkTextBuffer *buffer, GtkTextIter *start, GtkTextIter *end) { GString *s = g_string_new (NULL); while (!gtk_text_iter_is_end (start) && !gtk_text_iter_equal (start, end)) { gunichar c, nc; c = gtk_text_iter_get_char (start); if (g_unichar_islower (c)) nc = g_unichar_toupper (c); else nc = g_unichar_tolower (c); g_string_append_unichar (s, nc); gtk_text_iter_forward_char (start); } gtk_text_buffer_delete_selection (buffer, TRUE, TRUE); gtk_text_buffer_insert_at_cursor (buffer, s->str, s->len); g_string_free (s, TRUE); }
gboolean gb_str_simple_match (const gchar *haystack, const gchar *needle_down) { if (ide_str_empty0 (haystack)) return FALSE; else if (ide_str_empty0 (needle_down)) return TRUE; for (; *needle_down; needle_down = g_utf8_next_char (needle_down)) { gunichar ch = g_utf8_get_char (needle_down); const gchar *tmp; tmp = strchr (haystack, ch); if (!tmp) tmp = strchr (haystack, g_unichar_toupper (ch)); if (!tmp) return FALSE; haystack = tmp; } return TRUE; }
static void quickfill_insert_recursive (QuickFill *qf, const char *text, int len, const char *next_char, QuickFillSort sort) { guint key; char *old_text; QuickFill *match_qf; gunichar key_char_uc; if (qf == NULL) return; if ((text == NULL) || (*next_char == '\0')) return; key_char_uc = g_utf8_get_char (next_char); key = g_unichar_toupper (key_char_uc); match_qf = g_hash_table_lookup (qf->matches, GUINT_TO_POINTER (key)); if (match_qf == NULL) { match_qf = gnc_quickfill_new (); g_hash_table_insert (qf->matches, GUINT_TO_POINTER (key), match_qf); } old_text = match_qf->text; switch (sort) { case QUICKFILL_ALPHA: if (old_text && (g_utf8_collate (text, old_text) >= 0)) break; /* fall through */ case QUICKFILL_LIFO: default: /* If there's no string there already, just put the new one in. */ if (old_text == NULL) { match_qf->text = g_strdup(text); match_qf->len = len; break; } /* Leave prefixes in place */ if ((len > match_qf->len) && (strncmp(text, old_text, strlen(old_text)) == 0)) break; g_free(old_text); match_qf->text = g_strdup(text); match_qf->len = len; break; } quickfill_insert_recursive (match_qf, text, len, g_utf8_next_char (next_char), sort); }
static gchar* tsrr_replace (const gchar *text, const gchar *pattern, const gchar *replacement, gboolean case_sensitive) { const gchar *p; const gchar *t; gunichar pc; gunichar tc; GString *result = g_string_sized_new (32); while (*text != '\0') { /* compare the pattern to this part of the text */ for (p = pattern, t = text; *p != '\0' && *t != '\0'; p = g_utf8_next_char (p), t = g_utf8_next_char (t)) { /* determine the next unichars */ pc = g_utf8_get_char (p); tc = g_utf8_get_char (t); /* check if the chars don't match */ if (pc != tc && (case_sensitive || g_unichar_toupper (pc) != g_unichar_toupper (tc))) break; } /* check if the pattern matches */ if (G_UNLIKELY (*p == '\0')) { /* append the replacement to the result... */ g_string_append (result, replacement); /* ...and skip to the text after the pattern */ text = t; } else { /* just append the text char */ g_string_append_unichar (result, g_utf8_get_char (text)); text = g_utf8_next_char (text); } } return g_string_free (result, FALSE); }
/* * g_unichar_totitle */ RESULT test_g_unichar_totitle () { if (g_unichar_toupper (0) != 0) return FAILED ("#0"); if (g_unichar_totitle ('a') != 'A') return FAILED ("#1"); if (g_unichar_totitle ('1') != '1') return FAILED ("#2"); if (g_unichar_totitle (0x1C4) != 0x1C5) return FAILED ("#3"); if (g_unichar_totitle (0x1F2) != 0x1F2) return FAILED ("#4"); if (g_unichar_totitle (0x1F3) != 0x1F2) return FAILED ("#5"); if (g_unichar_toupper (0xFFFF) != 0xFFFF) return FAILED ("#6"); return NULL; }
QuickFill * gnc_quickfill_get_char_match (QuickFill *qf, gunichar uc) { guint key = g_unichar_toupper (uc); if (NULL == qf) return NULL; DEBUG ("xaccGetQuickFill(): index = %u\n", key); return g_hash_table_lookup (qf->matches, GUINT_TO_POINTER (key)); }
unsigned int _pcre_ucp_othercase(const unsigned int c) { unsigned int oc = NOTACHAR; if ((oc = g_unichar_toupper(c)) != c) return oc; if ((oc = g_unichar_tolower(c)) != c) return oc; return c; }
/************************************************************************** Find the larger common prefix. prefixes - A list of prefixes. num_prefixes - The number of prefixes. buf - The buffer to set. buf_len - The maximal size of the buffer. Returns the length of the common prefix (in characters). **************************************************************************/ static size_t get_common_prefix(const char *const *prefixes, size_t num_prefixes, char *buf, size_t buf_len) { const char *p; char *q; size_t i; fc_strlcpy(buf, prefixes[0], buf_len); for (i = 1; i < num_prefixes; i++) { for (p = prefixes[i], q = buf; *p != '\0' && *q != '\0'; p = g_utf8_next_char(p), q = g_utf8_next_char(q)) { if (g_unichar_toupper(g_utf8_get_char(p)) != g_unichar_toupper(g_utf8_get_char(q))) { *q = '\0'; break; } } } return g_utf8_strlen(buf, -1); }
static gchar * utf8_case_conv (const gchar *str, gssize len, gboolean upper) { gunichar *ustr; glong i, ulen; gchar *utf8; ustr = g_utf8_to_ucs4_fast (str, (glong) len, &ulen); for (i = 0; i < ulen; i++) ustr[i] = upper ? g_unichar_toupper (ustr[i]) : g_unichar_tolower (ustr[i]); utf8 = g_ucs4_to_utf8 (ustr, ulen, NULL, NULL, NULL); g_free (ustr); return utf8; }
/* Case-insensitive utf-8 string-has-prefix */ static gboolean lbab_rubrica_starts_from(const gchar * str, const gchar * filter_hi) { if (!str) return FALSE; while (*str && *filter_hi && g_unichar_toupper(g_utf8_get_char(str)) == g_utf8_get_char(filter_hi)) { str = g_utf8_next_char(str); filter_hi = g_utf8_next_char(filter_hi); } return *filter_hi == '\0'; }
/* * g_unichar_toupper */ RESULT test_g_unichar_toupper () { if (g_unichar_toupper (0) != 0) return FAILED ("#0"); if (g_unichar_toupper ('a') != 'A') return FAILED ("#1"); if (g_unichar_toupper ('1') != '1') return FAILED ("#2"); if (g_unichar_toupper (0x1C4) != 0x1C4) return FAILED ("#3"); if (g_unichar_toupper (0x1F2) != 0x1F1) return FAILED ("#4"); if (g_unichar_toupper (0x1F3) != 0x1F1) return FAILED ("#5"); if (g_unichar_toupper (0xFFFF) != 0xFFFF) return FAILED ("#6"); if (g_unichar_toupper (0x10428) != 0x10400) return FAILED ("#7"); return NULL; }
static int str_utf8_toupper (const char *text, char **out, size_t * remain) { gunichar uni; size_t left; uni = g_utf8_get_char_validated (text, -1); if (uni == (gunichar) (-1) || uni == (gunichar) (-2)) return 0; uni = g_unichar_toupper (uni); left = g_unichar_to_utf8 (uni, NULL); if (left >= *remain) return 0; left = g_unichar_to_utf8 (uni, *out); (*out) += left; (*remain) -= left; return 1; }
static void uspell_dict_add_to_session (EnchantDict * me, const char *const word, size_t len) { uSpell *manager; wide_t buf[MAXCHARS]; utf8_t myWord[MAXCHARS]; int length, index; manager = reinterpret_cast<uSpell *>(me->user_data); manager->acceptWord((const utf8_t *)word); if (len >= MAXCHARS) return; // too long; can't reasonably convert // see if we want to acceptWord(uppercase(myWord)) if (!(manager->theFlags & uSpell::upperLower)) return; // non-case language length = utf8_wide(buf, (const utf8_t *)word, MAXCHARS); for (index = 0; index < length; index++) { if (g_unichar_isupper(buf[index])) return; // case-sensitive word buf[index] = g_unichar_toupper(buf[index]); } wide_utf8(myWord, MAXCHARS, buf, length); manager->acceptWord(myWord); } // uspell_dict_add_to_session
/** * gnm_app_create_opener_filter: * @openers: (element-type GOFileOpener): a list of file openers. * * Creates a #GtkFileFilter from the list of file types supported by the * openers in the list. * Returns: (transfer full): the newly allocated #GtkFileFilter. **/ void * gnm_app_create_opener_filter (GList *openers) { /* See below. */ static const char *const bad_suffixes[] = { "txt", "html", "htm", "xml", NULL }; GtkFileFilter *filter = gtk_file_filter_new (); gboolean for_history = (openers == NULL); if (openers == NULL) openers = go_get_file_openers (); for (; openers; openers = openers->next) { GOFileOpener *opener = openers->data; if (opener != NULL) { const GSList *mimes = go_file_opener_get_mimes (opener); const GSList *suffixes = go_file_opener_get_suffixes (opener); if (!for_history) while (mimes) { const char *mime = mimes->data; /* * See 438918. Too many things * like *.xml and *.txt get added * to be useful for the file history */ gtk_file_filter_add_mime_type (filter, mime); if (0) g_print ("%s: Adding mime %s\n", go_file_opener_get_description (opener), mime); mimes = mimes->next; } while (suffixes) { const char *suffix = suffixes->data; GString *pattern; int i; if (for_history) for (i = 0; bad_suffixes[i]; i++) if (strcmp (suffix, bad_suffixes[i]) == 0) goto bad_suffix; /* Create "*.[xX][lL][sS]" */ pattern = g_string_new ("*."); while (*suffix) { gunichar uc = g_utf8_get_char (suffix); suffix = g_utf8_next_char (suffix); if (g_unichar_islower (uc)) { g_string_append_c (pattern, '['); g_string_append_unichar (pattern, uc); uc = g_unichar_toupper (uc); g_string_append_unichar (pattern, uc); g_string_append_c (pattern, ']'); } else g_string_append_unichar (pattern, uc); } gtk_file_filter_add_pattern (filter, pattern->str); if (0) g_print ("%s: Adding %s\n", go_file_opener_get_description (opener), pattern->str); g_string_free (pattern, TRUE); bad_suffix: suffixes = suffixes->next; } } } return filter; }
static void gnc_quickfill_remove_recursive (QuickFill *qf, const gchar *text, gint depth, QuickFillSort sort) { QuickFill *match_qf; gchar *child_text; gint child_len; child_text = NULL; child_len = 0; if (depth < g_utf8_strlen (text, -1)) { /* process next letter */ gchar *key_char; gunichar key_char_uc; guint key; key_char = g_utf8_offset_to_pointer (text, depth); key_char_uc = g_utf8_get_char (key_char); key = g_unichar_toupper (key_char_uc); match_qf = g_hash_table_lookup (qf->matches, GUINT_TO_POINTER (key)); if (match_qf) { /* remove text from child qf */ gnc_quickfill_remove_recursive (match_qf, text, depth + 1, sort); if (match_qf->text == NULL) { /* text was the only word with a prefix up to match_qf */ g_hash_table_remove (qf->matches, GUINT_TO_POINTER (key)); gnc_quickfill_destroy (match_qf); } else { /* remember remaining best child string */ child_text = match_qf->text; child_len = match_qf->len; } } } if (qf->text == NULL) return; if (strcmp (text, qf->text) == 0) { /* the currently best text is about to be removed */ gchar *best_text = NULL; gint best_len = 0; if (child_text != NULL) { /* other children are pretty good as well */ best_text = child_text; best_len = child_len; } else { if (g_hash_table_size (qf->matches) != 0) { /* otherwise search for another good text */ struct _BestText bts; bts.text = NULL; bts.sort = sort; g_hash_table_foreach (qf->matches, (GHFunc) best_text_helper, &bts); best_text = bts.text; best_len = (best_text == NULL) ? 0 : g_utf8_strlen (best_text, -1); } } /* now replace or clear text */ CACHE_REMOVE(qf->text); if (best_text != NULL) { qf->text = CACHE_INSERT((gpointer) best_text); qf->len = best_len; } else { qf->text = NULL; qf->len = 0; } } }
static void quickfill_insert_recursive (QuickFill *qf, const char *text, int depth, QuickFillSort sort) { guint key; char *old_text; QuickFill *match_qf; int len; char *key_char; gunichar key_char_uc; if (qf == NULL) return; if ((text == NULL) || (g_utf8_strlen (text, -1) <= depth)) return; key_char = g_utf8_offset_to_pointer (text, depth); key_char_uc = g_utf8_get_char (key_char); key = g_unichar_toupper (key_char_uc); match_qf = g_hash_table_lookup (qf->matches, GUINT_TO_POINTER (key)); if (match_qf == NULL) { match_qf = gnc_quickfill_new (); g_hash_table_insert (qf->matches, GUINT_TO_POINTER (key), match_qf); } old_text = match_qf->text; switch (sort) { case QUICKFILL_ALPHA: if (old_text && (g_utf8_collate (text, old_text) >= 0)) break; /* fall through */ case QUICKFILL_LIFO: default: len = g_utf8_strlen (text, -1); /* If there's no string there already, just put the new one in. */ if (old_text == NULL) { match_qf->text = CACHE_INSERT((gpointer) text); match_qf->len = len; break; } /* Leave prefixes in place */ if ((len > match_qf->len) && (strncmp(text, old_text, strlen(old_text)) == 0)) break; CACHE_REMOVE(old_text); match_qf->text = CACHE_INSERT((gpointer) text); match_qf->len = len; break; } quickfill_insert_recursive (match_qf, text, ++depth, sort); }
/*! shape() processes the information encapsulated by GR_ShapingInfo si and stores results in GR_*RenderInfo* pri. If the contents of pri are NULL the function must create a new instance of GR_*RenderInfo of the appropriate type and store the pointer in pri; it also must store pointer to this graphics instance in pri->m_pGraphics. If ri indicates that the text is justified, appropriate processing needs to be done This function is tied closely together to a class derrived from GR_RenderInfo which may contain caches of various data that will speed subsequent calls to prepareToRenderChars() and renderChars() */ bool GR_Graphics::shape(GR_ShapingInfo & si, GR_RenderInfo *& pri) { if(!si.m_pItem || si.m_pItem->getType() == GRScriptType_Void || !si.m_pFont) return false; if(!pri) { pri = new GR_XPRenderInfo(si.m_pItem->getType()); UT_return_val_if_fail(pri, false); pri->m_pGraphics = this; } GR_XPRenderInfo * pRI = (GR_XPRenderInfo *)pri; const GR_Font *pFont = si.m_pFont; // make sure that the buffers are of sufficient size ... if(si.m_iLength > pRI->m_iBufferSize) //buffer too small, reallocate { delete[] pRI->m_pChars; delete[] pRI->m_pWidths; pRI->m_pChars = new UT_UCS4Char[si.m_iLength + 1]; UT_return_val_if_fail(pRI->m_pChars, false); pRI->m_pWidths = new UT_sint32[si.m_iLength + 1]; UT_return_val_if_fail(pRI->m_pWidths, false); pRI->m_iBufferSize = si.m_iLength + 1; } pRI->m_iLength = si.m_iLength; pRI->m_iTotalLength = si.m_iLength; pRI->m_eScriptType = si.m_pItem->getType(); pRI->m_pItem = si.m_pItem; UT_UCS4Char glyph, current; UT_UCS4Char * dst_ptr = pRI->m_pChars; bool previousWasSpace = si.m_previousWasSpace; for(UT_sint32 i = 0; i < si.m_iLength; ++i, ++si.m_Text) { UT_return_val_if_fail(si.m_Text.getStatus() == UTIter_OK, false); current = si.m_Text.getChar(); if (si.m_TextTransform == GR_ShapingInfo::LOWERCASE) current = g_unichar_tolower(current); else if (si.m_TextTransform == GR_ShapingInfo::UPPERCASE) current = g_unichar_toupper(current); else if (si.m_TextTransform == GR_ShapingInfo::CAPITALIZE) { if (previousWasSpace) { current = g_unichar_toupper(current); } } // else si.m_TextTransform == GR_ShapingInfo::NONE previousWasSpace = g_unichar_isspace(current); if(si.m_iVisDir == UT_BIDI_RTL) glyph = s_getMirrorChar(current); else glyph = current; if(pFont->doesGlyphExist(glyph)) *dst_ptr++ = glyph; else { UT_UCS4Char t = s_remapGlyph(glyph); if(pFont->doesGlyphExist(t)) { *dst_ptr++ = t; } else { *dst_ptr++ = s_cDefaultGlyph; } } } pRI->m_eState = GRSR_BufferClean; if(pRI->isJustified()) justify(*pRI); // make sure that we invalidate the static buffers if we own them if(pRI->s_pOwner == pRI) pRI->s_pOwner = NULL; return true; }
gchar *strproper (gchar *s) { #if DISABLE_UTF8 gchar c; gchar *ptr; if (!s) return NULL; ptr = g_strdup(s); if (!ptr) return NULL; s = ptr; *s = toupper(*s); s++; while ((c = tolower(*s)) != '\0') *s++ = c; return ptr; #else gchar *ptr, *s1, *ptr1; gint len, first; gunichar c; if (!s) return NULL; len = 0; ptr = s; first = 1; while (*ptr) { c = g_utf8_get_char(ptr); if (first) { c = g_unichar_toupper(c); first = 0; } else c = g_unichar_tolower(c); len += g_unichar_to_utf8(c, NULL); ptr = g_utf8_next_char(ptr); } s1 = g_malloc(len + 1); if (!s1) return NULL; ptr = s; ptr1 = s1; first = 1; while (*ptr) { c = g_utf8_get_char(ptr); if (first) { c = g_unichar_toupper(c); first = 0; } else c = g_unichar_tolower(c); len = g_unichar_to_utf8(c, ptr1); ptr1 += len; ptr = g_utf8_next_char(ptr); } *ptr1 = '\0'; return s1; #endif }
/************************************************************************** Refresh info label **************************************************************************/ void update_info_label(void) { GtkWidget *label; const struct player *pplayer = client.conn.playing; label = gtk_frame_get_label_widget(GTK_FRAME(main_frame_civ_name)); if (pplayer != NULL) { const gchar *name; gunichar c; /* Capitalize the first character of the translated nation * plural name so that the frame label looks good. */ name = nation_plural_for_player(pplayer); c = g_utf8_get_char_validated(name, -1); if ((gunichar) -1 != c && (gunichar) -2 != c) { gchar nation[MAX_LEN_NAME]; gchar *next; gint len; len = g_unichar_to_utf8(g_unichar_toupper(c), nation); nation[len] = '\0'; next = g_utf8_find_next_char(name, NULL); if (NULL != next) { sz_strlcat(nation, next); } gtk_label_set_text(GTK_LABEL(label), nation); } else { gtk_label_set_text(GTK_LABEL(label), name); } } else { gtk_label_set_text(GTK_LABEL(label), "-"); } gtk_label_set_text(GTK_LABEL(main_label_info), get_info_label_text(!gui_gtk3_small_display_layout)); set_indicator_icons(client_research_sprite(), client_warming_sprite(), client_cooling_sprite(), client_government_sprite()); if (NULL != client.conn.playing) { int d = 0; for (; d < client.conn.playing->economic.luxury /10; d++) { struct sprite *sprite = get_tax_sprite(tileset, O_LUXURY); gtk_pixcomm_set_from_sprite(GTK_PIXCOMM(econ_label[d]), sprite); } for (; d < (client.conn.playing->economic.science + client.conn.playing->economic.luxury) / 10; d++) { struct sprite *sprite = get_tax_sprite(tileset, O_SCIENCE); gtk_pixcomm_set_from_sprite(GTK_PIXCOMM(econ_label[d]), sprite); } for (; d < 10; d++) { struct sprite *sprite = get_tax_sprite(tileset, O_GOLD); gtk_pixcomm_set_from_sprite(GTK_PIXCOMM(econ_label[d]), sprite); } } update_timeout_label(); /* update tooltips. */ gtk_widget_set_tooltip_text(econ_ebox, _("Shows your current luxury/science/tax rates; " "click to toggle them.")); gtk_widget_set_tooltip_text(bulb_ebox, get_bulb_tooltip()); gtk_widget_set_tooltip_text(sun_ebox, get_global_warming_tooltip()); gtk_widget_set_tooltip_text(flake_ebox, get_nuclear_winter_tooltip()); gtk_widget_set_tooltip_text(government_ebox, get_government_tooltip()); }
static unichar i_toupper(unichar c) { if (term_type == TERM_TYPE_UTF8) return g_unichar_toupper(c); return (c >= 0 && c <= 255) ? toupper(c) : c; }
static gchar* vala_ccode_file_get_define_for_filename (const gchar* filename) { gchar* result = NULL; GString* _tmp0_; GString* define; const gchar* _tmp1_; gchar* _tmp2_; gchar* i; GString* _tmp20_; GString* _tmp21_; const gchar* _tmp22_; gchar* _tmp23_; g_return_val_if_fail (filename != NULL, NULL); _tmp0_ = g_string_new ("__"); define = _tmp0_; _tmp1_ = filename; _tmp2_ = g_strdup (_tmp1_); i = _tmp2_; while (TRUE) { const gchar* _tmp3_; gint _tmp4_; gint _tmp5_; const gchar* _tmp6_; gunichar _tmp7_ = 0U; gunichar c; gboolean _tmp8_ = FALSE; gunichar _tmp9_; gboolean _tmp10_ = FALSE; gboolean _tmp12_; const gchar* _tmp17_; const gchar* _tmp18_ = NULL; gchar* _tmp19_; _tmp3_ = i; _tmp4_ = strlen (_tmp3_); _tmp5_ = _tmp4_; if (!(_tmp5_ > 0)) { break; } _tmp6_ = i; _tmp7_ = string_get_char (_tmp6_, (glong) 0); c = _tmp7_; _tmp9_ = c; _tmp10_ = g_unichar_isalnum (_tmp9_); if (_tmp10_) { gunichar _tmp11_; _tmp11_ = c; _tmp8_ = _tmp11_ < ((gunichar) 0x80); } else { _tmp8_ = FALSE; } _tmp12_ = _tmp8_; if (_tmp12_) { GString* _tmp13_; gunichar _tmp14_; gunichar _tmp15_ = 0U; _tmp13_ = define; _tmp14_ = c; _tmp15_ = g_unichar_toupper (_tmp14_); g_string_append_unichar (_tmp13_, _tmp15_); } else { GString* _tmp16_; _tmp16_ = define; g_string_append_c (_tmp16_, '_'); } _tmp17_ = i; _tmp18_ = g_utf8_next_char (_tmp17_); _tmp19_ = g_strdup (_tmp18_); _g_free0 (i); i = _tmp19_; } _tmp20_ = define; g_string_append (_tmp20_, "__"); _tmp21_ = define; _tmp22_ = _tmp21_->str; _tmp23_ = g_strdup (_tmp22_); result = _tmp23_; _g_free0 (i); _g_string_free0 (define); return result; }
gint donna_strcmp (const gchar *s1, const gchar *s2, DonnaSortOptions options) { gboolean is_string = TRUE; gint res_fb = 0; /* fallback */ gint res_cs = 0; /* case-sensitive */ gint res = 0; /* if at least one string if NULL or empty, we have a result */ if (!s1 || *s1 == '\0') { if (s2 && *s2 != '\0') return -1; else return 0; } else if (!s2 || *s2 == '\0') return 1; if (options & DONNA_SORT_DOT_FIRST) { if (*s1 == '.') { if (*s2 != '.') /* only s1 is dotted, it comes first */ return -1; else { /* both are dotted, skip the dot */ ++s1; ++s2; } } else if (*s2 == '.') /* only s2 is dotted, it comes first */ return 1; } else if (options & DONNA_SORT_DOT_MIXED) { if (*s1 == '.') ++s1; if (*s2 == '.') ++s2; } for (;;) { gunichar c1, c2; /* is at least one string over? */ if (!*s1) { if (!*s2) res = 0; else /* shorter first */ res = -1; goto done; } else if (!*s2) { /* shorter first */ res = 1; goto done; } c1 = g_utf8_get_char (s1); c2 = g_utf8_get_char (s2); if (is_string) { if (options & DONNA_SORT_IGNORE_SPUNCT) { while (g_unichar_isspace (c1) || g_unichar_ispunct (c1)) { s1 = g_utf8_next_char (s1); c1 = (*s1) ? g_utf8_get_char (s1) : 0; } while (g_unichar_isspace (c2) || g_unichar_ispunct (c2)) { s2 = g_utf8_next_char (s2); c2 = (*s2) ? g_utf8_get_char (s2) : 0; } /* did we reached the end of a string? */ if (!*s1 || !*s2) continue; } /* is at least one string a number? */ if (g_unichar_isdigit (c1)) { if (g_unichar_isdigit (c2)) { if (options & DONNA_SORT_NATURAL_ORDER) { /* switch to number comparison */ is_string = FALSE; continue; } } else { /* number first */ res = -1; goto done; } } else if (g_unichar_isdigit (c2)) { /* number first */ res = 1; goto done; } /* compare chars */ if (c1 > c2) res_cs = 1; else if (c1 < c2) res_cs = -1; if (options & DONNA_SORT_CASE_INSENSITIVE) { /* compare uppper chars */ c1 = g_unichar_toupper (c1); c2 = g_unichar_toupper (c2); if (c1 > c2) { res = 1; goto done; } else if (c1 < c2) { res = -1; goto done; } else if (res_fb == 0) /* set the case-sensitive result in case strings end up * being the same otherwise */ res_fb = res_cs; } /* do we have a res_cs yet? */ else if (res_cs != 0) { res = res_cs; goto done; } /* next chars */ s1 = g_utf8_next_char (s1); s2 = g_utf8_next_char (s2); } /* mode number */ else { unsigned long n1, n2; if (res_fb == 0) { /* count number of leading zeros */ for (n1 = 0; *s1 == '0'; ++n1, ++s1) ; for (n2 = 0; *s2 == '0'; ++n2, ++s2) ; /* try to set a fallback to put less leading zeros first */ if (n1 > n2) res_fb = 1; else if (n1 < n2) res_fb = -1; if (n1 > 0) c1 = g_utf8_get_char (s1); if (n2 > 0) c2 = g_utf8_get_char (s2); } n1 = 0; while (g_unichar_isdigit (c1)) { int d; d = g_unichar_digit_value (c1); n1 *= 10; n1 += (unsigned long) d; s1 = g_utf8_next_char (s1); if (*s1) c1 = g_utf8_get_char (s1); else break; } n2 = 0; while (g_unichar_isdigit (c2)) { int d; d = g_unichar_digit_value (c2); n2 *= 10; n2 += (unsigned long) d; s2 = g_utf8_next_char (s2); if (*s2) c2 = g_utf8_get_char (s2); else break; } if (n1 > n2) { res = 1; goto done; } else if (n1 < n2) { res = -1; goto done; } /* back to string comparison */ is_string = TRUE; } } done: return (res != 0) ? res : res_fb; }
static gint key_press(guint keyval, gchar *commit_str, gchar *preedit_str) { gint length_passed, i; gunichar c; gchar list_of_letters[255]; gchar *str; if(!gcomprisBoard) return FALSE; /* i suppose even numbers are passed through IM_context */ if ((commit_str == NULL) && (preedit_str == NULL)) return FALSE; gchar *string_passed; if (commit_str) string_passed = commit_str; else string_passed = preedit_str; str = g_strdup(string_passed); length_passed = g_utf8_strlen(string_passed, -1); for (i=0; i < length_passed; i++){ c = g_utf8_get_char (string_passed); if (is_falling_letter(c)){ gc_im_reset(); return TRUE; } /* if uppercase_only is set we do not care about upper or lower case at all */ gint level_uppercase; if (uppercase_only) level_uppercase = 10; else level_uppercase = 3; /* for 2 (or all) first level don't care abour uppercase/lowercase */ if ((gcomprisBoard->level < level_uppercase) && (is_falling_letter(g_unichar_toupper(c)))){ gc_im_reset(); return TRUE; } string_passed = g_utf8_next_char (string_passed); } list_of_letters[0] = '\0'; /* We have to loop to concat the letters */ g_hash_table_foreach (letters_table, (GHFunc) add_char, list_of_letters); /* Log what happened, what was expected, what we got */ gc_log_set_comment(gcomprisBoard, list_of_letters, str); g_free(str); return TRUE; }
/** * gdk_keyval_convert_case: * @symbol: a keyval * @lower: (out): return location for lowercase version of @symbol * @upper: (out): return location for uppercase version of @symbol * * Obtains the upper- and lower-case versions of the keyval @symbol. * Examples of keyvals are #GDK_KEY_a, #GDK_KEY_Enter, #GDK_KEY_F1, etc. */ void gdk_keyval_convert_case (guint symbol, guint *lower, guint *upper) { guint xlower, xupper; xlower = symbol; xupper = symbol; /* Check for directly encoded 24-bit UCS characters: */ if ((symbol & 0xff000000) == 0x01000000) { if (lower) *lower = gdk_unicode_to_keyval (g_unichar_tolower (symbol & 0x00ffffff)); if (upper) *upper = gdk_unicode_to_keyval (g_unichar_toupper (symbol & 0x00ffffff)); return; } switch (symbol >> 8) { case 0: /* Latin 1 */ if ((symbol >= GDK_KEY_A) && (symbol <= GDK_KEY_Z)) xlower += (GDK_KEY_a - GDK_KEY_A); else if ((symbol >= GDK_KEY_a) && (symbol <= GDK_KEY_z)) xupper -= (GDK_KEY_a - GDK_KEY_A); else if ((symbol >= GDK_KEY_Agrave) && (symbol <= GDK_KEY_Odiaeresis)) xlower += (GDK_KEY_agrave - GDK_KEY_Agrave); else if ((symbol >= GDK_KEY_agrave) && (symbol <= GDK_KEY_odiaeresis)) xupper -= (GDK_KEY_agrave - GDK_KEY_Agrave); else if ((symbol >= GDK_KEY_Ooblique) && (symbol <= GDK_KEY_Thorn)) xlower += (GDK_KEY_oslash - GDK_KEY_Ooblique); else if ((symbol >= GDK_KEY_oslash) && (symbol <= GDK_KEY_thorn)) xupper -= (GDK_KEY_oslash - GDK_KEY_Ooblique); break; case 1: /* Latin 2 */ /* Assume the KeySym is a legal value (ignore discontinuities) */ if (symbol == GDK_KEY_Aogonek) xlower = GDK_KEY_aogonek; else if (symbol >= GDK_KEY_Lstroke && symbol <= GDK_KEY_Sacute) xlower += (GDK_KEY_lstroke - GDK_KEY_Lstroke); else if (symbol >= GDK_KEY_Scaron && symbol <= GDK_KEY_Zacute) xlower += (GDK_KEY_scaron - GDK_KEY_Scaron); else if (symbol >= GDK_KEY_Zcaron && symbol <= GDK_KEY_Zabovedot) xlower += (GDK_KEY_zcaron - GDK_KEY_Zcaron); else if (symbol == GDK_KEY_aogonek) xupper = GDK_KEY_Aogonek; else if (symbol >= GDK_KEY_lstroke && symbol <= GDK_KEY_sacute) xupper -= (GDK_KEY_lstroke - GDK_KEY_Lstroke); else if (symbol >= GDK_KEY_scaron && symbol <= GDK_KEY_zacute) xupper -= (GDK_KEY_scaron - GDK_KEY_Scaron); else if (symbol >= GDK_KEY_zcaron && symbol <= GDK_KEY_zabovedot) xupper -= (GDK_KEY_zcaron - GDK_KEY_Zcaron); else if (symbol >= GDK_KEY_Racute && symbol <= GDK_KEY_Tcedilla) xlower += (GDK_KEY_racute - GDK_KEY_Racute); else if (symbol >= GDK_KEY_racute && symbol <= GDK_KEY_tcedilla) xupper -= (GDK_KEY_racute - GDK_KEY_Racute); break; case 2: /* Latin 3 */ /* Assume the KeySym is a legal value (ignore discontinuities) */ if (symbol >= GDK_KEY_Hstroke && symbol <= GDK_KEY_Hcircumflex) xlower += (GDK_KEY_hstroke - GDK_KEY_Hstroke); else if (symbol >= GDK_KEY_Gbreve && symbol <= GDK_KEY_Jcircumflex) xlower += (GDK_KEY_gbreve - GDK_KEY_Gbreve); else if (symbol >= GDK_KEY_hstroke && symbol <= GDK_KEY_hcircumflex) xupper -= (GDK_KEY_hstroke - GDK_KEY_Hstroke); else if (symbol >= GDK_KEY_gbreve && symbol <= GDK_KEY_jcircumflex) xupper -= (GDK_KEY_gbreve - GDK_KEY_Gbreve); else if (symbol >= GDK_KEY_Cabovedot && symbol <= GDK_KEY_Scircumflex) xlower += (GDK_KEY_cabovedot - GDK_KEY_Cabovedot); else if (symbol >= GDK_KEY_cabovedot && symbol <= GDK_KEY_scircumflex) xupper -= (GDK_KEY_cabovedot - GDK_KEY_Cabovedot); break; case 3: /* Latin 4 */ /* Assume the KeySym is a legal value (ignore discontinuities) */ if (symbol >= GDK_KEY_Rcedilla && symbol <= GDK_KEY_Tslash) xlower += (GDK_KEY_rcedilla - GDK_KEY_Rcedilla); else if (symbol >= GDK_KEY_rcedilla && symbol <= GDK_KEY_tslash) xupper -= (GDK_KEY_rcedilla - GDK_KEY_Rcedilla); else if (symbol == GDK_KEY_ENG) xlower = GDK_KEY_eng; else if (symbol == GDK_KEY_eng) xupper = GDK_KEY_ENG; else if (symbol >= GDK_KEY_Amacron && symbol <= GDK_KEY_Umacron) xlower += (GDK_KEY_amacron - GDK_KEY_Amacron); else if (symbol >= GDK_KEY_amacron && symbol <= GDK_KEY_umacron) xupper -= (GDK_KEY_amacron - GDK_KEY_Amacron); break; case 6: /* Cyrillic */ /* Assume the KeySym is a legal value (ignore discontinuities) */ if (symbol >= GDK_KEY_Serbian_DJE && symbol <= GDK_KEY_Serbian_DZE) xlower -= (GDK_KEY_Serbian_DJE - GDK_KEY_Serbian_dje); else if (symbol >= GDK_KEY_Serbian_dje && symbol <= GDK_KEY_Serbian_dze) xupper += (GDK_KEY_Serbian_DJE - GDK_KEY_Serbian_dje); else if (symbol >= GDK_KEY_Cyrillic_YU && symbol <= GDK_KEY_Cyrillic_HARDSIGN) xlower -= (GDK_KEY_Cyrillic_YU - GDK_KEY_Cyrillic_yu); else if (symbol >= GDK_KEY_Cyrillic_yu && symbol <= GDK_KEY_Cyrillic_hardsign) xupper += (GDK_KEY_Cyrillic_YU - GDK_KEY_Cyrillic_yu); break; case 7: /* Greek */ /* Assume the KeySym is a legal value (ignore discontinuities) */ if (symbol >= GDK_KEY_Greek_ALPHAaccent && symbol <= GDK_KEY_Greek_OMEGAaccent) xlower += (GDK_KEY_Greek_alphaaccent - GDK_KEY_Greek_ALPHAaccent); else if (symbol >= GDK_KEY_Greek_alphaaccent && symbol <= GDK_KEY_Greek_omegaaccent && symbol != GDK_KEY_Greek_iotaaccentdieresis && symbol != GDK_KEY_Greek_upsilonaccentdieresis) xupper -= (GDK_KEY_Greek_alphaaccent - GDK_KEY_Greek_ALPHAaccent); else if (symbol >= GDK_KEY_Greek_ALPHA && symbol <= GDK_KEY_Greek_OMEGA) xlower += (GDK_KEY_Greek_alpha - GDK_KEY_Greek_ALPHA); else if (symbol >= GDK_KEY_Greek_alpha && symbol <= GDK_KEY_Greek_omega && symbol != GDK_KEY_Greek_finalsmallsigma) xupper -= (GDK_KEY_Greek_alpha - GDK_KEY_Greek_ALPHA); break; default: break; } if (lower) *lower = xlower; if (upper) *upper = xupper; }
/** * Create one of our custom GClosure subclasses. To save us having to export * it, however, we just return the GClosure* that it extends. */ GClosure* bindings_java_closure_new ( JNIEnv* env, jobject handler, jclass receiver, const gchar* name, guint id ) { GClosure* closure; BindingsJavaClosure* bjc; GSignalQuery info; GString* buf; guint i; gchar* methodName; gchar* methodSignature; /* * First we allocate the closure and do the footwork to tell it what * its marshaller is */ closure = g_closure_new_simple(sizeof(BindingsJavaClosure), NULL); g_closure_add_finalize_notifier(closure, NULL, bindings_java_closure_destroy); g_closure_set_marshal(closure, bindings_java_marshaller); bjc = (BindingsJavaClosure*) closure; /* * And now we begin the legwork of figuring out what the methodID of * the callback to be invoked is and caching that in the closure. We * get the GSignalQuery data for the specified signal and then use that * to formulate a string that can be use to lookup the method. */ g_signal_query(id, &info); switch(G_TYPE_FUNDAMENTAL(info.return_type)) { case G_TYPE_BOOLEAN: bjc->returnType = 'Z'; break; case G_TYPE_INT: bjc->returnType = 'I'; break; case G_TYPE_ENUM: bjc->returnType = 'E'; break; case G_TYPE_STRING: /* * Strings are encoded as java.lang.String objects in signatures, * so we use the object type marker for gchar* (only). */ bjc->returnType = 'L'; break; case G_TYPE_NONE: bjc->returnType = 'V'; break; default: g_critical("Don't know what to do with signal return type %s", g_type_name(info.return_type)); return NULL; } /* * the name of the methods we invoke is algorithmic: "receiveName", * where Name is a PascalCase version of the signal name we were * passed in. */ buf = g_string_new("receive"); gchar** tokens = g_strsplit_set(name, "_-:", -1); for (i = 0; i < g_strv_length(tokens); i++) { gchar* token = tokens[i]; if (token[0] == '\0') { // skip past :: which splits signal name from "detail" continue; } gchar first = g_unichar_toupper(token[0]); g_string_append_c(buf, first); token++; g_string_append(buf, token); } methodName = buf->str; g_string_free(buf, FALSE); g_strfreev(tokens); /* * And here is the tricky bit: formulate the method signature that goes * along with this signal. A method of the signature * * boolean method(int, long, String) * * has a JNI encoding of * * (IJLjava/util/String;)Z */ buf = g_string_new("(Lorg/gnome/glib/Signal;J"); // add the signature for each parameter type for(i = 0; i < info.n_params; i++) { g_string_append(buf, bindings_java_typeToSignature(info.param_types[i])); } // and the return type g_string_append(buf, ")"); g_string_append(buf, bindings_java_typeToSignature(info.return_type)); methodSignature = buf->str; g_string_free(buf, FALSE); /* * Now at last we can lookup the method ID */ // jclass CANDIDATE = (*env)->FindClass(env, "org/gnome/gtk/GtkWidget"); // if ((*env)->IsSameObject(env, CANDIDATE, receiver)) { // g_debug("Received a GtkWidget"); // } bjc->receiver = receiver; bjc->method = (*env)->GetStaticMethodID(env, bjc->receiver, methodName, methodSignature); // g_debug("Looking for\nJava method %s\nwith signature %s\nin class %s\nto handle signal %s\n", // methodName, methodSignature, "FIXME", g_signal_name(id)); // clean up g_free(methodName); g_free(methodSignature); // and check for error if (bjc->method == NULL) { // Exception already thrown by GetMethodID return NULL; } /* * Set the reference so that the marshaller can find the Signal instance. */ bjc->handler = (*env)->NewWeakGlobalRef(env, handler); /* * And we're done! */ return closure; }
// convert a Mod+key arg to mod mask and keysym gboolean x11_parse_key ( char *combo, unsigned int *mod, xkb_keysym_t *key ) { GString *str = g_string_new ( "" ); unsigned int modmask = 0; if ( strcasestr ( combo, "shift" ) ) { modmask |= x11_mod_masks[X11MOD_SHIFT]; if ( x11_mod_masks[X11MOD_SHIFT] == 0 ) { g_string_append_printf ( str, "X11 configured keyboard has no <b>Shift</b> key.\n" ); } } if ( strcasestr ( combo, "control" ) ) { modmask |= x11_mod_masks[X11MOD_CONTROL]; if ( x11_mod_masks[X11MOD_CONTROL] == 0 ) { g_string_append_printf ( str, "X11 configured keyboard has no <b>Control</b> key.\n" ); } } if ( strcasestr ( combo, "alt" ) ) { modmask |= x11_mod_masks[X11MOD_ALT]; if ( x11_mod_masks[X11MOD_ALT] == 0 ) { g_string_append_printf ( str, "X11 configured keyboard has no <b>Alt</b> key.\n" ); } } if ( strcasestr ( combo, "super" ) ) { modmask |= x11_mod_masks[X11MOD_SUPER]; if ( x11_mod_masks[X11MOD_SUPER] == 0 ) { g_string_append_printf ( str, "X11 configured keyboard has no <b>Super</b> key.\n" ); } } if ( strcasestr ( combo, "meta" ) ) { modmask |= x11_mod_masks[X11MOD_META]; if ( x11_mod_masks[X11MOD_META] == 0 ) { g_string_append_printf ( str, "X11 configured keyboard has no <b>Meta</b> key.\n" ); } } if ( strcasestr ( combo, "hyper" ) ) { modmask |= x11_mod_masks[X11MOD_HYPER]; if ( x11_mod_masks[X11MOD_HYPER] == 0 ) { g_string_append_printf ( str, "X11 configured keyboard has no <b>Hyper</b> key.\n" ); } } int seen_mod = FALSE; if ( strcasestr ( combo, "Mod" ) ) { seen_mod = TRUE; } *mod = modmask; // Skip modifier (if exist) and parse key. char i = strlen ( combo ); while ( i > 0 && !strchr ( "-+", combo[i - 1] ) ) { i--; } xkb_keysym_t sym = XKB_KEY_NoSymbol; if ( ( modmask & x11_mod_masks[X11MOD_SHIFT] ) != 0 ) { gchar * str = g_utf8_next_char ( combo + i ); // If it is a single char, we make a capital out of it. if ( str != NULL && *str == '\0' ) { int l = 0; char buff[8]; gunichar v = g_utf8_get_char ( combo + i ); gunichar u = g_unichar_toupper ( v ); if ( ( l = g_unichar_to_utf8 ( u, buff ) ) ) { buff[l] = '\0'; sym = xkb_keysym_from_name ( buff, XKB_KEYSYM_NO_FLAGS ); } } } if ( sym == XKB_KEY_NoSymbol ) { sym = xkb_keysym_from_name ( combo + i, XKB_KEYSYM_CASE_INSENSITIVE ); } if ( sym == XKB_KEY_NoSymbol || ( !modmask && ( strchr ( combo, '-' ) || strchr ( combo, '+' ) ) ) ) { g_string_append_printf ( str, "Sorry, rofi cannot understand the key combination: <i>%s</i>\n", combo ); g_string_append ( str, "\nRofi supports the following modifiers:\n\t" ); g_string_append ( str, "<i>Shift,Control,Alt,Super,Meta,Hyper</i>" ); if ( seen_mod ) { g_string_append ( str, "\n\n<b>Mod1,Mod2,Mod3,Mod4,Mod5 are no longer supported, use one of the above.</b>" ); } } if ( str->len > 0 ) { rofi_view_error_dialog ( str->str, TRUE ); g_string_free ( str, TRUE ); return FALSE; } g_string_free ( str, TRUE ); *key = sym; return TRUE; }