Пример #1
0
gboolean
xed_spell_utils_is_digit (const char *text, gssize length)
{
	gunichar c;
	const gchar *p;
	const gchar *end;

	g_return_val_if_fail (text != NULL, FALSE);

	if (length < 0)
		length = strlen (text);

	p = text;
	end = text + length;

	while (p != end) {
		const gchar *next;
		next = g_utf8_next_char (p);

		c = g_utf8_get_char (p);

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

		p = next;
	}

	return TRUE;
}
Пример #2
0
static bool _tokenize_identifier(GSDLTokenizer *self, GSDLToken *result, gunichar c, GError **err) {
	int length = 7;
	char *output = result->val = g_malloc(length);
	GUnicodeType type;

	int i = g_unichar_to_utf8(c, output);

	while (_peek(self, &c, err) && (c == '-' || c == '.' || g_unichar_isalpha(c) || g_unichar_isdigit(c) || (type = g_unichar_type(c)) == G_UNICODE_CURRENCY_SYMBOL || type == G_UNICODE_CONNECT_PUNCTUATION || type == G_UNICODE_LETTER_NUMBER || type == G_UNICODE_SPACING_MARK || type == G_UNICODE_NON_SPACING_MARK)) {
		GROW_IF_NEEDED(output = result->val, i + 5, length);

		_consume(self);
		i += g_unichar_to_utf8(c, output + i);
	}

	FAIL_IF_ERR();
	output[i] = '\0';

	if (
			strcmp(output, "true") == 0 ||
			strcmp(output, "on") == 0 ||
			strcmp(output, "false") == 0 ||
			strcmp(output, "off") == 0) {
		result->type = T_BOOLEAN;
	} else if (strcmp(output, "null") == 0) {
		result->type = T_NULL;
	}

	return true;
}
Пример #3
0
void TextEdit::setFlags(int new_flags, bool revalidate)
{
  if (new_flags == flags)
    return;

  flags = new_flags;

  if (flags && revalidate) {
    bool valid = true;
    const char *p = getTextStart();
    while (p < bufend - 1) {
      gunichar uc = g_utf8_get_char(p);
      if ((flags & FLAG_ALPHABETIC) && !g_unichar_isalpha(uc)) {
        valid = false;
        break;
      }
      if ((flags & FLAG_NUMERIC) && !g_unichar_isdigit(uc)) {
        valid = false;
        break;
      }
      if ((flags & FLAG_NOSPACE) && g_unichar_isspace(uc)) {
        valid = false;
        break;
      }
      if ((flags & FLAG_NOPUNCTUATION) && g_unichar_ispunct(uc)) {
        valid = false;
        break;
      }
      p = nextChar(p);
    }
    if (!valid)
      clear();
  }
}
Пример #4
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;
}
Пример #5
0
static int
str_utf8_isdigit (const char *text)
{
    gunichar uni;

    uni = g_utf8_get_char_validated (text, -1);
    return g_unichar_isdigit (uni);
}
Пример #6
0
static void
browser_dialog_make_index_foreach (const gchar    *help_id,
                                   GimpHelpItem   *item,
                                   GimpHelpLocale *locale)
{
#if 0
  g_printerr ("%s: processing %s (parent %s)\n",
              G_STRFUNC,
              item->title  ? item->title  : "NULL",
              item->parent ? item->parent : "NULL");
#endif

  if (item->title)
    {
      gchar **indices = g_strsplit (item->title, ".", -1);
      gint    i;

      for (i = 0; i < 5; i++)
        {
          gunichar c;

          if (! indices[i])
            break;

          c = g_utf8_get_char (indices[i]);

          if (g_unichar_isdigit (c))
            {
              item->index += atoi (indices[i]) << (8 * (5 - i));
            }
          else if (g_utf8_strlen (indices[i], -1) == 1)
            {
              item->index += (c & 0xFF) << (8 * (5 - i));
            }
        }

      g_strfreev (indices);
    }

  if (item->parent && strlen (item->parent))
    {
      GimpHelpItem *parent;

      parent = g_hash_table_lookup (locale->help_id_mapping, item->parent);

      if (parent)
        {
          parent->children = g_list_prepend (parent->children, item);
        }
    }
  else
    {
      locale->toplevel_items = g_list_prepend (locale->toplevel_items, item);
    }
}
Пример #7
0
/* retrieve the status code from the server response line */
int DictClient::get_status_code(gchar *line)
{
  gint retval;

  if (strlen (line) < 3)
    return 0;

  if (!g_unichar_isdigit (line[0]) ||
      !g_unichar_isdigit (line[1]) ||
      !g_unichar_isdigit (line[2]))
    return 0;

  gchar tmp = line[3];
  line[3] = '\0';

  retval = atoi(line);

  line[3] = tmp;

  return retval;
}
Пример #8
0
static void
gnc_price_cell_modify_verify (BasicCell *_cell,
                              const char *change,
                              int change_len,
                              const char *newval,
                              int newval_len,
                              int *cursor_position,
                              int *start_selection,
                              int *end_selection)
{
    PriceCell *cell = (PriceCell *) _cell;
    struct lconv *lc = gnc_localeconv ();
    const char *toks = "+-*/=()_";
    gunichar decimal_point;
    gunichar thousands_sep;
    const char *c;
    gunichar uc;

    /* accept the newval string if user action was delete */
    if (change == NULL)
    {
        gnc_basic_cell_set_value_internal (_cell, newval);
        cell->need_to_parse = TRUE;
        return;
    }

    if (cell->print_info.monetary)
        decimal_point = g_utf8_get_char(lc->mon_decimal_point);
    else
        decimal_point = g_utf8_get_char(lc->decimal_point);

    if (cell->print_info.monetary)
        thousands_sep = g_utf8_get_char(lc->mon_thousands_sep);
    else
        thousands_sep = g_utf8_get_char(lc->thousands_sep);

    c = change;
    while (*c)
    {
        uc = g_utf8_get_char (c);
        if (!g_unichar_isdigit (uc) &&
                !g_unichar_isspace (uc) &&
                !g_unichar_isalpha (uc) &&
                (decimal_point != uc) &&
                (thousands_sep != uc) &&
                (g_utf8_strchr (toks, -1, uc) == NULL))
            return;
        c = g_utf8_next_char (c);
    }

    gnc_basic_cell_set_value_internal (_cell, newval);
    cell->need_to_parse = TRUE;
}
Пример #9
0
/*
 \brief Helper function to parse a line from the keymap configuration file.
*/
static int parse_keymap_line (imli_input_method_t im, char *line)
{
    char key = 0;
    char code = 0;
    imli_char_type_t type = TYPE_INVALID;
    
    // skip leading white space
    CHECK_AND_SKIP_WS(line, 0);
    // comments; ignore the rest of the line
    if (*line == '/' && *(line + 1) == '/')
	return 0;
    // key - only printable ascii allowed
    if (*line > 32)
    {
	key = *line++;
	CHECK_AND_SKIP_WS(line, -1);
    }
    else
    {
	return -1;
    }
    
    // code - only digits allowed
    while (g_unichar_isdigit(*line))
    {
	code = code * 10 + (*line - '0');
	line++;
    }
    
    CHECK_AND_SKIP_WS(line, -1);
    
    // type
    if (*line == 'C')
	type = TYPE_CONSONANT;
    else if (*line == 'V')
	type = TYPE_VOWEL;
    else if (*line == 'S')
	type = TYPE_SPECIAL;
    else if (*line == 'A')
	type = TYPE_ASCII;
    else if (*line == 'I')
	type = TYPE_INVALID;
    else
	return -1;
    
    // ignore the rest of the line
    im->codes[(int)key] = code;
    im->types[(int)key] = type;
    return 0;
}
Пример #10
0
static void dt_int_verify(GtkWidget *entry)
{
     char *txt = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1);
     gunichar c = 0;

     if (txt) {
	  char *t;
	  GString *s	= g_string_sized_new(strlen(txt));
	  int nope	= 0;

	  /* strip leading whitespace */
	  for(t = txt, c = g_utf8_get_char(t) ;
	      g_unichar_isspace(c) ;
	      t = g_utf8_next_char(t), c = g_utf8_get_char(t)) {
	  }

	  /* one leading minus is OK */
	  if (c == g_utf8_get_char("-")) {
	       g_string_append_unichar(s, c);
	       t = g_utf8_next_char(t);
	       c = g_utf8_get_char(t);
	  }

	  /* allow only digits, no leading zeroes */
	  for(c = g_utf8_get_char(t) ;
	      c ;
	      t = g_utf8_next_char(t), c = g_utf8_get_char(t)) {
	       if (g_unichar_isdigit(c)) {
		    g_string_append_unichar(s, c);
	       } else {
		    nope = 1;
	       }
	  }
	  g_free(txt);

	  txt = g_strcompress(s->str); /* one-byte chars only */
	  if (strcmp(txt, "0") != 0) {
	       for(t = txt ; *t == '0' ; t++) nope = 1;
	       if (*t == 0 && txt != t) t--; /* must have zeros-only string */
	  }

	  if (nope) {
	       gtk_entry_set_text(GTK_ENTRY(entry), t);
	  }

	  g_string_free(s, TRUE);
     }
     return;
}
Пример #11
0
gboolean
gnomegadu_protocol_is_valid_uin (gchar * uin_str)
{
	int i = 0;
	gboolean valid = TRUE;

	if (!uin_str || (g_utf8_strlen (uin_str, -1) == 0))
		return FALSE;

	for (i = 0; i < g_utf8_strlen (uin_str, -1); i++)
		if (!g_unichar_isdigit (uin_str[i]))
			valid = FALSE;

	return valid;
}
Пример #12
0
gboolean
empathy_spell_check (const gchar *word)
{
	gint         enchant_result = 1;
	const gchar *p;
	gboolean     digit;
	gunichar     c;
	gint         len;
	GList       *l;

	g_return_val_if_fail (word != NULL, FALSE);

	spell_setup_languages ();

	if (!languages) {
		DEBUG ("No languages to check against");
		return TRUE;
	}

	/* Ignore certain cases like numbers, etc. */
	for (p = word, digit = TRUE; *p && digit; p = g_utf8_next_char (p)) {
		c = g_utf8_get_char (p);
		digit = g_unichar_isdigit (c);
	}

	if (digit) {
		/* We don't spell check digits. */
		DEBUG ("Not spell checking word:'%s', it is all digits", word);
		return TRUE;
	}

	len = strlen (word);
	for (l = languages; l; l = l->next) {
		SpellLanguage  *lang;

		lang = l->data;

		enchant_result = enchant_dict_check (lang->speller, word, len);

		if (enchant_result == 0) {
			break;
		}
	}

	return (enchant_result == 0);
}
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;
}
Пример #14
0
void
glade_name_context_release_name (GladeNameContext *context, const gchar *name)
{

    const gchar *first_number = name;
    gchar *end_number, *base_name;
    GladeIDAllocator *id_allocator;
    gunichar ch;
    gint id;

    g_return_if_fail (context != NULL);
    g_return_if_fail (name && name[0]);

    /* Remove from name hash first... */
    g_hash_table_remove (context->names, name);

    do
    {
        ch = g_utf8_get_char (first_number);

        if (ch == 0 || g_unichar_isdigit (ch))
            break;

        first_number = g_utf8_next_char (first_number);
    }
    while (TRUE);

    /* if there is a number - then we have to unallocate it... */
    if (ch == 0)
        return;

    base_name = g_strdup (name);
    *(base_name + (first_number - name)) = 0;

    if ((id_allocator =
                g_hash_table_lookup (context->name_allocators, base_name)) != NULL)
    {
        id = (int) strtol (first_number, &end_number, 10);
        if (*end_number == 0)
            glade_id_allocator_release (id_allocator, id);
    }

    g_free (base_name);
}
Пример #15
0
static gboolean
ide_editor_view_goto_line_insert_text (IdeEditorView    *self,
                                       guint             position,
                                       const gchar      *chars,
                                       guint             n_chars,
                                       EggSimplePopover *popover)
{
  g_assert (IDE_IS_EDITOR_VIEW (self));
  g_assert (EGG_IS_SIMPLE_POPOVER (popover));
  g_assert (chars != NULL);

  for (; *chars; chars = g_utf8_next_char (chars))
    {
      if (!g_unichar_isdigit (g_utf8_get_char (chars)))
        return GDK_EVENT_STOP;
    }

  return GDK_EVENT_PROPAGATE;
}
Пример #16
0
gboolean
empathy_spell_check (const gchar *word)
{
	gint         enchant_result = 1;
	const gchar *p;
	gboolean     digit;
	gunichar     c;
	gint         len;
	GHashTableIter iter;
	SpellLanguage  *lang;

	g_return_val_if_fail (word != NULL, FALSE);

	spell_setup_languages ();

	if (!languages) {
		return TRUE;
	}

	/* Ignore certain cases like numbers, etc. */
	for (p = word, digit = TRUE; *p && digit; p = g_utf8_next_char (p)) {
		c = g_utf8_get_char (p);
		digit = g_unichar_isdigit (c);
	}

	if (digit) {
		/* We don't spell check digits. */
		DEBUG ("Not spell checking word:'%s', it is all digits", word);
		return TRUE;
	}

	len = strlen (word);
	g_hash_table_iter_init (&iter, languages);
	while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &lang)) {
		enchant_result = enchant_dict_check (lang->speller, word, len);

		if (enchant_result == 0) {
			break;
		}
	}

	return (enchant_result == 0);
}
Пример #17
0
static void
page_entry_insert_text (GtkEditable *editable,
			const gchar *text,
			gint         length,
			gint        *position)
{
	const gchar *end;
	const gchar *p;

	end = text + length;

	for (p = text; p < end; p = g_utf8_next_char (p))
	{
		if (!g_unichar_isdigit (g_utf8_get_char (p)))
		{
			g_signal_stop_emission_by_name (editable, "insert-text");
			break;
		}
	}
}
Пример #18
0
static void search_argumentE(struct parser_context *ctx,
			     struct tagstack_entry *e)
{
    struct gq_config *c = peek_tag(ctx->stack, 1)->data;

    /* compatibility with older versions of gq -- accept
       token number as well */

    gunichar ch = g_utf8_get_char((gchar*)e->cdata);
    if (g_unichar_isdigit(ch)) {
	long l = longCDATA(ctx, e);
	if (l >= 0) {
	    c->search_argument = l;
	} else {
	    XMLhandleError(ctx, _("Invalid token for '%s'"), e->tag);
	}
    } else {
	int t = tokenize(token_searchargument, (gchar*)e->cdata);
	c->search_argument = t;
    }
}
Пример #19
0
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;
}
Пример #20
0
void CheckCapitalization::check_capitalization(vector < int >&chapters, vector < ustring > &verses, ustring & text, vector < size_t > &pointers, bool end_check)
/*
Check capitalization in text.
If "end_check" is true, it also check for final sentence closing.
*/
{
  /*
     Note that this at first used gtk_text_iter_starts_sentence (&iter) and
     gtk_text_iter_ends_sentence (&iter), but these functions are not good enough,
     because do not work in several cases, like e.g. in the following line, it does
     not indicate the end of the sentence:
     As soon as the leaders of the tribes of Israel took their places, the 
     Israelites said, “How could such a horrible thing happen?"
     Therefore we use other means to check sentences.
   */

  // No check if there's no text.
  if (trim(text).empty())
    return;
  // Some variables needed.
  bool expect_capital_now = false;
  bool expect_capital_caused_by_reference = false;
  gunichar previous_char = 0;
  int localchapter = 0;
  ustring localverse = "0";
  GtkTextBuffer *textbuffer;
  textbuffer = gtk_text_buffer_new(NULL);
  gtk_text_buffer_set_text(textbuffer, text.c_str(), -1);
  GtkTextIter iter;
  gtk_text_buffer_get_start_iter(textbuffer, &iter);
  bool going = true;
  while (going) {
    // Get the unicode character.
    gunichar unichar = gtk_text_iter_get_char(&iter);
    // See whether to expect a capital now.
    if (punctuation_followed_by_capitals_set.find(unichar) != punctuation_followed_by_capitals_set.end()) {
      // Ok, expect capital.
      expect_capital_now = true;
      expect_capital_caused_by_reference = false;
      // Was this expectation caused by a reference?
      if (is_reference(iter))
        expect_capital_caused_by_reference = true;
    }
    // If we expect a capital, and we find one, no longer look for one.
    if (expect_capital_now) {
      if (g_unichar_isupper(unichar)) {
        expect_capital_now = false;
      }
    }
    // If we expect a capital, and we get lower case, that might be trouble.
    if (expect_capital_now) {
      if (g_unichar_islower(unichar)) {
        // There is no trouble if it follows a character after which to ignore lower case.
        if (ignore_lower_case_following_set.find(previous_char) != ignore_lower_case_following_set.end()) {
          expect_capital_now = false;
        }
        // If the lowercase character follows an abbreviation, there is no trouble either.
        GtkTextIter iter2 = iter;
        gtk_text_iter_backward_word_start(&iter2);
        GtkTextIter iter3 = iter2;
        gtk_text_iter_forward_word_end(&iter3);
        gtk_text_iter_forward_char(&iter3);
        ustring abbreviation = gtk_text_iter_get_text(&iter2, &iter3);
        if (abbreviations.find(abbreviation) != abbreviations.end()) {
          expect_capital_now = false;
        }
        // If it follows a reference, there is no trouble.
        if (expect_capital_caused_by_reference)
          expect_capital_now = false;
        // Ok, give message.
        if (expect_capital_now) {
          // Determine chapter and verse.
          get_chapter_and_verse(chapters, verses, pointers, iter, localchapter, localverse);
          message(book, localchapter, localverse, _("Capital expected: ") + get_context(iter));
        }
        // Only give one message about missing capitals in this context.
        expect_capital_now = false;
      }
    }
    // Store this characters as the previous characters for the next round.
    if (g_unichar_isgraph(unichar))
      previous_char = unichar;
    // Next round.
    going = gtk_text_iter_forward_char(&iter);
  }
  // The sentence should be ended with proper punctuation.
  if (end_check) {
    if (expect_capital_now)
      if (g_unichar_isdigit(previous_char))
        expect_capital_now = false;
    if (!expect_capital_now) {
      message(book, chapter, verse, _("Unended sentence: ") + get_context(iter));
    }
  }
  // Free memory
  g_object_unref(textbuffer);
}
Пример #21
0
static void
browser_dialog_make_index_foreach (const gchar    *help_id,
                                   GimpHelpItem   *item,
                                   GimpHelpLocale *locale)
{
  gchar *sort_key = item->title;

#if DEBUG_SORT_HELP_ITEMS
  g_printerr ("%s: processing %s (parent %s)\n",
              G_STRFUNC,
              item->title  ? item->title  : "NULL",
              item->parent ? item->parent : "NULL");
#endif

  if (item->sort &&
      g_regex_match_simple ("^[0-9]+([.][0-9]+)*$", item->sort, 0, 0))
    {
      sort_key = item->sort;

#if DEBUG_SORT_HELP_ITEMS
      g_printerr ("%s: sort key = %s\n", G_STRFUNC, sort_key);
#endif
    }

  item->index = 0;

  if (sort_key)
    {
      const gint max_tokens = GIMP_HELP_BROWSER_INDEX_MAX_DEPTH;
      gchar* *indices = g_strsplit (sort_key, ".", max_tokens + 1);
      gint    i;

      for (i = 0; i < max_tokens; i++)
        {
          gunichar c;

          if (! indices[i])
            {
              /* make sure that all item->index's are comparable */
              item->index <<= (8 * (max_tokens - i));
              break;
            }

          item->index <<= 8;  /* NOP if i = 0 */
          c = g_utf8_get_char (indices[i]);
          if (g_unichar_isdigit (c))
            {
              item->index += atoi (indices[i]);
            }
          else if (g_utf8_strlen (indices[i], -1) == 1)
            {
              item->index += (c & 0xFF);
            }
        }

      g_strfreev (indices);

#if DEBUG_SORT_HELP_ITEMS
      g_printerr ("%s: index = %lu\n", G_STRFUNC, item->index);
#endif
    }

  if (item->parent && strlen (item->parent))
    {
      GimpHelpItem *parent;

      parent = g_hash_table_lookup (locale->help_id_mapping, item->parent);

      if (parent)
        {
          parent->children = g_list_prepend (parent->children, item);
        }
    }
  else
    {
      locale->toplevel_items = g_list_prepend (locale->toplevel_items, item);
    }
}
Пример #22
0
static gboolean
gimp_eevl_unit_identifier_continue (gunichar c)
{
  return (gimp_eevl_unit_identifier_start (c) ||
          g_unichar_isdigit (c));
}
Пример #23
0
static void
search_entry_insert_text (GtkEditable    *editable,
                          const gchar    *text,
                          gint            length,
                          gint           *position,
                          GeditViewFrame *frame)
{
	if (frame->priv->search_mode == GOTO_LINE)
	{
		gunichar c;
		const gchar *p;
		const gchar *end;
		const gchar *next;

		p = text;
		end = text + length;

		if (p == end)
			return;

		c = g_utf8_get_char (p);
		
		if (((c == '-' || c == '+') && *position == 0) ||
		    (c == ':' && *position != 0))
		{
			gchar *s = NULL;
		
			if (c == ':')
			{
				s = gtk_editable_get_chars (editable, 0, -1);
				s = g_utf8_strchr (s, -1, ':');
			}
			
			if (s == NULL || s == p)
			{
				next = g_utf8_next_char (p);
				p = next;
			}
			
			g_free (s);
		}

		while (p != end)
		{
			next = g_utf8_next_char (p);

			c = g_utf8_get_char (p);

			if (!g_unichar_isdigit (c))
			{
				g_signal_stop_emission_by_name (editable, "insert_text");
				gtk_widget_error_bell (frame->priv->search_entry);
				break;
			}

			p = next;
		}
	}
	else
	{
		/* SEARCH mode */
		static gboolean  insert_text = FALSE;
		gchar           *escaped_text;
		gint             new_len;

		gedit_debug_message (DEBUG_SEARCH, "Text: %s", text);

		/* To avoid recursive behavior */
		if (insert_text)
			return;

		escaped_text = gedit_utils_escape_search_text (text);

		gedit_debug_message (DEBUG_SEARCH, "Escaped Text: %s", escaped_text);

		new_len = strlen (escaped_text);

		if (new_len == length)
		{
			g_free (escaped_text);
			return;
		}

		insert_text = TRUE;

		g_signal_stop_emission_by_name (editable, "insert_text");
		
		gtk_editable_insert_text (editable, escaped_text, new_len, position);

		insert_text = FALSE;

		g_free (escaped_text);
	}
}
Пример #24
0
static void shortcut_callback(gpointer *number)
{
	gchar *string;
	gchar *str;
	gint i, length;
	guchar a;
	guint val_read;

	string = macros[(long)number].action;
	length = strlen(string);

	for(i = 0; i < length; i++)
	{
		if(string[i] == '\\')
		{
			if(g_unichar_isdigit((gunichar)string[i + 1]))
			{
				if((string[i + 1] == '0') && (string[i + 2] != 0))
				{
					if(g_unichar_isxdigit((gunichar)string[i + 3]))
					{
						str = &string[i + 2];
						i += 3;
					}
					else
					{
						str = &string[i + 1];
						if(g_unichar_isxdigit((gunichar)string[i + 2]))
							i += 2;
						else
							i++;
					}
				}
				else
				{
					str = &string[i + 1];
					if(g_unichar_isxdigit((gunichar)string[i + 2]))
						i += 2;
					else
						i++;
				}
				if(sscanf(str, "%02X", &val_read) == 1)
					a = (guchar)val_read;
				else
					a = '\\';
			}
			else
			{
				switch(string[i + 1])
				{
				case 'a':
					a = '\a';
					break;
				case 'b':
					a = '\b';
					break;
				case 't':
					a = '\t';
					break;
				case 'n':
					a = '\n';
					break;
				case 'v':
					a = '\v';
					break;
				case 'f':
					a = '\f';
					break;
				case 'r':
					a = '\r';
					break;
				case '\\':
					a = '\\';
					break;
				default:
					a = '\\';
					i--;
					break;
				}
				i++;
			}
			send_serial((gchar*)&a, 1);
		}
		else
		{
			send_serial(&string[i], 1);
		}
	}

	str = g_strdup_printf(_("Macro \"%s\" sent !"), macros[(long)number].shortcut);
	Put_temp_message(str, 800);
	g_free(str);
}
Пример #25
0
static void
gnc_date_cell_modify_verify (BasicCell *_cell,
                             const char *change,
                             int change_len,
                             const char *newval,
                             int newval_len,
                             int *cursor_position,
                             int *start_selection,
                             int *end_selection)
{
    DateCell *cell = (DateCell *) _cell;
    PopBox *box = cell->cell.gui_private;
    gboolean accept = FALSE;

    if (box->in_date_select)
    {
        gnc_basic_cell_set_value (_cell, newval);
        return;
    }

    /* if user hit backspace, accept the change */
    if (change == NULL)
        accept = TRUE;
    else if (change_len == 0)
        accept = TRUE;
    else
    {
        int count = 0;
        unsigned char separator = dateSeparator ();
        gboolean ok = TRUE;
        const gchar *c;
        gunichar uc;

        /* accept only numbers or a date separator. Note that the
         * separator of '-' (for DATE_FORMAT_ISO) takes precedence
         * over the accelerator below! */
        c = change;
        while (*c)
        {
            uc = g_utf8_get_char (c);

            if (!g_unichar_isdigit (uc) && (separator != uc))
                ok = FALSE;

            if (separator == uc)
                count++;

            c = g_utf8_next_char (c);
        }

        c = _cell->value;
        while (*c)
        {
            uc = g_utf8_get_char (c);

            if (separator == uc)
                count++;

            c = g_utf8_next_char (c);
        }

        if (2 < count)
            ok = FALSE;

        if (ok)
            accept = TRUE;
    }

    /* keep a copy of the new value */
    if (accept)
    {

        gnc_basic_cell_set_value_internal (&cell->cell, newval);
        gnc_parse_date (&(box->date), newval);

        if (!box->date_picker)
            return;

        block_picker_signals (cell);
        gnc_date_picker_set_date (box->date_picker,
                                  box->date.tm_mday,
                                  box->date.tm_mon,
                                  box->date.tm_year + 1900);
        unblock_picker_signals (cell);
    }
}