Пример #1
0
//returns the filepath of a resource
static ALLEGRO_USTR *_get_resource_filepath(const ALLEGRO_USTR *skin_filepath, const char *resource_filename) {
    ALLEGRO_USTR *result;            
    int pos, end_pos;
    ALLEGRO_USTR *temp;
    ALLEGRO_USTR_INFO temp_info;

    //duplicate the resource filepath in order to replace '\' by '/'
    result = al_ustr_dup(skin_filepath);
    
    //replace '\' with '/'
    al_ustr_find_replace_cstr(result, 0, "\\", "/");
    
    //find the end of the string
    end_pos = al_ustr_size(result);
    
    //find the last occurrence of '/'
    pos = al_ustr_rfind_chr(result, end_pos, '/');
    
    //find the position after the '/'
    pos += al_utf8_width('/');   
    
    //the replace function needs a ustr
    temp = al_ref_cstr(&temp_info, resource_filename);
    
    //replace the string after the '/' with the resource filename
    al_ustr_replace_range(result, pos, end_pos, temp);
    
    return result;
}
Пример #2
0
/* Function: al_get_path_extension
 */
const char *al_get_path_extension(const ALLEGRO_PATH *path)
{
   int pos;
   ASSERT(path);

   pos = al_ustr_rfind_chr(path->filename, al_ustr_size(path->filename), '.');
   if (pos == -1)
      pos = al_ustr_size(path->filename);

   return al_cstr(path->filename) + pos;  /* include dot */
}
Пример #3
0
/* Function: al_get_path_basename
 */
const char *al_get_path_basename(const ALLEGRO_PATH *path)
{
   int dot;
   ASSERT(path);

   dot = al_ustr_rfind_chr(path->filename, al_ustr_size(path->filename), '.');
   if (dot >= 0) {
      al_ustr_assign_substr(path->basename, path->filename, 0, dot);
      return al_cstr(path->basename);
   }

   return al_cstr(path->filename);
}
Пример #4
0
/* Function: al_set_path_extension
 */
bool al_set_path_extension(ALLEGRO_PATH *path, char const *extension)
{
   int dot;
   ASSERT(path);

   if (al_ustr_size(path->filename) == 0) {
      return false;
   }

   dot = al_ustr_rfind_chr(path->filename, al_ustr_size(path->filename), '.');
   if (dot >= 0) {
      al_ustr_truncate(path->filename, dot);
   }
   al_ustr_append_cstr(path->filename, extension);
   return true;
}
Пример #5
0
/* Test al_ustr_rfind_chr. */
static void t32(void)
{
   ALLEGRO_USTR *us = al_ustr_new("aábdðeéfghiíaábdðeéfghií");
   int end = al_ustr_size(us);

   /* Find ASCII. */
   CHECK(al_ustr_rfind_chr(us, end, 'e') == 23);
   CHECK(al_ustr_rfind_chr(us, 23, 'e') == 7);        /* end_pos exclusive */
   CHECK(al_ustr_rfind_chr(us, end, '.') == -1);

   /* Find non-ASCII. */
   CHECK(al_ustr_rfind_chr(us, end, U_i_acute) == 30);
   CHECK(al_ustr_rfind_chr(us, end - 1, U_i_acute) == 14); /* end_pos exclusive */
   CHECK(al_ustr_rfind_chr(us, end, U_z_bar) == -1);

   al_ustr_free(us);
}