Esempio n. 1
0
static gchar *
_lm_parser_make_valid (const gchar *buffer, gchar **incomplete)
{
    GString *string;
    const gchar *remainder, *invalid;
    gint remaining_bytes, valid_bytes;
    gunichar code; /*error code for invalid character*/

    g_return_val_if_fail (buffer != NULL, NULL);

    string = NULL;
    remainder = buffer;
    remaining_bytes = strlen (buffer);

    while (remaining_bytes != 0)
    {
        if (g_utf8_validate (remainder, remaining_bytes, &invalid))
            break;
        valid_bytes = invalid - remainder;

        if (string == NULL)
            string = g_string_sized_new (remaining_bytes);

        g_string_append_len (string, remainder, valid_bytes);

        remainder = g_utf8_find_next_char(invalid, NULL);
        remaining_bytes -= valid_bytes + (remainder - invalid);

        code = g_utf8_get_char_validated (invalid, -1);

        if (code == -1) {
            /* A complete but invalid codepoint */
            /* append U+FFFD REPLACEMENT CHARACTER */
            g_string_append (string, "\357\277\275");
            g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_VERBOSE, "invalid character!\n");
        } else if (code == -2) {
            /* Beginning of what could be a character */
            *incomplete = g_strdup (invalid);
            g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_VERBOSE,
                           "incomplete character: %s\n", *incomplete);

            g_assert (remaining_bytes == 0);
            g_assert (*(g_utf8_find_next_char(invalid, NULL)) == '\0');
        }
    }

    if (string == NULL)
        return g_strdup (buffer);

    g_string_append (string, remainder);

    g_assert (g_utf8_validate (string->str, -1, NULL));

    return g_string_free (string, FALSE);
}
Esempio n. 2
0
static gboolean
move_forward(GntBindable *bind, GList *list)
{
	GntEntry *entry = GNT_ENTRY(bind);
	if (entry->cursor >= entry->end)
		return FALSE;
	entry->cursor = g_utf8_find_next_char(entry->cursor, NULL);
	while (gnt_util_onscreen_width(entry->scroll, entry->cursor) >= GNT_WIDGET(entry)->priv.width)
		entry->scroll = g_utf8_find_next_char(entry->scroll, NULL);
	update_kill_ring(entry, ENTRY_JAIL, NULL, 0);
	entry_redraw(GNT_WIDGET(entry));
	return TRUE;
}
Esempio n. 3
0
bool LaunchPoint::matchesTitle(const gchar* str) const
{
	if (!str || !m_title.lowercase)
		return false;

	if (g_str_has_prefix(m_title.lowercase, str))
		return true;

	static const gchar* delimiters = " ,._-:;()\\[]{}\"/";
	static size_t len = strlen(delimiters);
	bool matches = false;
	const gchar* start = m_title.lowercase;
	while (start != NULL) {
		start = strstr(start, str);

		// have we hit the end?
		if (start == NULL || start == m_title.lowercase)
			break;

		// is the previous character in our delimiter set?
		const gchar c[] = {*g_utf8_prev_char(start), '\0'};
		if (strcspn(delimiters, c) < len) {
			matches = true;
			break;
		}
		start = g_utf8_find_next_char(start, NULL);
	}
	return matches;
}
Esempio n. 4
0
static gchar *
build_fallback_thumbstr (FT_Face face)
{
    gchar *chars;
    gint idx, total_chars;
    GString *retval;
    gchar *ptr, *end;
    gboolean found_ascii;

    chars = check_for_ascii_glyph_numbers (face, &found_ascii);

    if (found_ascii)
        return chars;

    idx = 0;
    retval = g_string_new (NULL);
    total_chars = g_utf8_strlen (chars, -1);

    while (idx < 2) {
        total_chars = (gint) floor (total_chars / 2.0);
        ptr = g_utf8_offset_to_pointer (chars, total_chars);
        end = g_utf8_find_next_char (ptr, NULL);

        g_string_append_len (retval, ptr, end - ptr);
        idx++;
    }

  return g_string_free (retval, FALSE);
}
Esempio n. 5
0
/**
 * 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;
}
Esempio n. 6
0
gboolean
gedit_spell_utils_is_digit (const gchar *text)
{
	const gchar *p;
	const gchar *end;

	g_return_val_if_fail (text != NULL, FALSE);

	p = text;
	end = text + strlen (text);

	while (p != NULL && *p != '\0')
	{
		gunichar c = g_utf8_get_char (p);

		if (!g_unichar_isdigit (c) && c != '.' && c != ',')
		{
			return FALSE;
		}

		p = g_utf8_find_next_char (p, end);
	}

	return TRUE;
}
Esempio n. 7
0
static gchar *line_from_buffer(gchar *buffer, guint offset) {
	gint i,j;
	i=j=offset;
	while (i >=0 && i > (offset-40)) {
		if (buffer[i] == '\n' || buffer[i] == '\r') {
			break;
		}
		i--;
	}
	if (i <= offset-40) {
		gchar *tmp = g_utf8_find_next_char(buffer+i, NULL);
		if (tmp)
			i = tmp-buffer;
	} else {
		i++;
	}
	while (buffer[j] !='\0' && j < (offset+40)) {
		if (buffer[j] == '\n' || buffer[j] == '\r') {
			break;
		}
		j++;
	}
	if (j >= offset+40) {
		gchar *tmp = g_utf8_find_prev_char(buffer, buffer+j);
		if (tmp)
			j = tmp-buffer;
	}
	return g_strndup(buffer+i, j-i);
}
Esempio n. 8
0
static gchar *
random_string_from_available_chars (FT_Face face,
                                    gint n_chars)
{
  gchar *chars;
  gint idx, rand, total_chars;
  GString *retval;
  gchar *ptr, *end;

  idx = 0;
  chars = build_charlist_for_face (face, &total_chars);

  if (total_chars == 0)
    return NULL;

  retval = g_string_new (NULL);

  while (idx < n_chars) {
    rand = g_random_int_range (0, total_chars);

    ptr = g_utf8_offset_to_pointer (chars, rand);
    end = g_utf8_find_next_char (ptr, NULL);

    g_string_append_len (retval, ptr, end - ptr);
    idx++;
  }

  return g_string_free (retval, FALSE);
}
Esempio n. 9
0
/*! \brief Get name and value from an attribute 'name=value' string.
 *  \par Function Description
 *  This function parses the character string \a string expected to be
 *  an attribute string of the form 'name=value'.
 *
 *  It returns TRUE if it has been able to parse the string into the
 *  name and value parts of an attribute. Otherwise it returns FALSE,
 *  in that case \a *name_ptr and \a *value_ptr are set to NULL.
 *
 *  \a name_ptr and/or \a value_ptr can be NULL.
 *  If not NULL, the caller must g_free these returned strings.
 *
 *  \note
 *  If you get an invalid attribute (improper) with a name and no
 *  value, then it is NOT an attribute. Also, there cannot be any
 *  spaces beside the equals sign
 *
 *  \param [in]  string     String to split into name/value pair.
 *  \param [out] name_ptr   The return location for the name, or NULL.
 *  \param [out] value_ptr  The return location for the value, or NULL.
 *  \return TRUE on success, FALSE otherwise.
 */
gboolean
o_attrib_string_get_name_value (const gchar *string, gchar **name_ptr, gchar **value_ptr)
{
  gchar *ptr, *prev_char, *next_char;

  if (name_ptr != NULL)
    *name_ptr = NULL;
  if (value_ptr != NULL)
    *value_ptr = NULL;

  g_return_val_if_fail (string != NULL, FALSE);

  ptr = g_utf8_strchr (string, -1, g_utf8_get_char ("="));
  if (ptr == NULL) {
    return FALSE;
  }

  prev_char = g_utf8_find_prev_char (string, ptr);
  next_char = g_utf8_find_next_char (ptr, NULL);
  if (prev_char == NULL || *prev_char == ' ' ||
      next_char == NULL || *next_char == ' ' || *next_char == '\0' ) {
    return FALSE;
  }

  if (name_ptr != NULL) {
    *name_ptr = g_strndup (string, (ptr - string));
  }

  if (value_ptr != NULL) {
    *value_ptr = g_strdup (next_char);
  }

  return TRUE;
}
Esempio n. 10
0
static void
advance_pos (TextgenTemplate *tpl,
             const gchar *text, 
             gint length,
             gint *pos,
             gint *line,
             gint *column,
             GError **error)
{
  const gchar *next_char = g_utf8_find_next_char (text + *pos, text + length + 1);
  
  if (!next_char)
    {
      emit_message (tpl, TEXTGEN_MESSAGE_ERROR, *line, *column,
                    _("Invalid UTF-8 character"));
      set_parse_error (error);
      return;
    }
  
  if (text[*pos] == '\n')
    {
      (*line)++;
      *column = 1;
    }
  else
    (*column)++;

  *pos = next_char - text;
}
Esempio n. 11
0
/**
 * get a gsb_real number from a string, during file load
 * the string can be formatted :
 * - spaces and the given utf8-encoded thousands separators are ignored
 * - handle only "." as a decimal separator
 * - another character makes a error_real return
 *
 * \param string
 * \param mon_thousands_sep, can be NULL or empty, but only one utf8 sequence
 * \param mon_decimal_point, can be NULL or empty, but only one utf8 sequence
 *
 * \return the number in the string transformed to gsb_real
 */
gsb_real gsb_real_safe_real_from_string ( const gchar *string )
{
    unsigned nb_digits = 0;
    gint64 mantissa = 0;
    gint8 sign = 0;
    gint8 dot_position = -1;
    const gchar *p = string;

    if ( !string)
        return error_real;
    if ( g_strstr_len ( string, -1, ERROR_REAL_STRING ) )
        return error_real;

    for ( ; ; )
    {
        if ( g_ascii_isdigit ( *p ) )
        {
            mantissa *= 10;
            mantissa += ( *p - '0' );
            if ( mantissa > G_MAXINT64 )
                return error_real;
            if ( sign == 0 ) sign = 1; /* no sign found yet ==> positive */
            ++nb_digits;
            ++p;
            /* printf ("mantissa = %lld nb_digits = %d\n", mantissa, nb_digits); */
        }
        else if ( *p == 0 ) /* terminal zero */
        {
			gsb_real result;
			result.mantissa = sign * mantissa;
            if ( mantissa == 0 )
                result.exponent = 0;
            else
                result.exponent = ( dot_position >= 0 )
                              ? nb_digits - dot_position
                              : 0;
            /* printf ("result.mantissa = %ld result.exponent = %d\n", result.mantissa, result.exponent); */
            return result;
        }
        else if ( strchr ( ".", *p ) )
        {
            if ( dot_position >= 0 ) /* already found a decimal separator */
                return error_real;
            dot_position = nb_digits;
            p = g_utf8_find_next_char ( p, NULL );
        }
        else if ( strchr ( "-", *p ) )
        {
            if ( sign != 0 ) /* sign already set */
                return error_real;
            sign = -1;
            ++p;
        }
        else /* unknown char ==> error */
        {
            return error_real;
        }
    }
}
Esempio n. 12
0
char *TextEdit::nextChar(const char *p) const
{
  // this happens when point == gapstart
  if (p == gapstart)
    p = gapend;

  if (p < gapstart) {
    if ((p = g_utf8_find_next_char(p, gapstart)))
      return const_cast<char*>(p);
    else
      return const_cast<char*>(gapend);
  }

  if ((p = g_utf8_find_next_char(p, bufend)))
    return const_cast<char*>(p);
  else
    return const_cast<char*>(bufend);
}
Esempio n. 13
0
static const char *
next_begin_word(const char *text, const char *end)
{
	gunichar ch = 0;

	while (text && text < end && g_unichar_isspace(g_utf8_get_char(text)))
		text = g_utf8_find_next_char(text, end);

	if (text) {
		ch = g_utf8_get_char(text);
		while ((text = g_utf8_find_next_char(text, end)) != NULL && text <= end) {
			gunichar cur = g_utf8_get_char(text);
			if (!SAME(ch, cur))
				break;
		}
	}
	return (text ? text : end);
}
Esempio n. 14
0
static gboolean
move_end(GntBindable *bind, GList *null)
{
	GntEntry *entry = GNT_ENTRY(bind);
	entry->cursor = entry->end;
	/* This should be better than this */
	while (gnt_util_onscreen_width(entry->scroll, entry->cursor) >= GNT_WIDGET(entry)->priv.width)
		entry->scroll = g_utf8_find_next_char(entry->scroll, NULL);
	entry_redraw(GNT_WIDGET(entry));
	update_kill_ring(entry, ENTRY_JAIL, NULL, 0);
	return TRUE;
}
Esempio n. 15
0
int Window::mvaddstring(int x, int y, const char *str)
{
  g_assert(str);

  wmove(p->win, y, x);

  int printed = 0;
  while (str && *str) {
    printed += PrintChar(g_utf8_get_char(str));
    str = g_utf8_find_next_char(str, NULL);
  }
  return printed;
}
Esempio n. 16
0
static gboolean
move_forward_word(GntBindable *bind, GList *list)
{
	GntEntry *entry = GNT_ENTRY(bind);
	GntWidget *widget = GNT_WIDGET(bind);
	entry->cursor = (char *)next_begin_word(entry->cursor, entry->end);
	while (gnt_util_onscreen_width(entry->scroll, entry->cursor) >= widget->priv.width) {
		entry->scroll = g_utf8_find_next_char(entry->scroll, NULL);
	}
	update_kill_ring(entry, ENTRY_JAIL, NULL, 0);
	entry_redraw(widget);
	return TRUE;
}
Esempio n. 17
0
void str_ltrim(char *str)
{
	char *pos = str;

	while (*pos && (*pos == ' ' || *pos == '\t' || *pos == '\r' || *pos == '\n')) {
		pos = g_utf8_find_next_char(pos, NULL);
	}

	if (pos != str) {
		size_t size = strlen(str) - (pos-str) + 1;
		memmove(str, pos, size);
	}
}
Esempio n. 18
0
/**
 * tracker_text_normalize:
 * @text: the text to normalize
 * @max_words: the maximum words of @text to normalize
 * @n_words: the number of words actually normalized
 *
 * This function iterates through @text checking for UTF-8 validity
 * using g_utf8_get_char_validated(). For each character found, the
 * %GUnicodeType is checked to make sure it is one fo the following
 * values:
 * <itemizedlist>
 *  <listitem><para>%G_UNICODE_LOWERCASE_LETTER</para></listitem>
 *  <listitem><para>%G_UNICODE_MODIFIER_LETTER</para></listitem>
 *  <listitem><para>%G_UNICODE_OTHER_LETTER</para></listitem>
 *  <listitem><para>%G_UNICODE_TITLECASE_LETTER</para></listitem>
 *  <listitem><para>%G_UNICODE_UPPERCASE_LETTER</para></listitem>
 * </itemizedlist>
 *
 * All other symbols, punctuation, marks, numbers and separators are
 * stripped. A regular space (i.e. " ") is used to separate the words
 * in the returned string.
 *
 * The @n_words can be %NULL. If specified, it will be populated with
 * the number of words that were normalized in the result.
 *
 * Returns: a newly-allocated string holding the result which should
 * be freed with g_free() when finished with, otherwise %NULL.
 *
 * Since: 0.8
 *
 * Deprecated: 0.10: Use tracker_text_validate_utf8() instead.
 **/
gchar *
tracker_text_normalize (const gchar *text,
                        guint        max_words,
                        guint       *n_words)
{
	GString *string;
	gboolean in_break = TRUE;
	gunichar ch;
	gint words = 0;

	string = g_string_new (NULL);

	while ((ch = g_utf8_get_char_validated (text, -1)) > 0) {
		GUnicodeType type;

		type = g_unichar_type (ch);

		if (type == G_UNICODE_LOWERCASE_LETTER ||
		    type == G_UNICODE_MODIFIER_LETTER ||
		    type == G_UNICODE_OTHER_LETTER ||
		    type == G_UNICODE_TITLECASE_LETTER ||
		    type == G_UNICODE_UPPERCASE_LETTER) {
			/* Append regular chars */
			g_string_append_unichar (string, ch);
			in_break = FALSE;
		} else if (!in_break) {
			/* Non-regular char found, treat as word break */
			g_string_append_c (string, ' ');
			in_break = TRUE;
			words++;

			if (words > max_words) {
				break;
			}
		}

		text = g_utf8_find_next_char (text, NULL);
	}

	if (n_words) {
		if (!in_break) {
			/* Count the last word */
			words += 1;
		}
		*n_words = words;
	}

	return g_string_free (string, FALSE);
}
Esempio n. 19
0
static const char *
begin_word(const char *text, const char *begin)
{
	gunichar ch = 0;
	while (text > begin && (!*text || g_unichar_isspace(g_utf8_get_char(text))))
		text = g_utf8_find_prev_char(begin, text);
	ch = g_utf8_get_char(text);
	while ((text = g_utf8_find_prev_char(begin, text)) >= begin) {
		gunichar cur = g_utf8_get_char(text);
		if (!SAME(ch, cur))
			break;
	}

	return (text ? g_utf8_find_next_char(text, NULL) : begin);
}
Esempio n. 20
0
static gboolean search_by_letters (const gchar *source, gint s_len, const gchar *letters, gint l_len)
{
  gboolean found = FALSE;
  const gchar *p1 = letters;
  const gchar *p2 = source;
  while (p1 < letters + l_len) {
    gunichar c1 = g_utf8_get_char (p1);
    found = FALSE;
    while (p2 < source + s_len) {
      gunichar c2 = g_utf8_get_char (p2);
      if (c1 == c2) {
	found = TRUE;
	p2 = g_utf8_find_next_char (p2, NULL);
	break;
      }
      p2 = g_utf8_find_next_char (p2, NULL);
    }
    if (!found)
      break;
    p1 = g_utf8_find_next_char (p1, NULL);
  }

  return found;
}
Esempio n. 21
0
int Window::mvaddstring(int x, int y, const char *str, const char *end)
{
  g_assert(str);
  g_assert(end);

  if (str >= end)
    return 0;

  wmove(p->win, y, x);

  int printed = 0;
  while (str < end && str && *str) {
    printed += PrintChar(g_utf8_get_char(str));
    str = g_utf8_find_next_char(str, end);
  }
  return printed;
}
static gdouble
quality_func (MatePasswordDialog *dialog, const char *text, gpointer ptr)
{
	const char *p;
	gsize length;
	int uppercase = 0, symbols = 0, numbers = 0, strength;
	gunichar uc;

	if (text == NULL) return 0.0;

	/* Get the length */
	length = g_utf8_strlen (text, -1);

	/* Count the number of number, symbols and uppercase chars */
	for (p = text; *p; p = g_utf8_find_next_char (p, NULL))
	{
		uc = g_utf8_get_char (p);

		if (g_unichar_isdigit (uc))
		{
			numbers++;
		}
		else if (g_unichar_isupper (uc))
		{
			uppercase++;
		}
		else if (g_unichar_islower (uc))
		{
			/* Not counted */
		}
		else if (g_unichar_isgraph (uc))
		{
			symbols++;
		}
	}

	if (length    > 5) length = 5;
	if (numbers   > 3) numbers = 3;
	if (symbols   > 3) symbols = 3;
	if (uppercase > 3) uppercase = 3;

	strength = (length * 10 - 20) + (numbers * 10) + (symbols * 15) + (uppercase * 10);
	strength = CLAMP (strength, 0, 100);

	return (double) strength / 100.0;
}
Esempio n. 23
0
char *
linguistics_expand_special(char *str, int mode)
{
	char *in=str;
	char *out,*ret;
	int found=0;
	out=ret=g_strdup(str);
	if (!mode) 
		return ret;
	while (*in) {
		char *next=g_utf8_find_next_char(in, NULL);
		int i,len=next-in;
		int match=0;
		if (len > 1) {
			for (i = 0 ; i < sizeof(special)/sizeof(special[0]); i++) {
				const char *search=special[i][0];
				if (!strncmp(in,search,len)) {
					const char *replace=special[i][mode];
					if (replace) {
						int replace_len=strlen(replace);
						dbg_assert(replace_len <= len);
						dbg(1,"found %s %s %d %s %d\n",in,search,len,replace,replace_len);
						strcpy(out, replace);
						out+=replace_len;
						match=1;
						break;
					}
				}
			}
		}
		if (match) {
			found=1;
			in=next;
		} else {
			while (len-- > 0) 
				*out++=*in++;
		}
	}
	*out++='\0';
	if (!found) {
		g_free(ret);
		ret=NULL;
	}
	return ret;
}
static gchar *
rejilla_project_name_truncate_label (const gchar *label)
{
	const gchar *delim;
	gchar *next_char;

	/* find last possible character. We can't just do a tmp + 32 
	 * since we don't know if we are at the start of a character */
	delim = label;
	while ((next_char = g_utf8_find_next_char (delim, NULL))) {
		if (next_char - label > 32)
			break;

		delim = next_char;
	}

	return g_strndup (label, delim - label);
}
Esempio n. 25
0
void
fvkbd_key_send_utf8_string(gchar *string)
{
	gint i,ret = 1;
	gchar *p = string;

	for (i = g_utf8_strlen(string, -1); i > 0; i--) {
		ret = fakekey_press(get_fakekey_instance(),
				(unsigned char *)p, -1, 0);
		fakekey_release(get_fakekey_instance());

		if (ret == 0)
			break;

		p = g_utf8_find_next_char(p, NULL);
	}
	DBG("action: send string: %s, result:%d\n", string, ret);
}
static gunichar
get_first_non_underscore_char (const char *str)
{
    const char *p;

    if (!str)
        return 0;

    for (p = str; p && *p; p = g_utf8_find_next_char (p, NULL))
    {
        gunichar ch;

        ch = g_utf8_get_char (p);
        if (g_unichar_isalpha (ch))
            return ch;
    }

    return 0;
}
Esempio n. 27
0
static gboolean
delkey(GntBindable *bind, GList *null)
{
	int len;
	GntEntry *entry = GNT_ENTRY(bind);

	if (entry->cursor >= entry->end)
		return FALSE;

	len = g_utf8_find_next_char(entry->cursor, NULL) - entry->cursor;
	update_kill_ring(entry, ENTRY_JAIL, entry->cursor, len);
	memmove(entry->cursor, entry->cursor + len, entry->end - entry->cursor - len + 1);
	entry->end -= len;
	entry_redraw(GNT_WIDGET(entry));

	if (entry->ddown)
		show_suggest_dropdown(entry);
	entry_text_changed(entry);
	return TRUE;
}
Esempio n. 28
0
void goto_local_label (const gchar *l)
{
	gchar *t = g_utf8_find_next_char (l, NULL);
	gchar *s = g_strconcat ("<a name=\"", t, NULL);

	GtkTextIter iter;
	GtkTextIter match_start;

	GtkTextMark *m = gtk_text_buffer_get_insert (GTK_TEXT_BUFFER(cur_text_doc->text_buffer)); 
	gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER(cur_text_doc->text_buffer), &iter, m);

	if (gtk_text_iter_forward_search  (&iter, s, GTK_TEXT_SEARCH_TEXT_ONLY, &match_start, NULL, NULL))
	{
		gtk_text_buffer_place_cursor (GTK_TEXT_BUFFER(cur_text_doc->text_buffer), &match_start );
		gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW(cur_text_doc->text_view), &match_start, 0.0, TRUE, 0.0, 0.0 );
		gtk_text_view_place_cursor_onscreen (GTK_TEXT_VIEW (cur_text_doc->text_view));
	}

	g_free (s);
}
Esempio n. 29
0
void
dates_details_time_entry_changed (GtkEditable *entry, gchar *new_text,
				  gint new_text_length,
				  gint *position,
				  DatesData *d)
{
    gint i;
    gchar *c;
	
    for (i = 0, c = new_text; c;
	 c = g_utf8_find_next_char (c, (new_text_length != -1) ?
				    (new_text + new_text_length) : NULL)) {
	if (*c < '0' || *c > '9') {
	    g_signal_stop_emission (entry, g_signal_lookup (
					"insert-text", GTK_TYPE_EDITABLE), 0);
	    gdk_beep ();
	    break;
	}
    }
}
Esempio n. 30
0
/**
 * SPI_createAccessibleKeySet:
 * @len: the number of key values in the key set.
 * @keysyms: a UTF-8 string containing symbolic key values to be matched, or NULL if
 *           matching is performed against other key values instead.
 * @keycodes: an array of unsigned short values which are the hardware keycodes
 *           to be matched, or NULL if the keyset is specified solely by keysyms
 *           and/or keystrings.
 * @keystrings: an array of null-terminated character strings which specify key
 *             name values to match, or NULL if the keyset is specified solely by
 *             keycodes and/or keysyms.
 *
 * Create a new #AccessibleKeySet of a specified length.
 * A KeySet is used typically to match key event values, and a matches are made
 * using the following criteria: a match exists with a key event if all non-null
 * i-th members of the keyset match the key event.
 * If both keystring and keysym values are NULL, a keycode value match is
 * forced, thus the match for keysym=0, keycode=0, keystring=NULL is
 * keycode 0.
 *
 * Returns: a pointer to a newly-created #AccessibleKeySet.
 *
 **/
AccessibleKeySet *
SPI_createAccessibleKeySet (int len, const char *keysyms, short *keycodes,
			    const char **keystrings)
{
  AccessibleKeySet *keyset = g_new0 (AccessibleKeySet, 1);
  int i, keysym_len = 0;
  const char *keysym_ptr = keysyms;
  keyset->len = len;
  keyset->keysyms = g_new0 (unsigned long, len);
  keyset->keycodes = g_new0 (unsigned short, len);
  keyset->keystrings = g_new0 (char *, len);
  if (keysyms)
    {
      keysym_len = g_utf8_strlen (keysyms, -1);
    }
  for (i = 0; i < len; ++i)
    {
      if (i < keysym_len)
        {
	  keyset->keysyms [i] = (unsigned long) g_utf8_get_char (keysym_ptr);
	  keysym_ptr = g_utf8_find_next_char (keysym_ptr, NULL);
        }
      else
        {
          keyset->keysyms [i] = 0;
        }
      if (keycodes)
        {
	  keyset->keycodes [i] = keycodes [i];
	}
      if (keystrings)
        {
	  keyset->keystrings [i] = g_strdup (keystrings [i]);
	}
    }
  return keyset;	
}