Пример #1
0
/* Test al_ustr_has_prefix, al_ustr_has_suffix. */
static void t48(void)
{
   ALLEGRO_USTR_INFO i1;
   const ALLEGRO_USTR *us1 = al_ref_cstr(&i1, "Thú mỏ vịt");

   /* The _cstr versions are simple wrappers around the real functions so its
    * okay to test them only.
    */

   CHECK(al_ustr_has_prefix_cstr(us1, ""));
   CHECK(al_ustr_has_prefix_cstr(us1, "Thú"));
   CHECK(! al_ustr_has_prefix_cstr(us1, "Thú mỏ vịt."));

   CHECK(al_ustr_has_suffix_cstr(us1, ""));
   CHECK(al_ustr_has_suffix_cstr(us1, "vịt"));
   CHECK(! al_ustr_has_suffix_cstr(us1, "Thú mỏ vịt."));
}
Пример #2
0
static ALLEGRO_USTR *create_filter_string(const ALLEGRO_USTR *patterns)
{
   ALLEGRO_USTR *filter = al_ustr_new("");
   bool filter_all = false;
   int start, end;

   if (0 == strcmp(al_cstr(patterns), "*.*")) {
      filter_all = true;
   }
   else {
      al_ustr_append_cstr(filter, "All Supported Files");
      al_ustr_append_chr(filter, '\0');
      start = al_ustr_size(filter);
      al_ustr_append(filter, patterns);

      /* Remove all instances of "*.*", which will be added separately. */
      for (;;) {
         int pos = al_ustr_find_cstr(filter, start, "*.*;");
         if (pos == -1)
            break;
         if (pos == start || al_ustr_get(filter, pos - 1) == ';') {
            filter_all = true;
            al_ustr_remove_range(filter, pos, pos + 4);
            start = pos;
         }
         else {
            start = pos + 4;
         }
      }
      while (al_ustr_has_suffix_cstr(filter, ";*.*")) {
         filter_all = true;
         end = al_ustr_size(filter);
         al_ustr_remove_range(filter, end - 4, end);
      }

      al_ustr_append_chr(filter, '\0');
   }

   if (filter_all) {
      al_ustr_append_cstr(filter, "All Files");
      al_ustr_append_chr(filter, '\0');
      al_ustr_append_cstr(filter, "*.*");
      al_ustr_append_chr(filter, '\0');
   }

   al_ustr_append_chr(filter, '\0');
   return filter;
}
Пример #3
0
/* Function: al_is_path_present
 */
bool al_is_path_present(const ALLEGRO_PATH *path)
{
   ALLEGRO_USTR *ustr;
   bool rc;
   ASSERT(path);

   ustr = al_ustr_new("");
   path_to_ustr(path, ALLEGRO_NATIVE_PATH_SEP, ustr);

   /* Windows' stat() doesn't like the slash at the end of the path when
    * the path is pointing to a directory. There are other places which
    * might require the same fix.
    */
#ifdef ALLEGRO_WINDOWS
   if (al_ustr_has_suffix_cstr(ustr, "\\")) {
      al_ustr_truncate(ustr, al_ustr_size(ustr) - 1);
   }
#endif

   rc = al_filename_exists(al_cstr(ustr));
   al_ustr_free(ustr);

   return rc;
}