Example #1
0
/* Function: al_ustr_compare
 */
int al_ustr_compare(const ALLEGRO_USTR *us1, const ALLEGRO_USTR *us2)
{
   int pos1 = 0;
   int pos2 = 0;

   for (;;) {
      int32_t c1 = al_ustr_get_next(us1, &pos1);
      int32_t c2 = al_ustr_get_next(us2, &pos2);

      if (c1 != c2)
	 return c1 - c2;

      if (c1 == -1) /* == c2 */
	 return 0;
   }
}
Example #2
0
/* Function: al_ustr_find_set
 */
int al_ustr_find_set(const ALLEGRO_USTR *us, int start_pos,
   const ALLEGRO_USTR *accept)
{
   int rc;
   int32_t c, d;
   int pos;
   int set_pos;

   /* Fast path for ASCII characters. */
   if (all_ascii(accept)) {
      rc = _al_binchr(us, start_pos, accept);
      return (rc == _AL_BSTR_ERR) ? -1 : rc;
   }

   /* Non-ASCII. */
   pos = 0;
   while ((c = al_ustr_get(us, pos)) != -1) {
      if (c == -2) {
         /* Invalid byte sequence. */
         pos++;
         continue;
      }

      set_pos = 0;
      while ((d = al_ustr_get_next(accept, &set_pos)) != -1) {
         if (c == d)
            return pos;
      }

      pos += al_utf8_width(c);
   }

   return -1;
}
Example #3
0
/* Function: al_ustr_ncompare
 */
int al_ustr_ncompare(const ALLEGRO_USTR *us1, const ALLEGRO_USTR *us2, int n)
{
   int pos1 = 0;
   int pos2 = 0;

   if (n <= 0)
      return 0;

   for (;;) {
      int32_t c1 = al_ustr_get_next(us1, &pos1);
      int32_t c2 = al_ustr_get_next(us2, &pos2);

      if (c1 != c2)
	 return c1 - c2;

      if ((c1 == -1) || (--n <= 0))
	 return 0;
   }
}
Example #4
0
static mrb_value
bmfont_each_codepoint_from(mrb_state *mrb, mrb_value self)
{
  char *cstr;
  mrb_value blk;

  ALLEGRO_USTR *ustr;
  int pos = 0;
  int codepoint = 0;

  mrb_get_args(mrb, "z&", &cstr, &blk);

  ustr = al_ustr_new(cstr);

  for (codepoint = al_ustr_get_next(ustr, &pos); codepoint > 0; codepoint = al_ustr_get_next(ustr, &pos)) {
    mrb_yield(mrb, blk, mrb_fixnum_value(codepoint));
  }

  if (ustr) al_ustr_free(ustr);

  return mrb_nil_value();
}
Example #5
0
/* Output message to Unicode log. */
static void wlog_do_append_native_text_log_unicode(ALLEGRO_NATIVE_DIALOG *textlog)
{
#define BUFFER_SIZE  512
   bool flush;
   int index, ch, next;
   static WCHAR buffer[BUFFER_SIZE + 1] = { 0 };

   CHARFORMATW format;
   memset(&format, 0, sizeof(format));
   format.cbSize      = sizeof(format);
   format.dwMask      = CFM_COLOR;
   format.crTextColor = RGB(128, 255, 128);

   index = GetWindowTextLength(textlog->tl_textview);
   SendMessageW(textlog->tl_textview, EM_SETSEL, (WPARAM)index, (LPARAM)index);
   SendMessageW(textlog->tl_textview, EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&format);

   next = 0;
   index = 0;
   flush = false;
   while ((ch = al_ustr_get_next(textlog->tl_pending_text, &next)) >= 0) {
      buffer[index] = (WCHAR)ch;
      flush = true;

      index++;

      if ((index % BUFFER_SIZE) == 0) {
         buffer[BUFFER_SIZE] = L'\0';
         SendMessageW(textlog->tl_textview, EM_REPLACESEL, 0, (LPARAM)buffer);
         flush = false;
         index = 0;
      }
   }

   if (flush) {
      buffer[index] = L'\0';
      SendMessageW(textlog->tl_textview, EM_REPLACESEL, 0, (LPARAM)buffer);
   }

   al_ustr_truncate(textlog->tl_pending_text, 0);
   textlog->tl_have_pending = false;
}
Example #6
0
/* Test al_ustr_get_next. */
static void t29(void)
{
   ALLEGRO_USTR *us = al_ustr_new("aþ€");
   int pos;

   pos = 0;
   CHECK(al_ustr_get_next(us, &pos) == 'a');
   CHECK(al_ustr_get_next(us, &pos) == U_thorn);
   CHECK(al_ustr_get_next(us, &pos) == U_euro);
   CHECK(al_ustr_get_next(us, &pos) == -1);
   CHECK(pos == (int) al_ustr_size(us));

   /* Start in the middle of þ. */
   pos = 2;
   CHECK(al_ustr_get_next(us, &pos) == -2);
   CHECK(al_ustr_get_next(us, &pos) == U_euro);

   al_ustr_free(us);
}