Beispiel #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;
}
Beispiel #2
0
/* Test al_ustr_replace_range. */
static void t44(void)
{
   ALLEGRO_USTR *us1 = al_ustr_new("Šis kungs par visu samaksās");
   ALLEGRO_USTR *us2 = al_ustr_new("ī kundze");

   CHECK(al_ustr_replace_range(us1, 2, 10, us2));
   CHECK(0 == strcmp(al_cstr(us1), "Šī kundze par visu samaksās"));

   /* Insert into itself. */
   CHECK(al_ustr_replace_range(us1, 5, 11, us1));
   CHECK(0 == strcmp(al_cstr(us1),
         "Šī Šī kundze par visu samaksās par visu samaksās"));

   al_ustr_free(us1);
   al_ustr_free(us2);
}
Beispiel #3
0
/* Test al_ustr_replace_range (part 2). */
static void t45(void)
{
   ALLEGRO_USTR *us1 = al_ustr_new("abcdef");
   ALLEGRO_USTR *us2 = al_ustr_new("ABCDEF");

   /* Start1 < 0 [not allowed] */
   CHECK(! al_ustr_replace_range(us1, -1, 1, us2));

   /* Start1 > end(us1) [padded] */
   CHECK(al_ustr_replace_range(us1, 8, 100, us2));
   CHECK(0 == memcmp(al_cstr(us1), "abcdef\0\0ABCDEF", 15));

   /* Start1 > end1 [not allowed] */
   CHECK(! al_ustr_replace_range(us1, 8, 1, us2));
   CHECK(0 == memcmp(al_cstr(us1), "abcdef\0\0ABCDEF", 15));

   al_ustr_free(us1);
   al_ustr_free(us2);
}