diff options
author | Ernestas Kulik <ernestask@gnome.org> | 2017-12-23 17:28:00 +0200 |
---|---|---|
committer | Ernestas Kulik <ernestask@gnome.org> | 2017-12-23 17:38:17 +0200 |
commit | 61ac48bdc0230eed8466b7d1a3164aae2a5e8594 (patch) | |
tree | bb96c868ab81ff65012b179585ebe660abea7fb7 /eel | |
parent | 351e3f7d4b25a5e8db6e5fee80acea5254fa32d1 (diff) | |
download | nautilus-61ac48bdc0230eed8466b7d1a3164aae2a5e8594.tar.gz |
file-utilities: rework common prefix computation
Currently, the process for getting the common prefix of a list of file
names is a tad too greedy:
1. Find the common prefix of all the strings.
2. Strip the extension from the prefix.
3. Strip trailing punctuation.
Step 2 may strip dots if there’s trailing whitespace and step 3 may
strip useful punctuation (e.g. parentheses). This commit reworks the
process as such:
1. Strip the extension from all the file names.
2. Find the common prefix of all the strings.
3. Trim trailing whitespace.
Fixes #174.
Diffstat (limited to 'eel')
-rw-r--r-- | eel/eel-string.c | 36 | ||||
-rw-r--r-- | eel/eel-string.h | 8 |
2 files changed, 0 insertions, 44 deletions
diff --git a/eel/eel-string.c b/eel/eel-string.c index 85c0841a4..0a41a0bf9 100644 --- a/eel/eel-string.c +++ b/eel/eel-string.c @@ -224,42 +224,6 @@ eel_str_replace_substring (const char *string, return result; } -char * -eel_str_rtrim_punctuation (char *str) -{ - int num_punctuation_chars; - int str_len; - int num_chars_left; - char *current_char_pos; - gunichar current_char; - - num_punctuation_chars = 0; - str_len = g_utf8_strlen (str, -1); - current_char_pos = g_utf8_offset_to_pointer (str, str_len); - - while (num_punctuation_chars <= str_len) - { - current_char_pos = g_utf8_prev_char (current_char_pos); - current_char = g_utf8_get_char (current_char_pos); - - if (!g_unichar_ispunct (current_char) && !g_unichar_isspace (current_char)) - { - break; - } - - ++num_punctuation_chars; - } - - if (num_punctuation_chars == 0) - { - return g_strdup (str); - } - - num_chars_left = str_len - num_punctuation_chars; - - return g_utf8_substring (str, 0, num_chars_left); -} - /** * get_common_prefix_length: * @str_a: first string diff --git a/eel/eel-string.h b/eel/eel-string.h index 98cca7e9f..5df4b6b2a 100644 --- a/eel/eel-string.h +++ b/eel/eel-string.h @@ -57,14 +57,6 @@ char * eel_str_strip_substring_and_after (const char *str, char * eel_str_replace_substring (const char *str, const char *substring, const char *replacement); -/** - * eel_str_rtrim_punctuation: - * @str: string - * - * Returns: a copy of str with trailing punctuation characters removed - */ -char * eel_str_rtrim_punctuation (char *str); - /** * eel_str_get_common_prefix: |