Exemplo n.º 1
0
static void
do_title_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 (gtk_text_iter_starts_word (start))
			nc = g_unichar_totitle (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);
}
Exemplo n.º 2
0
/*
 *  call-seq:
 *    utf8_titleize(string)
 *
 *  Returns a title case string.
 *
 *    Glib.utf8_titleize('привет всем') #=> Привет Всем
 */
static VALUE utf8_titleize(VALUE self, VALUE string)
{
  VALUE result;
  gchar *temp;
  long index, length_in_bytes, length_in_chars;
  gunichar *chars_as_ucs4, current_char;
  gboolean first_character_of_word = TRUE;

  Check_Type(string, T_STRING);

  length_in_bytes = RSTRING_LEN(string);
  if ((chars_as_ucs4 = g_utf8_to_ucs4(StringValuePtr(string), length_in_bytes, NULL, &length_in_chars, NULL))) {
    for (index = 0; index < length_in_chars; index++) {
      current_char = chars_as_ucs4[index];
      if (first_character_of_word == TRUE && g_unichar_isalpha(current_char)) {
        chars_as_ucs4[index] = g_unichar_totitle(current_char);
        first_character_of_word = FALSE;
      }

      if (g_unichar_isspace(current_char) || g_unichar_ispunct(current_char)) {
        first_character_of_word = TRUE;
      }
    }
    
    temp = g_ucs4_to_utf8(chars_as_ucs4, -1, NULL, NULL, NULL);
    result = rb_str_new2(temp);
    g_free(chars_as_ucs4);
    g_free(temp);
    
    return result;
  } else {
    return Qnil;
  }
}
Exemplo n.º 3
0
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;
}
Exemplo n.º 4
0
static int enchant_is_title_case(const char*const word, size_t len)
{
	gunichar ch;
	GUnicodeType type;
	const char* it = word;

	g_return_val_if_fail (word && *word, 0);

	ch = g_utf8_get_char(it);
	
	type = g_unichar_type(ch);
	if(type != G_UNICODE_UPPERCASE_LETTER && type != G_UNICODE_TITLECASE_LETTER)
		return 0;

	if(ch != g_unichar_totitle(ch) )
		return 0;
			
	for(it = g_utf8_next_char(it); it < word + len; it = g_utf8_next_char(it))
		{
			type = g_unichar_type(g_utf8_get_char(it));
			if(type == G_UNICODE_UPPERCASE_LETTER || type == G_UNICODE_TITLECASE_LETTER)
				return 0;
		}
	return 1;
}
Exemplo n.º 5
0
/*
 * 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;
}
Exemplo n.º 6
0
static char *
capitalize_utf8_string (const char *str)
{
        char first[8] = { 0 };

        if (!str)
                return NULL;

        g_unichar_to_utf8 (g_unichar_totitle (g_utf8_get_char (str)), first);

        return g_strconcat (first, g_utf8_offset_to_pointer (str, 1), NULL);
}