Example #1
0
/* Test whitespace trim functions (edge cases). */
static void t16(void)
{
   ALLEGRO_USTR *us1;

   /* Check return value when passed empty strings. */
   us1 = al_ustr_new("");
   CHECK(al_ustr_ltrim_ws(us1));
   CHECK(al_ustr_rtrim_ws(us1));
   CHECK(al_ustr_trim_ws(us1));
   al_ustr_free(us1);

   /* Check nothing bad happens if the whole string is whitespace. */
   us1 = al_ustr_new(" \f\n\r\t\v");
   CHECK(al_ustr_ltrim_ws(us1));
   CHECK(al_ustr_size(us1) == 0);
   al_ustr_free(us1);

   us1 = al_ustr_new(" \f\n\r\t\v");
   CHECK(al_ustr_rtrim_ws(us1));
   CHECK(al_ustr_size(us1) == 0);
   al_ustr_free(us1);

   us1 = al_ustr_new(" \f\n\r\t\v");
   CHECK(al_ustr_trim_ws(us1));
   CHECK(al_ustr_size(us1) == 0);
   al_ustr_free(us1);
}
Example #2
0
//adds a substring
static int _add_substring(ALLEGRO_USTR *str, int begin_pos, int end_pos, ALLEGRO_USTR *result[], int result_len, int *count) {
    //if the count exceeds the string length, do nothing
    if (*count >= result_len) return 0;
    
    //create a substring; remove whitespace
    result[*count] = al_ustr_dup_substr(str, begin_pos, end_pos);
    al_ustr_trim_ws(result[*count]);
    
    //increment the count
    ++(*count);
    
    //success
    return 1;
}
static void print_bitmap_flags(ALLEGRO_BITMAP *bitmap)
{
   ALLEGRO_USTR *ustr = al_ustr_new("");
   if (al_get_bitmap_flags(bitmap) & ALLEGRO_VIDEO_BITMAP)
      al_ustr_append_cstr(ustr, " VIDEO");
   if (al_get_bitmap_flags(bitmap) & ALLEGRO_MEMORY_BITMAP)
      al_ustr_append_cstr(ustr, " MEMORY");
   if (al_get_bitmap_flags(bitmap) & ALLEGRO_CONVERT_BITMAP)
      al_ustr_append_cstr(ustr, " CONVERT");
   
   al_ustr_trim_ws(ustr);
   al_ustr_find_replace_cstr(ustr, 0, " ", " | ");
   
   log_printf("%s", al_cstr(ustr));
   al_ustr_free(ustr);
}
Example #4
0
/* Test whitespace trim functions. */
static void t15(void)
{
   ALLEGRO_USTR *us1 = al_ustr_new(" \f\n\r\t\vhello \f\n\r\t\v");
   ALLEGRO_USTR *us2 = al_ustr_new(" \f\n\r\t\vhello \f\n\r\t\v");

   CHECK(al_ustr_ltrim_ws(us1));
   CHECK(0 == strcmp(al_cstr(us1), "hello \f\n\r\t\v"));

   CHECK(al_ustr_rtrim_ws(us1));
   CHECK(0 == strcmp(al_cstr(us1), "hello"));

   CHECK(al_ustr_trim_ws(us2));
   CHECK(0 == strcmp(al_cstr(us2), "hello"));

   al_ustr_free(us1);
   al_ustr_free(us2);
}
Example #5
0
int _al_parse_key_binding(const char *s, unsigned int *modifiers)
{
   ALLEGRO_USTR *us;
   unsigned start = 0;
   int keycode = 0;

   us = al_ustr_new(s);
   al_ustr_trim_ws(us);
   *modifiers = 0;

   while (start < al_ustr_size(us)) {
      /* XXX not all keys can be bound due to a conflict with the delimiter
       * characters
       */
      int end = al_ustr_find_set_cstr(us, start, "+-");
      unsigned int mod;

      /* Last component must be a key. */
      if (end == -1) {
         keycode = match_key_name(al_cstr(us) + start);
         break;
      }

      /* Otherwise must be a modifier. */
      al_ustr_set_chr(us, end, '\0');
      mod = match_modifier(al_cstr(us) + start);
      if (!mod) {
         break;
      }
      (*modifiers) |= mod;
      start = end + 1;
   }

   al_ustr_free(us);

   return keycode;
}