mirror of
https://gitlab.gnome.org/GNOME/nautilus
synced 2024-08-25 02:36:07 +00:00
Add support for case insensitive string lists.
* libnautilus-extensions/nautilus-string-list.c: (nautilus_string_list_new), (nautilus_string_list_new_from_string), (nautilus_string_list_new_from_string_list), (nautilus_string_list_new_from_tokens), (nautilus_string_list_contains), (nautilus_string_list_equals), (nautilus_string_list_get_index_for_string), (nautilus_string_list_sort), (nautilus_string_list_remove_duplicates), (str_is_equal), (nautilus_self_check_string_list): * libnautilus-extensions/nautilus-string-list.h: Add support for case insensitive string lists. * libnautilus-extensions/nautilus-string-map.c, * libnautilus-extensions/nautilus-string-map.c: (nautilus_string_map_add), (map_entry_new), (map_entry_list_lookup_mapped_string), (str_is_equal), (nautilus_self_check_string_map): Add support for case insensitive string maps. * libnautilus-extensions/nautilus-string.c: (nautilus_istr_compare): Add missing function that apparentlt was missing and unnoticed. * libnautilus-extensions/nautilus-font-picker.c: (font_picker_update_weight_picker), (font_picker_update_slant_picker), (font_picker_update_set_width_picker): * libnautilus-extensions/nautilus-preference.c: (preference_allocate_type_info): * libnautilus-extensions/nautilus-preferences-item.c: (preferences_item_create_font_family), (preferences_item_create_theme): * libnautilus-extensions/nautilus-scalable-font.c: (parse_font_description_file), (font_family_table_add_fonts), (nautilus_scalable_font_largest_fitting_font_size), (font_family_table_get_family_list), (nautilus_scalable_font_query_font): * libnautilus-extensions/nautilus-string-picker.c: (nautilus_string_picker_initialize), (nautilus_string_picker_get_string_list), (nautilus_string_picker_insert_string): * libnautilus-extensions/nautilus-user-level-manager.c: (user_level_manager_new), (nautilus_user_level_manager_get_user_level_names): * src/file-manager/fm-directory-view.c: (real_get_emblem_names_to_exclude): * src/nautilus-application.c: (nautilus_application_check_user_directories): * test/test-nautilus-image.c: (create_font_picker_frame): * test/test-nautilus-label.c: (create_font_picker_frame): * test/test-nautilus-widgets.c: (test_string_picker): Update for case insensitive support changes in string list api.
This commit is contained in:
parent
9f5459ceea
commit
b08142cc0f
59
ChangeLog
59
ChangeLog
|
@ -1,3 +1,62 @@
|
|||
2000-08-21 Ramiro Estrugo <ramiro@eazel.com>
|
||||
|
||||
* libnautilus-extensions/nautilus-string-list.c:
|
||||
(nautilus_string_list_new), (nautilus_string_list_new_from_string),
|
||||
(nautilus_string_list_new_from_string_list),
|
||||
(nautilus_string_list_new_from_tokens),
|
||||
(nautilus_string_list_contains), (nautilus_string_list_equals),
|
||||
(nautilus_string_list_get_index_for_string),
|
||||
(nautilus_string_list_sort),
|
||||
(nautilus_string_list_remove_duplicates), (str_is_equal),
|
||||
(nautilus_self_check_string_list):
|
||||
* libnautilus-extensions/nautilus-string-list.h:
|
||||
|
||||
Add support for case insensitive string lists.
|
||||
|
||||
* libnautilus-extensions/nautilus-string-map.c,
|
||||
* libnautilus-extensions/nautilus-string-map.c:
|
||||
(nautilus_string_map_add), (map_entry_new),
|
||||
(map_entry_list_lookup_mapped_string), (str_is_equal),
|
||||
(nautilus_self_check_string_map):
|
||||
|
||||
Add support for case insensitive string maps.
|
||||
|
||||
* libnautilus-extensions/nautilus-string.c:
|
||||
(nautilus_istr_compare):
|
||||
|
||||
Add missing function that apparentlt was missing and unnoticed.
|
||||
|
||||
* libnautilus-extensions/nautilus-font-picker.c:
|
||||
(font_picker_update_weight_picker),
|
||||
(font_picker_update_slant_picker),
|
||||
(font_picker_update_set_width_picker):
|
||||
* libnautilus-extensions/nautilus-preference.c:
|
||||
(preference_allocate_type_info):
|
||||
* libnautilus-extensions/nautilus-preferences-item.c:
|
||||
(preferences_item_create_font_family),
|
||||
(preferences_item_create_theme):
|
||||
* libnautilus-extensions/nautilus-scalable-font.c:
|
||||
(parse_font_description_file), (font_family_table_add_fonts),
|
||||
(nautilus_scalable_font_largest_fitting_font_size),
|
||||
(font_family_table_get_family_list),
|
||||
(nautilus_scalable_font_query_font):
|
||||
* libnautilus-extensions/nautilus-string-picker.c:
|
||||
(nautilus_string_picker_initialize),
|
||||
(nautilus_string_picker_get_string_list),
|
||||
(nautilus_string_picker_insert_string):
|
||||
* libnautilus-extensions/nautilus-user-level-manager.c:
|
||||
(user_level_manager_new),
|
||||
(nautilus_user_level_manager_get_user_level_names):
|
||||
* src/file-manager/fm-directory-view.c:
|
||||
(real_get_emblem_names_to_exclude):
|
||||
* src/nautilus-application.c:
|
||||
(nautilus_application_check_user_directories):
|
||||
* test/test-nautilus-image.c: (create_font_picker_frame):
|
||||
* test/test-nautilus-label.c: (create_font_picker_frame):
|
||||
* test/test-nautilus-widgets.c: (test_string_picker):
|
||||
|
||||
Update for case insensitive support changes in string list api.
|
||||
|
||||
2000-08-21 Ramiro Estrugo <ramiro@eazel.com>
|
||||
|
||||
* libnautilus-extensions/nautilus-directory.c:
|
||||
|
|
|
@ -203,7 +203,7 @@ font_picker_update_weight_picker (NautilusFontPicker *font_picker)
|
|||
|
||||
family = nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->family_picker));
|
||||
|
||||
unique_weight_list = nautilus_string_list_new_from_string_list (font_picker->detail->weight_list);
|
||||
unique_weight_list = nautilus_string_list_new_from_string_list (font_picker->detail->weight_list, TRUE);
|
||||
|
||||
nautilus_string_list_sort (unique_weight_list);
|
||||
nautilus_string_list_remove_duplicates (unique_weight_list);
|
||||
|
@ -232,7 +232,7 @@ font_picker_update_slant_picker (NautilusFontPicker *font_picker)
|
|||
g_assert (nautilus_string_list_get_length (font_picker->detail->slant_list) ==
|
||||
nautilus_string_list_get_length (font_picker->detail->weight_list));
|
||||
|
||||
unique_slant_list = nautilus_string_list_new ();
|
||||
unique_slant_list = nautilus_string_list_new (TRUE);
|
||||
|
||||
for (i = 0; i < nautilus_string_list_get_length (font_picker->detail->slant_list); i++) {
|
||||
char *weight = nautilus_string_list_nth (font_picker->detail->weight_list, i);
|
||||
|
@ -279,7 +279,7 @@ font_picker_update_set_width_picker (NautilusFontPicker *font_picker)
|
|||
g_assert (nautilus_string_list_get_length (font_picker->detail->slant_list) ==
|
||||
nautilus_string_list_get_length (font_picker->detail->set_width_list));
|
||||
|
||||
unique_set_width_list = nautilus_string_list_new ();
|
||||
unique_set_width_list = nautilus_string_list_new (TRUE);
|
||||
|
||||
for (i = 0; i < nautilus_string_list_get_length (font_picker->detail->set_width_list); i++) {
|
||||
char *weight = nautilus_string_list_nth (font_picker->detail->weight_list, i);
|
||||
|
|
|
@ -249,9 +249,9 @@ preference_allocate_type_info (NautilusPreference *preference)
|
|||
|
||||
info = g_new (PreferenceEnumInfo, 1);
|
||||
|
||||
info->names = nautilus_string_list_new ();
|
||||
info->names = nautilus_string_list_new (TRUE);
|
||||
|
||||
info->descriptions = nautilus_string_list_new ();
|
||||
info->descriptions = nautilus_string_list_new (TRUE);
|
||||
|
||||
info->values = NULL;
|
||||
|
||||
|
|
|
@ -467,7 +467,7 @@ preferences_item_create_font_family (NautilusPreferencesItem *item,
|
|||
g_free (description);
|
||||
|
||||
/* FIXME bugzilla.eazel.com 1274: Need to query system for available fonts */
|
||||
font_list = nautilus_string_list_new ();
|
||||
font_list = nautilus_string_list_new (TRUE);
|
||||
|
||||
nautilus_string_list_insert (font_list, "helvetica");
|
||||
nautilus_string_list_insert (font_list, "times");
|
||||
|
@ -595,7 +595,7 @@ preferences_item_create_theme (NautilusPreferencesItem *item,
|
|||
|
||||
g_free (description);
|
||||
|
||||
theme_list = nautilus_string_list_new ();
|
||||
theme_list = nautilus_string_list_new (TRUE);
|
||||
nautilus_string_list_insert (theme_list, "default");
|
||||
add_icon_themes(theme_list, "i-directory");
|
||||
|
||||
|
|
|
@ -187,7 +187,7 @@ parse_font_description_file (const char *directory,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
tokenized_list = nautilus_string_list_new_from_tokens (fonts_dir_content, "\n");
|
||||
tokenized_list = nautilus_string_list_new_from_tokens (fonts_dir_content, "\n", TRUE);
|
||||
g_free (fonts_dir_content);
|
||||
|
||||
if (tokenized_list == NULL) {
|
||||
|
@ -203,8 +203,8 @@ parse_font_description_file (const char *directory,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
*font_pfb_list_out = nautilus_string_list_new ();
|
||||
*font_xfld_list_out = nautilus_string_list_new ();
|
||||
*font_pfb_list_out = nautilus_string_list_new (TRUE);
|
||||
*font_xfld_list_out = nautilus_string_list_new (TRUE);
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
char *line = nautilus_string_list_nth (tokenized_list, i + 1);
|
||||
|
@ -461,7 +461,7 @@ font_family_table_add_fonts (GHashTable *font_family_table, const char *font_pat
|
|||
xfld = nautilus_string_list_nth (font_xfld_list, i);
|
||||
g_assert (xfld != NULL);
|
||||
|
||||
tokenized_xfld = nautilus_string_list_new_from_tokens (xfld, "-");
|
||||
tokenized_xfld = nautilus_string_list_new_from_tokens (xfld, "-", TRUE);
|
||||
|
||||
foundry = nautilus_string_list_nth (tokenized_xfld, 1);
|
||||
family = nautilus_string_list_nth (tokenized_xfld, 2);
|
||||
|
@ -663,7 +663,7 @@ nautilus_scalable_font_largest_fitting_font_size (const NautilusScalableFont *f
|
|||
return font_sizes[num_font_sizes - 1];
|
||||
}
|
||||
|
||||
tokenized_string = nautilus_string_list_new_from_tokens (text, "\n");
|
||||
tokenized_string = nautilus_string_list_new_from_tokens (text, "\n", TRUE);
|
||||
longest_string = nautilus_string_list_get_longest_string (tokenized_string);
|
||||
g_assert (longest_string != NULL);
|
||||
nautilus_string_list_free (tokenized_string);
|
||||
|
@ -928,7 +928,7 @@ font_family_table_get_family_list (GHashTable *font_family_table)
|
|||
|
||||
g_return_val_if_fail (font_family_table != NULL, NULL);
|
||||
|
||||
list = nautilus_string_list_new ();
|
||||
list = nautilus_string_list_new (TRUE);
|
||||
|
||||
g_hash_table_foreach (font_family_table, font_family_table_for_each_append, list);
|
||||
|
||||
|
@ -996,15 +996,15 @@ nautilus_scalable_font_query_font (const char *family,
|
|||
}
|
||||
|
||||
if (weights_out != NULL) {
|
||||
*weights_out = nautilus_string_list_new ();
|
||||
*weights_out = nautilus_string_list_new (TRUE);
|
||||
}
|
||||
|
||||
if (slants_out != NULL) {
|
||||
*slants_out = nautilus_string_list_new ();
|
||||
*slants_out = nautilus_string_list_new (TRUE);
|
||||
}
|
||||
|
||||
if (set_widths_out != NULL) {
|
||||
*set_widths_out = nautilus_string_list_new ();
|
||||
*set_widths_out = nautilus_string_list_new (TRUE);
|
||||
}
|
||||
|
||||
for (iterator = family_entry->fonts; iterator != NULL; iterator = iterator->next) {
|
||||
|
|
|
@ -35,43 +35,51 @@ static gboolean supress_out_of_bounds_warning;
|
|||
|
||||
struct _NautilusStringList
|
||||
{
|
||||
GList *strings;
|
||||
GList *strings;
|
||||
GCompareFunc compare_function;
|
||||
};
|
||||
|
||||
static gboolean str_is_equal (const char *a,
|
||||
const char *b,
|
||||
gboolean case_sensitive);
|
||||
|
||||
/**
|
||||
* nautilus_string_list_new:
|
||||
*
|
||||
* Construct an empty string list.
|
||||
* @case_sensitive: Flag indicating whether the new string list is case sensitive.
|
||||
*
|
||||
* Returns the string list.
|
||||
* Return value: A newly constructed string list.
|
||||
*/
|
||||
NautilusStringList *
|
||||
nautilus_string_list_new (void)
|
||||
nautilus_string_list_new (gboolean case_sensitive)
|
||||
{
|
||||
NautilusStringList * string_list;
|
||||
|
||||
string_list = g_new (NautilusStringList, 1);
|
||||
|
||||
string_list->strings = NULL;
|
||||
string_list->compare_function = case_sensitive ? nautilus_str_compare : nautilus_istr_compare;
|
||||
|
||||
return string_list;
|
||||
}
|
||||
|
||||
/**
|
||||
* nautilus_string_list_new:
|
||||
* nautilus_string_list_new_from_string:
|
||||
*
|
||||
* Construct an empty string list.
|
||||
* @other_or_null: A NautilusStringList or NULL
|
||||
* @case_sensitive: Flag indicating whether the new string list is case sensitive.
|
||||
*
|
||||
* Returns the string list.
|
||||
* Return value: A newly constructed string list with one entry 'string'.
|
||||
*/
|
||||
NautilusStringList *
|
||||
nautilus_string_list_new_from_string (const char *string)
|
||||
nautilus_string_list_new_from_string (const char *string,
|
||||
gboolean case_sensitive)
|
||||
{
|
||||
NautilusStringList * string_list;
|
||||
|
||||
g_return_val_if_fail (string != NULL, NULL);
|
||||
|
||||
string_list = nautilus_string_list_new ();
|
||||
string_list = nautilus_string_list_new (case_sensitive);
|
||||
|
||||
nautilus_string_list_insert (string_list, string);
|
||||
|
||||
|
@ -79,14 +87,16 @@ nautilus_string_list_new_from_string (const char *string)
|
|||
}
|
||||
|
||||
/**
|
||||
* nautilus_string_list_new:
|
||||
* nautilus_string_list_new_from_string_list:
|
||||
*
|
||||
* Construct an empty string list.
|
||||
* @other_or_null: A NautilusStringList or NULL
|
||||
* @case_sensitive: Flag indicating whether the new string list is case sensitive.
|
||||
*
|
||||
* Returns the string list.
|
||||
* Return value: A newly allocated string list that is equal to other.
|
||||
*/
|
||||
NautilusStringList *
|
||||
nautilus_string_list_new_from_string_list (const NautilusStringList *other_or_null)
|
||||
nautilus_string_list_new_from_string_list (const NautilusStringList *other_or_null,
|
||||
gboolean case_sensitive)
|
||||
{
|
||||
NautilusStringList *string_list;
|
||||
|
||||
|
@ -94,7 +104,7 @@ nautilus_string_list_new_from_string_list (const NautilusStringList *other_or_nu
|
|||
return NULL;
|
||||
}
|
||||
|
||||
string_list = nautilus_string_list_new ();
|
||||
string_list = nautilus_string_list_new (case_sensitive);
|
||||
|
||||
nautilus_string_list_assign_from_string_list (string_list, other_or_null);
|
||||
|
||||
|
@ -103,14 +113,15 @@ nautilus_string_list_new_from_string_list (const NautilusStringList *other_or_nu
|
|||
|
||||
/* Construct a string list from tokens delimited by the given string and delimiter */
|
||||
NautilusStringList *
|
||||
nautilus_string_list_new_from_tokens (const char *string,
|
||||
const char *delimiter)
|
||||
nautilus_string_list_new_from_tokens (const char *string,
|
||||
const char *delimiter,
|
||||
gboolean case_sensitive)
|
||||
{
|
||||
NautilusStringList *string_list;
|
||||
|
||||
g_return_val_if_fail (delimiter != NULL, NULL);
|
||||
|
||||
string_list = nautilus_string_list_new ();
|
||||
string_list = nautilus_string_list_new (case_sensitive);
|
||||
|
||||
if (string != NULL) {
|
||||
char **string_array;
|
||||
|
@ -196,8 +207,8 @@ nautilus_string_list_nth (const NautilusStringList *string_list, guint n)
|
|||
}
|
||||
|
||||
gboolean
|
||||
nautilus_string_list_contains (const NautilusStringList *string_list,
|
||||
const char *string)
|
||||
nautilus_string_list_contains (const NautilusStringList *string_list,
|
||||
const char *string)
|
||||
{
|
||||
GList *find;
|
||||
|
||||
|
@ -207,7 +218,7 @@ nautilus_string_list_contains (const NautilusStringList *string_list,
|
|||
|
||||
g_return_val_if_fail (string != NULL, FALSE);
|
||||
|
||||
find = g_list_find_custom (string_list->strings, (gpointer) string, nautilus_str_compare);
|
||||
find = g_list_find_custom (string_list->strings, (gpointer) string, string_list->compare_function);
|
||||
|
||||
return find == NULL ? FALSE : TRUE;
|
||||
}
|
||||
|
@ -243,7 +254,7 @@ nautilus_string_list_equals (const NautilusStringList *a,
|
|||
for (a_iterator = a->strings, b_iterator = b->strings;
|
||||
a_iterator != NULL && b_iterator != NULL;
|
||||
a_iterator = a_iterator->next, b_iterator = b_iterator->next) {
|
||||
if (!nautilus_str_is_equal ((const char *) a_iterator->data, (const char *) b_iterator->data)) {
|
||||
if (!str_is_equal ((const char *) a_iterator->data, (const char *) b_iterator->data, a->compare_function == b->compare_function)) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
@ -294,7 +305,7 @@ nautilus_string_list_get_index_for_string (const NautilusStringList *string_list
|
|||
g_return_val_if_fail (string != NULL, NAUTILUS_STRING_LIST_NOT_FOUND);
|
||||
|
||||
for (iterator = string_list->strings; iterator != NULL; iterator = iterator->next) {
|
||||
if (nautilus_str_is_equal ((const char *) iterator->data, string)) {
|
||||
if (str_is_equal ((const char *) iterator->data, string, string_list->compare_function == nautilus_str_compare)) {
|
||||
return n;
|
||||
}
|
||||
|
||||
|
@ -359,7 +370,7 @@ nautilus_string_list_sort (NautilusStringList *string_list)
|
|||
{
|
||||
g_return_if_fail (string_list != NULL);
|
||||
|
||||
string_list->strings = g_list_sort (string_list->strings, nautilus_str_compare);
|
||||
string_list->strings = g_list_sort (string_list->strings, string_list->compare_function);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -374,7 +385,7 @@ nautilus_string_list_remove_duplicates (NautilusStringList *string_list)
|
|||
const char *string = (const char *) iterator->data;
|
||||
g_assert (string != NULL);
|
||||
|
||||
if (g_list_find_custom (new_strings, (gpointer) string, nautilus_str_compare) == NULL) {
|
||||
if (g_list_find_custom (new_strings, (gpointer) string, string_list->compare_function) == NULL) {
|
||||
new_strings = g_list_append (new_strings, g_strdup (string));
|
||||
}
|
||||
}
|
||||
|
@ -458,6 +469,14 @@ nautilus_string_list_get_longest_string_length (const NautilusStringList *string
|
|||
return longest_length;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
str_is_equal (const char *a,
|
||||
const char *b,
|
||||
gboolean case_sensitive)
|
||||
{
|
||||
return case_sensitive ? nautilus_str_is_equal (a, b) : nautilus_istr_is_equal (a, b);
|
||||
}
|
||||
|
||||
#if !defined (NAUTILUS_OMIT_SELF_CHECK)
|
||||
|
||||
void
|
||||
|
@ -473,37 +492,46 @@ nautilus_self_check_string_list (void)
|
|||
const char token_string[] = "london:paris:rome";
|
||||
const char token_string_thick[] = "london####paris####rome";
|
||||
|
||||
empty = nautilus_string_list_new ();
|
||||
/*
|
||||
* nautilus_string_list_contains
|
||||
*/
|
||||
empty = nautilus_string_list_new (TRUE);
|
||||
|
||||
NAUTILUS_CHECK_INTEGER_RESULT (nautilus_string_list_get_length (empty), 0);
|
||||
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_contains (empty, "something"), FALSE);
|
||||
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_contains (NULL, "something"), FALSE);
|
||||
|
||||
/********/
|
||||
|
||||
cities = nautilus_string_list_new ();
|
||||
/*
|
||||
* nautilus_string_list_new
|
||||
*/
|
||||
cities = nautilus_string_list_new (TRUE);
|
||||
|
||||
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_equals (cities, empty), TRUE);
|
||||
|
||||
|
||||
nautilus_string_list_insert (cities, "london");
|
||||
nautilus_string_list_insert (cities, "paris");
|
||||
nautilus_string_list_insert (cities, "rome");
|
||||
|
||||
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_equals (cities, empty), FALSE);
|
||||
|
||||
/********/
|
||||
|
||||
cities_copy = nautilus_string_list_new_from_string_list (cities);
|
||||
/*
|
||||
* nautilus_string_list_new_from_string_list
|
||||
*/
|
||||
cities_copy = nautilus_string_list_new_from_string_list (cities, TRUE);
|
||||
|
||||
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_equals (cities, cities_copy), TRUE);
|
||||
|
||||
nautilus_string_list_free (cities_copy);
|
||||
|
||||
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_new_from_string_list (NULL) == NULL, TRUE);
|
||||
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_new_from_string_list (NULL, TRUE) == NULL, TRUE);
|
||||
|
||||
/********/
|
||||
|
||||
fruits = nautilus_string_list_new ();
|
||||
/*
|
||||
* nautilus_string_list_insert,
|
||||
* nautilus_string_list_nth,
|
||||
* nautilus_string_list_contains,
|
||||
* nautilus_string_list_get_length
|
||||
*/
|
||||
fruits = nautilus_string_list_new (TRUE);
|
||||
|
||||
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_equals (fruits, empty), TRUE);
|
||||
|
||||
|
@ -540,24 +568,26 @@ nautilus_self_check_string_list (void)
|
|||
nautilus_string_list_free (fruits);
|
||||
nautilus_string_list_free (empty);
|
||||
|
||||
/********/
|
||||
|
||||
tokens = nautilus_string_list_new_from_tokens (token_string, ":");
|
||||
/*
|
||||
* nautilus_string_list_new_from_tokens
|
||||
*/
|
||||
tokens = nautilus_string_list_new_from_tokens (token_string, ":", TRUE);
|
||||
|
||||
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_equals (cities, tokens), TRUE);
|
||||
|
||||
nautilus_string_list_free (tokens);
|
||||
|
||||
tokens = nautilus_string_list_new_from_tokens (token_string_thick, "####");
|
||||
tokens = nautilus_string_list_new_from_tokens (token_string_thick, "####", TRUE);
|
||||
|
||||
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_equals (cities, tokens), TRUE);
|
||||
|
||||
nautilus_string_list_free (cities);
|
||||
nautilus_string_list_free (tokens);
|
||||
|
||||
/********/
|
||||
|
||||
single = nautilus_string_list_new_from_string ("something");
|
||||
/*
|
||||
* nautilus_string_list_new_from_string
|
||||
*/
|
||||
single = nautilus_string_list_new_from_string ("something", TRUE);
|
||||
|
||||
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_contains (single, "something"), TRUE);
|
||||
NAUTILUS_CHECK_INTEGER_RESULT (nautilus_string_list_get_length (single), 1);
|
||||
|
@ -574,7 +604,7 @@ nautilus_self_check_string_list (void)
|
|||
GList *glist_iterator;
|
||||
NautilusStringList *string_list;
|
||||
|
||||
string_list = nautilus_string_list_new ();
|
||||
string_list = nautilus_string_list_new (TRUE);
|
||||
|
||||
nautilus_string_list_insert (string_list, "orange");
|
||||
nautilus_string_list_insert (string_list, "apple");
|
||||
|
@ -612,7 +642,7 @@ nautilus_self_check_string_list (void)
|
|||
{
|
||||
NautilusStringList *fruits;
|
||||
|
||||
fruits = nautilus_string_list_new ();
|
||||
fruits = nautilus_string_list_new (TRUE);
|
||||
|
||||
nautilus_string_list_insert (fruits, "orange");
|
||||
nautilus_string_list_insert (fruits, "apple");
|
||||
|
@ -640,7 +670,7 @@ nautilus_self_check_string_list (void)
|
|||
{
|
||||
NautilusStringList *l;
|
||||
|
||||
l = nautilus_string_list_new ();
|
||||
l = nautilus_string_list_new (TRUE);
|
||||
|
||||
nautilus_string_list_insert (l, "x");
|
||||
|
||||
|
@ -666,7 +696,7 @@ nautilus_self_check_string_list (void)
|
|||
{
|
||||
NautilusStringList *l;
|
||||
|
||||
l = nautilus_string_list_new ();
|
||||
l = nautilus_string_list_new (TRUE);
|
||||
|
||||
nautilus_string_list_insert (l, "dog");
|
||||
nautilus_string_list_insert (l, "cat");
|
||||
|
@ -688,7 +718,7 @@ nautilus_self_check_string_list (void)
|
|||
{
|
||||
NautilusStringList *l;
|
||||
|
||||
l = nautilus_string_list_new ();
|
||||
l = nautilus_string_list_new (TRUE);
|
||||
|
||||
nautilus_string_list_remove_duplicates (l);
|
||||
NAUTILUS_CHECK_INTEGER_RESULT (nautilus_string_list_get_length (l), 0);
|
||||
|
@ -728,8 +758,8 @@ nautilus_self_check_string_list (void)
|
|||
NautilusStringList *l;
|
||||
NautilusStringList *other;
|
||||
|
||||
l = nautilus_string_list_new ();
|
||||
other = nautilus_string_list_new ();
|
||||
l = nautilus_string_list_new (TRUE);
|
||||
other = nautilus_string_list_new (TRUE);
|
||||
|
||||
/* assign an other with some items */
|
||||
nautilus_string_list_insert (other, "dog");
|
||||
|
@ -747,7 +777,7 @@ nautilus_self_check_string_list (void)
|
|||
nautilus_string_list_assign_from_string_list (l, other);
|
||||
NAUTILUS_CHECK_INTEGER_RESULT (nautilus_string_list_get_length (l), 1);
|
||||
NAUTILUS_CHECK_STRING_RESULT (nautilus_string_list_nth (l, 0), "something");
|
||||
|
||||
|
||||
/* assign an empty other */
|
||||
nautilus_string_list_clear (other);
|
||||
nautilus_string_list_assign_from_string_list (l, other);
|
||||
|
@ -765,7 +795,7 @@ nautilus_self_check_string_list (void)
|
|||
{
|
||||
NautilusStringList *l;
|
||||
|
||||
l = nautilus_string_list_new ();
|
||||
l = nautilus_string_list_new (TRUE);
|
||||
|
||||
NAUTILUS_CHECK_STRING_RESULT (nautilus_string_list_get_longest_string (l), NULL);
|
||||
NAUTILUS_CHECK_INTEGER_RESULT (nautilus_string_list_get_longest_string_length (l), 0);
|
||||
|
@ -787,6 +817,35 @@ nautilus_self_check_string_list (void)
|
|||
nautilus_string_list_free (l);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* case insensitive tests
|
||||
*
|
||||
*/
|
||||
{
|
||||
NautilusStringList *l;
|
||||
|
||||
l = nautilus_string_list_new (FALSE);
|
||||
|
||||
nautilus_string_list_insert (l, "foo");
|
||||
nautilus_string_list_insert (l, "bar");
|
||||
|
||||
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_contains (l, "Foo"), TRUE);
|
||||
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_contains (l, "foO"), TRUE);
|
||||
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_contains (l, "fOo"), TRUE);
|
||||
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_contains (l, "foo"), TRUE);
|
||||
|
||||
nautilus_string_list_clear (l);
|
||||
|
||||
nautilus_string_list_insert (l, "Foo");
|
||||
nautilus_string_list_insert (l, "Foo");
|
||||
nautilus_string_list_insert (l, "fOo");
|
||||
nautilus_string_list_insert (l, "foO");
|
||||
nautilus_string_list_remove_duplicates (l);
|
||||
NAUTILUS_CHECK_INTEGER_RESULT (nautilus_string_list_get_length (l), 1);
|
||||
|
||||
nautilus_string_list_free (l);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* !NAUTILUS_OMIT_SELF_CHECK */
|
||||
|
|
|
@ -33,19 +33,22 @@
|
|||
typedef struct _NautilusStringList NautilusStringList;
|
||||
|
||||
/* Construct an empty string list. */
|
||||
NautilusStringList *nautilus_string_list_new (void);
|
||||
NautilusStringList *nautilus_string_list_new (gboolean case_sensitive);
|
||||
|
||||
|
||||
/* Construct a string list with a single element */
|
||||
NautilusStringList *nautilus_string_list_new_from_string (const char *string);
|
||||
NautilusStringList *nautilus_string_list_new_from_string (const char *string,
|
||||
gboolean case_sensitive);
|
||||
|
||||
|
||||
/* Construct a string list that is a copy of another string list */
|
||||
NautilusStringList *nautilus_string_list_new_from_string_list (const NautilusStringList *other_or_null);
|
||||
NautilusStringList *nautilus_string_list_new_from_string_list (const NautilusStringList *other_or_null,
|
||||
gboolean case_sensitive);
|
||||
|
||||
/* Construct a string list from tokens delimited by the given string and delimeter */
|
||||
NautilusStringList *nautilus_string_list_new_from_tokens (const char *string,
|
||||
const char *delimiter);
|
||||
const char *delimiter,
|
||||
gboolean case_sensitive);
|
||||
|
||||
/* Assign the contents another string list. The other string list can be null. */
|
||||
void nautilus_string_list_assign_from_string_list (NautilusStringList *string_list,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
|
||||
|
||||
nautilus-string-list.h: A collection of strings.
|
||||
nautilus-string-map.c: A many-to-one string mapping data structure.
|
||||
|
||||
Copyright (C) 1999, 2000 Eazel, Inc.
|
||||
|
||||
|
@ -48,12 +48,17 @@ typedef struct
|
|||
} MapEntry;
|
||||
|
||||
/* MapEntry things */
|
||||
static MapEntry *map_entry_new (const char *string);
|
||||
static MapEntry *map_entry_new (const char *string,
|
||||
gboolean case_sensitive);
|
||||
static void map_entry_free (MapEntry *map_entry);
|
||||
static MapEntry *map_entry_list_lookup_mapped_string (GList *entry_list,
|
||||
const char *mapped_string);
|
||||
const char *mapped_string,
|
||||
gboolean case_sensitive);
|
||||
static MapEntry *map_entry_list_lookup (GList *entry_list,
|
||||
const char *string);
|
||||
static gboolean str_is_equal (const char *a,
|
||||
const char *b,
|
||||
gboolean case_sensitive);
|
||||
|
||||
/**
|
||||
* nautilus_string_map_new:
|
||||
|
@ -170,10 +175,10 @@ nautilus_string_map_add (NautilusStringMap *string_map,
|
|||
g_return_if_fail (string_maps_to != NULL);
|
||||
g_return_if_fail (string != NULL);
|
||||
|
||||
map_entry = map_entry_list_lookup_mapped_string (string_map->map, string_maps_to);
|
||||
map_entry = map_entry_list_lookup_mapped_string (string_map->map, string_maps_to, string_map->case_sensitive);
|
||||
|
||||
if (map_entry == NULL) {
|
||||
map_entry = map_entry_new (string_maps_to);
|
||||
map_entry = map_entry_new (string_maps_to, string_map->case_sensitive);
|
||||
|
||||
/* Add a mapping for the string_maps_to to simplify things */
|
||||
nautilus_string_list_insert (map_entry->map_list, string_maps_to);
|
||||
|
@ -186,14 +191,15 @@ nautilus_string_map_add (NautilusStringMap *string_map,
|
|||
|
||||
/* MapEntry things */
|
||||
static MapEntry *
|
||||
map_entry_new (const char *string)
|
||||
map_entry_new (const char *string,
|
||||
gboolean case_sensitive)
|
||||
{
|
||||
MapEntry *map_entry;
|
||||
|
||||
g_return_val_if_fail (string != NULL, NULL);
|
||||
|
||||
map_entry = g_new (MapEntry, 1);
|
||||
map_entry->map_list = nautilus_string_list_new ();
|
||||
map_entry->map_list = nautilus_string_list_new (case_sensitive);
|
||||
map_entry->string = g_strdup (string);
|
||||
|
||||
return map_entry;
|
||||
|
@ -212,7 +218,8 @@ map_entry_free (MapEntry *map_entry)
|
|||
|
||||
static MapEntry *
|
||||
map_entry_list_lookup_mapped_string (GList *entry_list,
|
||||
const char *mapped_string)
|
||||
const char *mapped_string,
|
||||
gboolean case_sensitive)
|
||||
{
|
||||
GList *iterator;
|
||||
|
||||
|
@ -226,7 +233,7 @@ map_entry_list_lookup_mapped_string (GList *entry_list,
|
|||
MapEntry *map_entry = (MapEntry *) iterator->data;
|
||||
g_assert (map_entry != NULL);
|
||||
|
||||
if (nautilus_str_is_equal (map_entry->string, mapped_string)) {
|
||||
if (str_is_equal (map_entry->string, mapped_string, case_sensitive)) {
|
||||
return map_entry;
|
||||
}
|
||||
}
|
||||
|
@ -258,12 +265,19 @@ map_entry_list_lookup (GList *entry_list,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
str_is_equal (const char *a,
|
||||
const char *b,
|
||||
gboolean case_sensitive)
|
||||
{
|
||||
return case_sensitive ? nautilus_str_is_equal (a, b) : nautilus_istr_is_equal (a, b);
|
||||
}
|
||||
|
||||
#if !defined (NAUTILUS_OMIT_SELF_CHECK)
|
||||
|
||||
void
|
||||
nautilus_self_check_string_map (void)
|
||||
{
|
||||
#if 0
|
||||
NautilusStringMap *map;
|
||||
|
||||
map = nautilus_string_map_new (TRUE);
|
||||
|
@ -288,8 +302,33 @@ nautilus_self_check_string_map (void)
|
|||
NAUTILUS_CHECK_STRING_RESULT (nautilus_string_map_lookup (map, "nerd"), "human");
|
||||
NAUTILUS_CHECK_STRING_RESULT (nautilus_string_map_lookup (map, "lozer"), "human");
|
||||
|
||||
NAUTILUS_CHECK_STRING_RESULT (nautilus_string_map_lookup (map, "Lozer"), NULL);
|
||||
NAUTILUS_CHECK_STRING_RESULT (nautilus_string_map_lookup (map, "HuMaN"), NULL);
|
||||
|
||||
nautilus_string_map_free (map);
|
||||
|
||||
/*
|
||||
* case insensitive tests
|
||||
*
|
||||
*/
|
||||
map = nautilus_string_map_new (FALSE);
|
||||
|
||||
NAUTILUS_CHECK_STRING_RESULT (nautilus_string_map_lookup (map, "foo"), NULL);
|
||||
|
||||
nautilus_string_map_clear (map);
|
||||
|
||||
nautilus_string_map_add (map, "animal", "dog");
|
||||
nautilus_string_map_add (map, "animal", "cat");
|
||||
nautilus_string_map_add (map, "animal", "mouse");
|
||||
|
||||
NAUTILUS_CHECK_STRING_RESULT (nautilus_string_map_lookup (map, "animal"), "animal");
|
||||
NAUTILUS_CHECK_STRING_RESULT (nautilus_string_map_lookup (map, "Animal"), "animal");
|
||||
NAUTILUS_CHECK_STRING_RESULT (nautilus_string_map_lookup (map, "cat"), "animal");
|
||||
NAUTILUS_CHECK_STRING_RESULT (nautilus_string_map_lookup (map, "CAT"), "animal");
|
||||
NAUTILUS_CHECK_STRING_RESULT (nautilus_string_map_lookup (map, "dog"), "animal");
|
||||
NAUTILUS_CHECK_STRING_RESULT (nautilus_string_map_lookup (map, "DoG"), "animal");
|
||||
|
||||
nautilus_string_map_free (map);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* !NAUTILUS_OMIT_SELF_CHECK */
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
|
||||
|
||||
nautilus-string-list.h: A collection of strings.
|
||||
nautilus-string-map.h: A many-to-one string mapping data structure.
|
||||
|
||||
Copyright (C) 1999, 2000 Eazel, Inc.
|
||||
|
||||
|
@ -22,6 +22,20 @@
|
|||
Author: Ramiro Estrugo <ramiro@eazel.com>
|
||||
*/
|
||||
|
||||
/* NautilusStringMap is a simple data structure to manage many-to-one
|
||||
* mappings of string. For example:
|
||||
*
|
||||
* map = map_new (TRUE);
|
||||
* map_add (map, "animal", "dog");
|
||||
* map_add (map, "animal", "cat");
|
||||
* map_add (map, "animal", "mouse");
|
||||
*
|
||||
* map_lookup (map, "dog") => "animal"
|
||||
* map_lookup (map, "cat") => "animal"
|
||||
* map_lookup (map, "animal") => "animal"
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef NAUTILUS_STRING_MAP_H
|
||||
#define NAUTILUS_STRING_MAP_H
|
||||
|
||||
|
@ -30,17 +44,26 @@
|
|||
/* Opaque type declaration. */
|
||||
typedef struct _NautilusStringMap NautilusStringMap;
|
||||
|
||||
/* Construct an empty string list. */
|
||||
/* Construct an empty string map. */
|
||||
NautilusStringMap *nautilus_string_map_new (gboolean case_sensitive);
|
||||
|
||||
/* Construct a string list with a single element */
|
||||
/* Add a mapping from 'string' to 'strings_maps_to' */
|
||||
void nautilus_string_map_add (NautilusStringMap *string_map,
|
||||
const char *string_maps_to,
|
||||
const char *string);
|
||||
|
||||
/* Free the string map */
|
||||
void nautilus_string_map_free (NautilusStringMap *string_map);
|
||||
|
||||
|
||||
/* Clear the string map */
|
||||
void nautilus_string_map_clear (NautilusStringMap *string_map);
|
||||
|
||||
|
||||
/* Lookup the string in the map. Returns the string 'string' maps to or NULL of not found. */
|
||||
char * nautilus_string_map_lookup (const NautilusStringMap *string_map,
|
||||
const char *key);
|
||||
const char *string);
|
||||
|
||||
|
||||
#endif /* NAUTILUS_STRING_MAP_H */
|
||||
|
||||
|
|
|
@ -103,7 +103,7 @@ nautilus_string_picker_initialize (NautilusStringPicker *string_picker)
|
|||
gtk_box_set_homogeneous (GTK_BOX (string_picker), FALSE);
|
||||
gtk_box_set_spacing (GTK_BOX (string_picker), STRING_PICKER_SPACING);
|
||||
|
||||
string_picker->detail->string_list = nautilus_string_list_new ();
|
||||
string_picker->detail->string_list = nautilus_string_list_new (TRUE);
|
||||
string_picker->detail->menu = NULL;
|
||||
|
||||
string_picker->detail->option_menu = gtk_option_menu_new ();
|
||||
|
@ -243,7 +243,7 @@ nautilus_string_picker_get_string_list (const NautilusStringPicker *string_picke
|
|||
g_return_val_if_fail (string_picker != NULL, NULL);
|
||||
g_return_val_if_fail (NAUTILUS_IS_STRING_PICKER (string_picker), NULL);
|
||||
|
||||
return nautilus_string_list_new_from_string_list (string_picker->detail->string_list);
|
||||
return nautilus_string_list_new_from_string_list (string_picker->detail->string_list, TRUE);
|
||||
}
|
||||
|
||||
/* FIXME bugzilla.eazel.com 1556:
|
||||
|
@ -311,7 +311,7 @@ nautilus_string_picker_insert_string (NautilusStringPicker *string_picker,
|
|||
|
||||
g_return_if_fail (NAUTILUS_IS_STRING_PICKER (string_picker));
|
||||
|
||||
new_string_list = nautilus_string_list_new_from_string_list (string_picker->detail->string_list);
|
||||
new_string_list = nautilus_string_list_new_from_string_list (string_picker->detail->string_list, TRUE);
|
||||
nautilus_string_list_insert (new_string_list, string);
|
||||
nautilus_string_picker_set_string_list (string_picker, new_string_list);
|
||||
nautilus_string_list_free (new_string_list);
|
||||
|
|
|
@ -82,6 +82,13 @@ nautilus_str_compare (gconstpointer string_a, gconstpointer string_b)
|
|||
(const char *) string_b);
|
||||
}
|
||||
|
||||
int
|
||||
nautilus_istr_compare (gconstpointer string_a, gconstpointer string_b)
|
||||
{
|
||||
return nautilus_strcasecmp ((const char *) string_a,
|
||||
(const char *) string_b);
|
||||
}
|
||||
|
||||
gboolean
|
||||
nautilus_str_has_prefix (const char *haystack, const char *needle)
|
||||
{
|
||||
|
|
|
@ -137,7 +137,7 @@ user_level_manager_new (void)
|
|||
NULL);
|
||||
|
||||
manager->num_user_levels = DEFAULT_NUM_USER_LEVELS;
|
||||
manager->user_level_names = nautilus_string_list_new ();
|
||||
manager->user_level_names = nautilus_string_list_new (TRUE);
|
||||
|
||||
for (i = 0; i < DEFAULT_NUM_USER_LEVELS; i++) {
|
||||
nautilus_string_list_insert (manager->user_level_names, DEFAULT_USER_LEVEL_NAMES[i]);
|
||||
|
@ -345,7 +345,7 @@ nautilus_user_level_manager_get_user_level_names (void)
|
|||
{
|
||||
NautilusUserLevelManager *manager = nautilus_user_level_manager_get ();
|
||||
|
||||
return nautilus_string_list_new_from_string_list (manager->user_level_names);
|
||||
return nautilus_string_list_new_from_string_list (manager->user_level_names, TRUE);
|
||||
}
|
||||
|
||||
char *
|
||||
|
|
|
@ -203,7 +203,7 @@ font_picker_update_weight_picker (NautilusFontPicker *font_picker)
|
|||
|
||||
family = nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->family_picker));
|
||||
|
||||
unique_weight_list = nautilus_string_list_new_from_string_list (font_picker->detail->weight_list);
|
||||
unique_weight_list = nautilus_string_list_new_from_string_list (font_picker->detail->weight_list, TRUE);
|
||||
|
||||
nautilus_string_list_sort (unique_weight_list);
|
||||
nautilus_string_list_remove_duplicates (unique_weight_list);
|
||||
|
@ -232,7 +232,7 @@ font_picker_update_slant_picker (NautilusFontPicker *font_picker)
|
|||
g_assert (nautilus_string_list_get_length (font_picker->detail->slant_list) ==
|
||||
nautilus_string_list_get_length (font_picker->detail->weight_list));
|
||||
|
||||
unique_slant_list = nautilus_string_list_new ();
|
||||
unique_slant_list = nautilus_string_list_new (TRUE);
|
||||
|
||||
for (i = 0; i < nautilus_string_list_get_length (font_picker->detail->slant_list); i++) {
|
||||
char *weight = nautilus_string_list_nth (font_picker->detail->weight_list, i);
|
||||
|
@ -279,7 +279,7 @@ font_picker_update_set_width_picker (NautilusFontPicker *font_picker)
|
|||
g_assert (nautilus_string_list_get_length (font_picker->detail->slant_list) ==
|
||||
nautilus_string_list_get_length (font_picker->detail->set_width_list));
|
||||
|
||||
unique_set_width_list = nautilus_string_list_new ();
|
||||
unique_set_width_list = nautilus_string_list_new (TRUE);
|
||||
|
||||
for (i = 0; i < nautilus_string_list_get_length (font_picker->detail->set_width_list); i++) {
|
||||
char *weight = nautilus_string_list_nth (font_picker->detail->weight_list, i);
|
||||
|
|
|
@ -249,9 +249,9 @@ preference_allocate_type_info (NautilusPreference *preference)
|
|||
|
||||
info = g_new (PreferenceEnumInfo, 1);
|
||||
|
||||
info->names = nautilus_string_list_new ();
|
||||
info->names = nautilus_string_list_new (TRUE);
|
||||
|
||||
info->descriptions = nautilus_string_list_new ();
|
||||
info->descriptions = nautilus_string_list_new (TRUE);
|
||||
|
||||
info->values = NULL;
|
||||
|
||||
|
|
|
@ -467,7 +467,7 @@ preferences_item_create_font_family (NautilusPreferencesItem *item,
|
|||
g_free (description);
|
||||
|
||||
/* FIXME bugzilla.eazel.com 1274: Need to query system for available fonts */
|
||||
font_list = nautilus_string_list_new ();
|
||||
font_list = nautilus_string_list_new (TRUE);
|
||||
|
||||
nautilus_string_list_insert (font_list, "helvetica");
|
||||
nautilus_string_list_insert (font_list, "times");
|
||||
|
@ -595,7 +595,7 @@ preferences_item_create_theme (NautilusPreferencesItem *item,
|
|||
|
||||
g_free (description);
|
||||
|
||||
theme_list = nautilus_string_list_new ();
|
||||
theme_list = nautilus_string_list_new (TRUE);
|
||||
nautilus_string_list_insert (theme_list, "default");
|
||||
add_icon_themes(theme_list, "i-directory");
|
||||
|
||||
|
|
|
@ -187,7 +187,7 @@ parse_font_description_file (const char *directory,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
tokenized_list = nautilus_string_list_new_from_tokens (fonts_dir_content, "\n");
|
||||
tokenized_list = nautilus_string_list_new_from_tokens (fonts_dir_content, "\n", TRUE);
|
||||
g_free (fonts_dir_content);
|
||||
|
||||
if (tokenized_list == NULL) {
|
||||
|
@ -203,8 +203,8 @@ parse_font_description_file (const char *directory,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
*font_pfb_list_out = nautilus_string_list_new ();
|
||||
*font_xfld_list_out = nautilus_string_list_new ();
|
||||
*font_pfb_list_out = nautilus_string_list_new (TRUE);
|
||||
*font_xfld_list_out = nautilus_string_list_new (TRUE);
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
char *line = nautilus_string_list_nth (tokenized_list, i + 1);
|
||||
|
@ -461,7 +461,7 @@ font_family_table_add_fonts (GHashTable *font_family_table, const char *font_pat
|
|||
xfld = nautilus_string_list_nth (font_xfld_list, i);
|
||||
g_assert (xfld != NULL);
|
||||
|
||||
tokenized_xfld = nautilus_string_list_new_from_tokens (xfld, "-");
|
||||
tokenized_xfld = nautilus_string_list_new_from_tokens (xfld, "-", TRUE);
|
||||
|
||||
foundry = nautilus_string_list_nth (tokenized_xfld, 1);
|
||||
family = nautilus_string_list_nth (tokenized_xfld, 2);
|
||||
|
@ -663,7 +663,7 @@ nautilus_scalable_font_largest_fitting_font_size (const NautilusScalableFont *f
|
|||
return font_sizes[num_font_sizes - 1];
|
||||
}
|
||||
|
||||
tokenized_string = nautilus_string_list_new_from_tokens (text, "\n");
|
||||
tokenized_string = nautilus_string_list_new_from_tokens (text, "\n", TRUE);
|
||||
longest_string = nautilus_string_list_get_longest_string (tokenized_string);
|
||||
g_assert (longest_string != NULL);
|
||||
nautilus_string_list_free (tokenized_string);
|
||||
|
@ -928,7 +928,7 @@ font_family_table_get_family_list (GHashTable *font_family_table)
|
|||
|
||||
g_return_val_if_fail (font_family_table != NULL, NULL);
|
||||
|
||||
list = nautilus_string_list_new ();
|
||||
list = nautilus_string_list_new (TRUE);
|
||||
|
||||
g_hash_table_foreach (font_family_table, font_family_table_for_each_append, list);
|
||||
|
||||
|
@ -996,15 +996,15 @@ nautilus_scalable_font_query_font (const char *family,
|
|||
}
|
||||
|
||||
if (weights_out != NULL) {
|
||||
*weights_out = nautilus_string_list_new ();
|
||||
*weights_out = nautilus_string_list_new (TRUE);
|
||||
}
|
||||
|
||||
if (slants_out != NULL) {
|
||||
*slants_out = nautilus_string_list_new ();
|
||||
*slants_out = nautilus_string_list_new (TRUE);
|
||||
}
|
||||
|
||||
if (set_widths_out != NULL) {
|
||||
*set_widths_out = nautilus_string_list_new ();
|
||||
*set_widths_out = nautilus_string_list_new (TRUE);
|
||||
}
|
||||
|
||||
for (iterator = family_entry->fonts; iterator != NULL; iterator = iterator->next) {
|
||||
|
|
|
@ -35,43 +35,51 @@ static gboolean supress_out_of_bounds_warning;
|
|||
|
||||
struct _NautilusStringList
|
||||
{
|
||||
GList *strings;
|
||||
GList *strings;
|
||||
GCompareFunc compare_function;
|
||||
};
|
||||
|
||||
static gboolean str_is_equal (const char *a,
|
||||
const char *b,
|
||||
gboolean case_sensitive);
|
||||
|
||||
/**
|
||||
* nautilus_string_list_new:
|
||||
*
|
||||
* Construct an empty string list.
|
||||
* @case_sensitive: Flag indicating whether the new string list is case sensitive.
|
||||
*
|
||||
* Returns the string list.
|
||||
* Return value: A newly constructed string list.
|
||||
*/
|
||||
NautilusStringList *
|
||||
nautilus_string_list_new (void)
|
||||
nautilus_string_list_new (gboolean case_sensitive)
|
||||
{
|
||||
NautilusStringList * string_list;
|
||||
|
||||
string_list = g_new (NautilusStringList, 1);
|
||||
|
||||
string_list->strings = NULL;
|
||||
string_list->compare_function = case_sensitive ? nautilus_str_compare : nautilus_istr_compare;
|
||||
|
||||
return string_list;
|
||||
}
|
||||
|
||||
/**
|
||||
* nautilus_string_list_new:
|
||||
* nautilus_string_list_new_from_string:
|
||||
*
|
||||
* Construct an empty string list.
|
||||
* @other_or_null: A NautilusStringList or NULL
|
||||
* @case_sensitive: Flag indicating whether the new string list is case sensitive.
|
||||
*
|
||||
* Returns the string list.
|
||||
* Return value: A newly constructed string list with one entry 'string'.
|
||||
*/
|
||||
NautilusStringList *
|
||||
nautilus_string_list_new_from_string (const char *string)
|
||||
nautilus_string_list_new_from_string (const char *string,
|
||||
gboolean case_sensitive)
|
||||
{
|
||||
NautilusStringList * string_list;
|
||||
|
||||
g_return_val_if_fail (string != NULL, NULL);
|
||||
|
||||
string_list = nautilus_string_list_new ();
|
||||
string_list = nautilus_string_list_new (case_sensitive);
|
||||
|
||||
nautilus_string_list_insert (string_list, string);
|
||||
|
||||
|
@ -79,14 +87,16 @@ nautilus_string_list_new_from_string (const char *string)
|
|||
}
|
||||
|
||||
/**
|
||||
* nautilus_string_list_new:
|
||||
* nautilus_string_list_new_from_string_list:
|
||||
*
|
||||
* Construct an empty string list.
|
||||
* @other_or_null: A NautilusStringList or NULL
|
||||
* @case_sensitive: Flag indicating whether the new string list is case sensitive.
|
||||
*
|
||||
* Returns the string list.
|
||||
* Return value: A newly allocated string list that is equal to other.
|
||||
*/
|
||||
NautilusStringList *
|
||||
nautilus_string_list_new_from_string_list (const NautilusStringList *other_or_null)
|
||||
nautilus_string_list_new_from_string_list (const NautilusStringList *other_or_null,
|
||||
gboolean case_sensitive)
|
||||
{
|
||||
NautilusStringList *string_list;
|
||||
|
||||
|
@ -94,7 +104,7 @@ nautilus_string_list_new_from_string_list (const NautilusStringList *other_or_nu
|
|||
return NULL;
|
||||
}
|
||||
|
||||
string_list = nautilus_string_list_new ();
|
||||
string_list = nautilus_string_list_new (case_sensitive);
|
||||
|
||||
nautilus_string_list_assign_from_string_list (string_list, other_or_null);
|
||||
|
||||
|
@ -103,14 +113,15 @@ nautilus_string_list_new_from_string_list (const NautilusStringList *other_or_nu
|
|||
|
||||
/* Construct a string list from tokens delimited by the given string and delimiter */
|
||||
NautilusStringList *
|
||||
nautilus_string_list_new_from_tokens (const char *string,
|
||||
const char *delimiter)
|
||||
nautilus_string_list_new_from_tokens (const char *string,
|
||||
const char *delimiter,
|
||||
gboolean case_sensitive)
|
||||
{
|
||||
NautilusStringList *string_list;
|
||||
|
||||
g_return_val_if_fail (delimiter != NULL, NULL);
|
||||
|
||||
string_list = nautilus_string_list_new ();
|
||||
string_list = nautilus_string_list_new (case_sensitive);
|
||||
|
||||
if (string != NULL) {
|
||||
char **string_array;
|
||||
|
@ -196,8 +207,8 @@ nautilus_string_list_nth (const NautilusStringList *string_list, guint n)
|
|||
}
|
||||
|
||||
gboolean
|
||||
nautilus_string_list_contains (const NautilusStringList *string_list,
|
||||
const char *string)
|
||||
nautilus_string_list_contains (const NautilusStringList *string_list,
|
||||
const char *string)
|
||||
{
|
||||
GList *find;
|
||||
|
||||
|
@ -207,7 +218,7 @@ nautilus_string_list_contains (const NautilusStringList *string_list,
|
|||
|
||||
g_return_val_if_fail (string != NULL, FALSE);
|
||||
|
||||
find = g_list_find_custom (string_list->strings, (gpointer) string, nautilus_str_compare);
|
||||
find = g_list_find_custom (string_list->strings, (gpointer) string, string_list->compare_function);
|
||||
|
||||
return find == NULL ? FALSE : TRUE;
|
||||
}
|
||||
|
@ -243,7 +254,7 @@ nautilus_string_list_equals (const NautilusStringList *a,
|
|||
for (a_iterator = a->strings, b_iterator = b->strings;
|
||||
a_iterator != NULL && b_iterator != NULL;
|
||||
a_iterator = a_iterator->next, b_iterator = b_iterator->next) {
|
||||
if (!nautilus_str_is_equal ((const char *) a_iterator->data, (const char *) b_iterator->data)) {
|
||||
if (!str_is_equal ((const char *) a_iterator->data, (const char *) b_iterator->data, a->compare_function == b->compare_function)) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
@ -294,7 +305,7 @@ nautilus_string_list_get_index_for_string (const NautilusStringList *string_list
|
|||
g_return_val_if_fail (string != NULL, NAUTILUS_STRING_LIST_NOT_FOUND);
|
||||
|
||||
for (iterator = string_list->strings; iterator != NULL; iterator = iterator->next) {
|
||||
if (nautilus_str_is_equal ((const char *) iterator->data, string)) {
|
||||
if (str_is_equal ((const char *) iterator->data, string, string_list->compare_function == nautilus_str_compare)) {
|
||||
return n;
|
||||
}
|
||||
|
||||
|
@ -359,7 +370,7 @@ nautilus_string_list_sort (NautilusStringList *string_list)
|
|||
{
|
||||
g_return_if_fail (string_list != NULL);
|
||||
|
||||
string_list->strings = g_list_sort (string_list->strings, nautilus_str_compare);
|
||||
string_list->strings = g_list_sort (string_list->strings, string_list->compare_function);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -374,7 +385,7 @@ nautilus_string_list_remove_duplicates (NautilusStringList *string_list)
|
|||
const char *string = (const char *) iterator->data;
|
||||
g_assert (string != NULL);
|
||||
|
||||
if (g_list_find_custom (new_strings, (gpointer) string, nautilus_str_compare) == NULL) {
|
||||
if (g_list_find_custom (new_strings, (gpointer) string, string_list->compare_function) == NULL) {
|
||||
new_strings = g_list_append (new_strings, g_strdup (string));
|
||||
}
|
||||
}
|
||||
|
@ -458,6 +469,14 @@ nautilus_string_list_get_longest_string_length (const NautilusStringList *string
|
|||
return longest_length;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
str_is_equal (const char *a,
|
||||
const char *b,
|
||||
gboolean case_sensitive)
|
||||
{
|
||||
return case_sensitive ? nautilus_str_is_equal (a, b) : nautilus_istr_is_equal (a, b);
|
||||
}
|
||||
|
||||
#if !defined (NAUTILUS_OMIT_SELF_CHECK)
|
||||
|
||||
void
|
||||
|
@ -473,37 +492,46 @@ nautilus_self_check_string_list (void)
|
|||
const char token_string[] = "london:paris:rome";
|
||||
const char token_string_thick[] = "london####paris####rome";
|
||||
|
||||
empty = nautilus_string_list_new ();
|
||||
/*
|
||||
* nautilus_string_list_contains
|
||||
*/
|
||||
empty = nautilus_string_list_new (TRUE);
|
||||
|
||||
NAUTILUS_CHECK_INTEGER_RESULT (nautilus_string_list_get_length (empty), 0);
|
||||
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_contains (empty, "something"), FALSE);
|
||||
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_contains (NULL, "something"), FALSE);
|
||||
|
||||
/********/
|
||||
|
||||
cities = nautilus_string_list_new ();
|
||||
/*
|
||||
* nautilus_string_list_new
|
||||
*/
|
||||
cities = nautilus_string_list_new (TRUE);
|
||||
|
||||
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_equals (cities, empty), TRUE);
|
||||
|
||||
|
||||
nautilus_string_list_insert (cities, "london");
|
||||
nautilus_string_list_insert (cities, "paris");
|
||||
nautilus_string_list_insert (cities, "rome");
|
||||
|
||||
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_equals (cities, empty), FALSE);
|
||||
|
||||
/********/
|
||||
|
||||
cities_copy = nautilus_string_list_new_from_string_list (cities);
|
||||
/*
|
||||
* nautilus_string_list_new_from_string_list
|
||||
*/
|
||||
cities_copy = nautilus_string_list_new_from_string_list (cities, TRUE);
|
||||
|
||||
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_equals (cities, cities_copy), TRUE);
|
||||
|
||||
nautilus_string_list_free (cities_copy);
|
||||
|
||||
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_new_from_string_list (NULL) == NULL, TRUE);
|
||||
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_new_from_string_list (NULL, TRUE) == NULL, TRUE);
|
||||
|
||||
/********/
|
||||
|
||||
fruits = nautilus_string_list_new ();
|
||||
/*
|
||||
* nautilus_string_list_insert,
|
||||
* nautilus_string_list_nth,
|
||||
* nautilus_string_list_contains,
|
||||
* nautilus_string_list_get_length
|
||||
*/
|
||||
fruits = nautilus_string_list_new (TRUE);
|
||||
|
||||
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_equals (fruits, empty), TRUE);
|
||||
|
||||
|
@ -540,24 +568,26 @@ nautilus_self_check_string_list (void)
|
|||
nautilus_string_list_free (fruits);
|
||||
nautilus_string_list_free (empty);
|
||||
|
||||
/********/
|
||||
|
||||
tokens = nautilus_string_list_new_from_tokens (token_string, ":");
|
||||
/*
|
||||
* nautilus_string_list_new_from_tokens
|
||||
*/
|
||||
tokens = nautilus_string_list_new_from_tokens (token_string, ":", TRUE);
|
||||
|
||||
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_equals (cities, tokens), TRUE);
|
||||
|
||||
nautilus_string_list_free (tokens);
|
||||
|
||||
tokens = nautilus_string_list_new_from_tokens (token_string_thick, "####");
|
||||
tokens = nautilus_string_list_new_from_tokens (token_string_thick, "####", TRUE);
|
||||
|
||||
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_equals (cities, tokens), TRUE);
|
||||
|
||||
nautilus_string_list_free (cities);
|
||||
nautilus_string_list_free (tokens);
|
||||
|
||||
/********/
|
||||
|
||||
single = nautilus_string_list_new_from_string ("something");
|
||||
/*
|
||||
* nautilus_string_list_new_from_string
|
||||
*/
|
||||
single = nautilus_string_list_new_from_string ("something", TRUE);
|
||||
|
||||
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_contains (single, "something"), TRUE);
|
||||
NAUTILUS_CHECK_INTEGER_RESULT (nautilus_string_list_get_length (single), 1);
|
||||
|
@ -574,7 +604,7 @@ nautilus_self_check_string_list (void)
|
|||
GList *glist_iterator;
|
||||
NautilusStringList *string_list;
|
||||
|
||||
string_list = nautilus_string_list_new ();
|
||||
string_list = nautilus_string_list_new (TRUE);
|
||||
|
||||
nautilus_string_list_insert (string_list, "orange");
|
||||
nautilus_string_list_insert (string_list, "apple");
|
||||
|
@ -612,7 +642,7 @@ nautilus_self_check_string_list (void)
|
|||
{
|
||||
NautilusStringList *fruits;
|
||||
|
||||
fruits = nautilus_string_list_new ();
|
||||
fruits = nautilus_string_list_new (TRUE);
|
||||
|
||||
nautilus_string_list_insert (fruits, "orange");
|
||||
nautilus_string_list_insert (fruits, "apple");
|
||||
|
@ -640,7 +670,7 @@ nautilus_self_check_string_list (void)
|
|||
{
|
||||
NautilusStringList *l;
|
||||
|
||||
l = nautilus_string_list_new ();
|
||||
l = nautilus_string_list_new (TRUE);
|
||||
|
||||
nautilus_string_list_insert (l, "x");
|
||||
|
||||
|
@ -666,7 +696,7 @@ nautilus_self_check_string_list (void)
|
|||
{
|
||||
NautilusStringList *l;
|
||||
|
||||
l = nautilus_string_list_new ();
|
||||
l = nautilus_string_list_new (TRUE);
|
||||
|
||||
nautilus_string_list_insert (l, "dog");
|
||||
nautilus_string_list_insert (l, "cat");
|
||||
|
@ -688,7 +718,7 @@ nautilus_self_check_string_list (void)
|
|||
{
|
||||
NautilusStringList *l;
|
||||
|
||||
l = nautilus_string_list_new ();
|
||||
l = nautilus_string_list_new (TRUE);
|
||||
|
||||
nautilus_string_list_remove_duplicates (l);
|
||||
NAUTILUS_CHECK_INTEGER_RESULT (nautilus_string_list_get_length (l), 0);
|
||||
|
@ -728,8 +758,8 @@ nautilus_self_check_string_list (void)
|
|||
NautilusStringList *l;
|
||||
NautilusStringList *other;
|
||||
|
||||
l = nautilus_string_list_new ();
|
||||
other = nautilus_string_list_new ();
|
||||
l = nautilus_string_list_new (TRUE);
|
||||
other = nautilus_string_list_new (TRUE);
|
||||
|
||||
/* assign an other with some items */
|
||||
nautilus_string_list_insert (other, "dog");
|
||||
|
@ -747,7 +777,7 @@ nautilus_self_check_string_list (void)
|
|||
nautilus_string_list_assign_from_string_list (l, other);
|
||||
NAUTILUS_CHECK_INTEGER_RESULT (nautilus_string_list_get_length (l), 1);
|
||||
NAUTILUS_CHECK_STRING_RESULT (nautilus_string_list_nth (l, 0), "something");
|
||||
|
||||
|
||||
/* assign an empty other */
|
||||
nautilus_string_list_clear (other);
|
||||
nautilus_string_list_assign_from_string_list (l, other);
|
||||
|
@ -765,7 +795,7 @@ nautilus_self_check_string_list (void)
|
|||
{
|
||||
NautilusStringList *l;
|
||||
|
||||
l = nautilus_string_list_new ();
|
||||
l = nautilus_string_list_new (TRUE);
|
||||
|
||||
NAUTILUS_CHECK_STRING_RESULT (nautilus_string_list_get_longest_string (l), NULL);
|
||||
NAUTILUS_CHECK_INTEGER_RESULT (nautilus_string_list_get_longest_string_length (l), 0);
|
||||
|
@ -787,6 +817,35 @@ nautilus_self_check_string_list (void)
|
|||
nautilus_string_list_free (l);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* case insensitive tests
|
||||
*
|
||||
*/
|
||||
{
|
||||
NautilusStringList *l;
|
||||
|
||||
l = nautilus_string_list_new (FALSE);
|
||||
|
||||
nautilus_string_list_insert (l, "foo");
|
||||
nautilus_string_list_insert (l, "bar");
|
||||
|
||||
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_contains (l, "Foo"), TRUE);
|
||||
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_contains (l, "foO"), TRUE);
|
||||
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_contains (l, "fOo"), TRUE);
|
||||
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_list_contains (l, "foo"), TRUE);
|
||||
|
||||
nautilus_string_list_clear (l);
|
||||
|
||||
nautilus_string_list_insert (l, "Foo");
|
||||
nautilus_string_list_insert (l, "Foo");
|
||||
nautilus_string_list_insert (l, "fOo");
|
||||
nautilus_string_list_insert (l, "foO");
|
||||
nautilus_string_list_remove_duplicates (l);
|
||||
NAUTILUS_CHECK_INTEGER_RESULT (nautilus_string_list_get_length (l), 1);
|
||||
|
||||
nautilus_string_list_free (l);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* !NAUTILUS_OMIT_SELF_CHECK */
|
||||
|
|
|
@ -33,19 +33,22 @@
|
|||
typedef struct _NautilusStringList NautilusStringList;
|
||||
|
||||
/* Construct an empty string list. */
|
||||
NautilusStringList *nautilus_string_list_new (void);
|
||||
NautilusStringList *nautilus_string_list_new (gboolean case_sensitive);
|
||||
|
||||
|
||||
/* Construct a string list with a single element */
|
||||
NautilusStringList *nautilus_string_list_new_from_string (const char *string);
|
||||
NautilusStringList *nautilus_string_list_new_from_string (const char *string,
|
||||
gboolean case_sensitive);
|
||||
|
||||
|
||||
/* Construct a string list that is a copy of another string list */
|
||||
NautilusStringList *nautilus_string_list_new_from_string_list (const NautilusStringList *other_or_null);
|
||||
NautilusStringList *nautilus_string_list_new_from_string_list (const NautilusStringList *other_or_null,
|
||||
gboolean case_sensitive);
|
||||
|
||||
/* Construct a string list from tokens delimited by the given string and delimeter */
|
||||
NautilusStringList *nautilus_string_list_new_from_tokens (const char *string,
|
||||
const char *delimiter);
|
||||
const char *delimiter,
|
||||
gboolean case_sensitive);
|
||||
|
||||
/* Assign the contents another string list. The other string list can be null. */
|
||||
void nautilus_string_list_assign_from_string_list (NautilusStringList *string_list,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
|
||||
|
||||
nautilus-string-list.h: A collection of strings.
|
||||
nautilus-string-map.c: A many-to-one string mapping data structure.
|
||||
|
||||
Copyright (C) 1999, 2000 Eazel, Inc.
|
||||
|
||||
|
@ -48,12 +48,17 @@ typedef struct
|
|||
} MapEntry;
|
||||
|
||||
/* MapEntry things */
|
||||
static MapEntry *map_entry_new (const char *string);
|
||||
static MapEntry *map_entry_new (const char *string,
|
||||
gboolean case_sensitive);
|
||||
static void map_entry_free (MapEntry *map_entry);
|
||||
static MapEntry *map_entry_list_lookup_mapped_string (GList *entry_list,
|
||||
const char *mapped_string);
|
||||
const char *mapped_string,
|
||||
gboolean case_sensitive);
|
||||
static MapEntry *map_entry_list_lookup (GList *entry_list,
|
||||
const char *string);
|
||||
static gboolean str_is_equal (const char *a,
|
||||
const char *b,
|
||||
gboolean case_sensitive);
|
||||
|
||||
/**
|
||||
* nautilus_string_map_new:
|
||||
|
@ -170,10 +175,10 @@ nautilus_string_map_add (NautilusStringMap *string_map,
|
|||
g_return_if_fail (string_maps_to != NULL);
|
||||
g_return_if_fail (string != NULL);
|
||||
|
||||
map_entry = map_entry_list_lookup_mapped_string (string_map->map, string_maps_to);
|
||||
map_entry = map_entry_list_lookup_mapped_string (string_map->map, string_maps_to, string_map->case_sensitive);
|
||||
|
||||
if (map_entry == NULL) {
|
||||
map_entry = map_entry_new (string_maps_to);
|
||||
map_entry = map_entry_new (string_maps_to, string_map->case_sensitive);
|
||||
|
||||
/* Add a mapping for the string_maps_to to simplify things */
|
||||
nautilus_string_list_insert (map_entry->map_list, string_maps_to);
|
||||
|
@ -186,14 +191,15 @@ nautilus_string_map_add (NautilusStringMap *string_map,
|
|||
|
||||
/* MapEntry things */
|
||||
static MapEntry *
|
||||
map_entry_new (const char *string)
|
||||
map_entry_new (const char *string,
|
||||
gboolean case_sensitive)
|
||||
{
|
||||
MapEntry *map_entry;
|
||||
|
||||
g_return_val_if_fail (string != NULL, NULL);
|
||||
|
||||
map_entry = g_new (MapEntry, 1);
|
||||
map_entry->map_list = nautilus_string_list_new ();
|
||||
map_entry->map_list = nautilus_string_list_new (case_sensitive);
|
||||
map_entry->string = g_strdup (string);
|
||||
|
||||
return map_entry;
|
||||
|
@ -212,7 +218,8 @@ map_entry_free (MapEntry *map_entry)
|
|||
|
||||
static MapEntry *
|
||||
map_entry_list_lookup_mapped_string (GList *entry_list,
|
||||
const char *mapped_string)
|
||||
const char *mapped_string,
|
||||
gboolean case_sensitive)
|
||||
{
|
||||
GList *iterator;
|
||||
|
||||
|
@ -226,7 +233,7 @@ map_entry_list_lookup_mapped_string (GList *entry_list,
|
|||
MapEntry *map_entry = (MapEntry *) iterator->data;
|
||||
g_assert (map_entry != NULL);
|
||||
|
||||
if (nautilus_str_is_equal (map_entry->string, mapped_string)) {
|
||||
if (str_is_equal (map_entry->string, mapped_string, case_sensitive)) {
|
||||
return map_entry;
|
||||
}
|
||||
}
|
||||
|
@ -258,12 +265,19 @@ map_entry_list_lookup (GList *entry_list,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
str_is_equal (const char *a,
|
||||
const char *b,
|
||||
gboolean case_sensitive)
|
||||
{
|
||||
return case_sensitive ? nautilus_str_is_equal (a, b) : nautilus_istr_is_equal (a, b);
|
||||
}
|
||||
|
||||
#if !defined (NAUTILUS_OMIT_SELF_CHECK)
|
||||
|
||||
void
|
||||
nautilus_self_check_string_map (void)
|
||||
{
|
||||
#if 0
|
||||
NautilusStringMap *map;
|
||||
|
||||
map = nautilus_string_map_new (TRUE);
|
||||
|
@ -288,8 +302,33 @@ nautilus_self_check_string_map (void)
|
|||
NAUTILUS_CHECK_STRING_RESULT (nautilus_string_map_lookup (map, "nerd"), "human");
|
||||
NAUTILUS_CHECK_STRING_RESULT (nautilus_string_map_lookup (map, "lozer"), "human");
|
||||
|
||||
NAUTILUS_CHECK_STRING_RESULT (nautilus_string_map_lookup (map, "Lozer"), NULL);
|
||||
NAUTILUS_CHECK_STRING_RESULT (nautilus_string_map_lookup (map, "HuMaN"), NULL);
|
||||
|
||||
nautilus_string_map_free (map);
|
||||
|
||||
/*
|
||||
* case insensitive tests
|
||||
*
|
||||
*/
|
||||
map = nautilus_string_map_new (FALSE);
|
||||
|
||||
NAUTILUS_CHECK_STRING_RESULT (nautilus_string_map_lookup (map, "foo"), NULL);
|
||||
|
||||
nautilus_string_map_clear (map);
|
||||
|
||||
nautilus_string_map_add (map, "animal", "dog");
|
||||
nautilus_string_map_add (map, "animal", "cat");
|
||||
nautilus_string_map_add (map, "animal", "mouse");
|
||||
|
||||
NAUTILUS_CHECK_STRING_RESULT (nautilus_string_map_lookup (map, "animal"), "animal");
|
||||
NAUTILUS_CHECK_STRING_RESULT (nautilus_string_map_lookup (map, "Animal"), "animal");
|
||||
NAUTILUS_CHECK_STRING_RESULT (nautilus_string_map_lookup (map, "cat"), "animal");
|
||||
NAUTILUS_CHECK_STRING_RESULT (nautilus_string_map_lookup (map, "CAT"), "animal");
|
||||
NAUTILUS_CHECK_STRING_RESULT (nautilus_string_map_lookup (map, "dog"), "animal");
|
||||
NAUTILUS_CHECK_STRING_RESULT (nautilus_string_map_lookup (map, "DoG"), "animal");
|
||||
|
||||
nautilus_string_map_free (map);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* !NAUTILUS_OMIT_SELF_CHECK */
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
|
||||
|
||||
nautilus-string-list.h: A collection of strings.
|
||||
nautilus-string-map.h: A many-to-one string mapping data structure.
|
||||
|
||||
Copyright (C) 1999, 2000 Eazel, Inc.
|
||||
|
||||
|
@ -22,6 +22,20 @@
|
|||
Author: Ramiro Estrugo <ramiro@eazel.com>
|
||||
*/
|
||||
|
||||
/* NautilusStringMap is a simple data structure to manage many-to-one
|
||||
* mappings of string. For example:
|
||||
*
|
||||
* map = map_new (TRUE);
|
||||
* map_add (map, "animal", "dog");
|
||||
* map_add (map, "animal", "cat");
|
||||
* map_add (map, "animal", "mouse");
|
||||
*
|
||||
* map_lookup (map, "dog") => "animal"
|
||||
* map_lookup (map, "cat") => "animal"
|
||||
* map_lookup (map, "animal") => "animal"
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef NAUTILUS_STRING_MAP_H
|
||||
#define NAUTILUS_STRING_MAP_H
|
||||
|
||||
|
@ -30,17 +44,26 @@
|
|||
/* Opaque type declaration. */
|
||||
typedef struct _NautilusStringMap NautilusStringMap;
|
||||
|
||||
/* Construct an empty string list. */
|
||||
/* Construct an empty string map. */
|
||||
NautilusStringMap *nautilus_string_map_new (gboolean case_sensitive);
|
||||
|
||||
/* Construct a string list with a single element */
|
||||
/* Add a mapping from 'string' to 'strings_maps_to' */
|
||||
void nautilus_string_map_add (NautilusStringMap *string_map,
|
||||
const char *string_maps_to,
|
||||
const char *string);
|
||||
|
||||
/* Free the string map */
|
||||
void nautilus_string_map_free (NautilusStringMap *string_map);
|
||||
|
||||
|
||||
/* Clear the string map */
|
||||
void nautilus_string_map_clear (NautilusStringMap *string_map);
|
||||
|
||||
|
||||
/* Lookup the string in the map. Returns the string 'string' maps to or NULL of not found. */
|
||||
char * nautilus_string_map_lookup (const NautilusStringMap *string_map,
|
||||
const char *key);
|
||||
const char *string);
|
||||
|
||||
|
||||
#endif /* NAUTILUS_STRING_MAP_H */
|
||||
|
||||
|
|
|
@ -103,7 +103,7 @@ nautilus_string_picker_initialize (NautilusStringPicker *string_picker)
|
|||
gtk_box_set_homogeneous (GTK_BOX (string_picker), FALSE);
|
||||
gtk_box_set_spacing (GTK_BOX (string_picker), STRING_PICKER_SPACING);
|
||||
|
||||
string_picker->detail->string_list = nautilus_string_list_new ();
|
||||
string_picker->detail->string_list = nautilus_string_list_new (TRUE);
|
||||
string_picker->detail->menu = NULL;
|
||||
|
||||
string_picker->detail->option_menu = gtk_option_menu_new ();
|
||||
|
@ -243,7 +243,7 @@ nautilus_string_picker_get_string_list (const NautilusStringPicker *string_picke
|
|||
g_return_val_if_fail (string_picker != NULL, NULL);
|
||||
g_return_val_if_fail (NAUTILUS_IS_STRING_PICKER (string_picker), NULL);
|
||||
|
||||
return nautilus_string_list_new_from_string_list (string_picker->detail->string_list);
|
||||
return nautilus_string_list_new_from_string_list (string_picker->detail->string_list, TRUE);
|
||||
}
|
||||
|
||||
/* FIXME bugzilla.eazel.com 1556:
|
||||
|
@ -311,7 +311,7 @@ nautilus_string_picker_insert_string (NautilusStringPicker *string_picker,
|
|||
|
||||
g_return_if_fail (NAUTILUS_IS_STRING_PICKER (string_picker));
|
||||
|
||||
new_string_list = nautilus_string_list_new_from_string_list (string_picker->detail->string_list);
|
||||
new_string_list = nautilus_string_list_new_from_string_list (string_picker->detail->string_list, TRUE);
|
||||
nautilus_string_list_insert (new_string_list, string);
|
||||
nautilus_string_picker_set_string_list (string_picker, new_string_list);
|
||||
nautilus_string_list_free (new_string_list);
|
||||
|
|
|
@ -82,6 +82,13 @@ nautilus_str_compare (gconstpointer string_a, gconstpointer string_b)
|
|||
(const char *) string_b);
|
||||
}
|
||||
|
||||
int
|
||||
nautilus_istr_compare (gconstpointer string_a, gconstpointer string_b)
|
||||
{
|
||||
return nautilus_strcasecmp ((const char *) string_a,
|
||||
(const char *) string_b);
|
||||
}
|
||||
|
||||
gboolean
|
||||
nautilus_str_has_prefix (const char *haystack, const char *needle)
|
||||
{
|
||||
|
|
|
@ -137,7 +137,7 @@ user_level_manager_new (void)
|
|||
NULL);
|
||||
|
||||
manager->num_user_levels = DEFAULT_NUM_USER_LEVELS;
|
||||
manager->user_level_names = nautilus_string_list_new ();
|
||||
manager->user_level_names = nautilus_string_list_new (TRUE);
|
||||
|
||||
for (i = 0; i < DEFAULT_NUM_USER_LEVELS; i++) {
|
||||
nautilus_string_list_insert (manager->user_level_names, DEFAULT_USER_LEVEL_NAMES[i]);
|
||||
|
@ -345,7 +345,7 @@ nautilus_user_level_manager_get_user_level_names (void)
|
|||
{
|
||||
NautilusUserLevelManager *manager = nautilus_user_level_manager_get ();
|
||||
|
||||
return nautilus_string_list_new_from_string_list (manager->user_level_names);
|
||||
return nautilus_string_list_new_from_string_list (manager->user_level_names, TRUE);
|
||||
}
|
||||
|
||||
char *
|
||||
|
|
|
@ -3553,7 +3553,7 @@ real_get_emblem_names_to_exclude (FMDirectoryView *view)
|
|||
{
|
||||
g_assert (FM_IS_DIRECTORY_VIEW (view));
|
||||
|
||||
return nautilus_string_list_new_from_string (NAUTILUS_FILE_EMBLEM_NAME_TRASH);
|
||||
return nautilus_string_list_new_from_string (NAUTILUS_FILE_EMBLEM_NAME_TRASH, TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -219,7 +219,7 @@ nautilus_application_check_user_directories (NautilusApplication *application)
|
|||
user_main_directory = nautilus_get_user_main_directory ();
|
||||
desktop_directory = nautilus_get_desktop_directory ();
|
||||
|
||||
dir_list = nautilus_string_list_new ();
|
||||
dir_list = nautilus_string_list_new (TRUE);
|
||||
|
||||
/* FIXME bugzilla.eazel.com 1115: Need better name for "User Directory"
|
||||
* and "User Data Directory".
|
||||
|
|
|
@ -420,7 +420,7 @@ create_font_picker_frame (const char *title,
|
|||
|
||||
font_size_list = nautilus_string_list_new_from_tokens ("5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,"
|
||||
"30,40,50,60,70,80,90,100,110,120,130,140,"
|
||||
"200,400,800", ",");
|
||||
"200,400,800", ",", TRUE);
|
||||
|
||||
nautilus_string_picker_set_string_list (NAUTILUS_STRING_PICKER (font_size_picker), font_size_list);
|
||||
nautilus_string_list_free (font_size_list);
|
||||
|
|
|
@ -420,7 +420,7 @@ create_font_picker_frame (const char *title,
|
|||
|
||||
font_size_list = nautilus_string_list_new_from_tokens ("5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,"
|
||||
"30,40,50,60,70,80,90,100,110,120,130,140,"
|
||||
"200,400,800", ",");
|
||||
"200,400,800", ",", TRUE);
|
||||
|
||||
nautilus_string_picker_set_string_list (NAUTILUS_STRING_PICKER (font_size_picker), font_size_list);
|
||||
nautilus_string_list_free (font_size_list);
|
||||
|
|
|
@ -206,7 +206,7 @@ test_string_picker (void)
|
|||
|
||||
nautilus_caption_set_title_label (NAUTILUS_CAPTION (picker), "Icon Font Family:");
|
||||
|
||||
font_list = nautilus_string_list_new ();
|
||||
font_list = nautilus_string_list_new (TRUE);
|
||||
|
||||
nautilus_string_list_insert (font_list, "Helvetica");
|
||||
nautilus_string_list_insert (font_list, "Times");
|
||||
|
|
Loading…
Reference in a new issue