120
/* NOTE: 'ALL' is equivalent to 'NFKD'. If this is ever updated, please
121
* update the unaccenting mechanism as well. */
125
122
normalized = g_utf8_normalize (str, -1, G_NORMALIZE_ALL);
126
123
result = g_utf8_casefold (normalized, -1);
127
124
g_free (normalized);
128
/* Combining diacritical mark?
129
* Basic range: [0x0300,0x036F]
130
* Supplement: [0x1DC0,0x1DFF]
131
* For Symbols: [0x20D0,0x20FF]
132
* Half marks: [0xFE20,0xFE2F]
134
#define IS_CDM_UCS4(c) (((c) >= 0x0300 && (c) <= 0x036F) || \
135
((c) >= 0x1DC0 && (c) <= 0x1DFF) || \
136
((c) >= 0x20D0 && (c) <= 0x20FF) || \
137
((c) >= 0xFE20 && (c) <= 0xFE2F))
139
/* Copied from tracker/src/libtracker-fts/tracker-parser-glib.c under the GPL
140
* Originally written by Aleksander Morgado <aleksander@gnu.org>
143
shell_util_normalize_casefold_and_unaccent (const char *str)
146
gsize i = 0, j = 0, ilen;
151
/* Get the NFKD-normalized and casefolded string */
152
tmp = shell_util_normalize_and_casefold (str);
161
/* Get next character of the word as UCS4 */
162
unichar = g_utf8_get_char_validated (&tmp[i], -1);
164
/* Invalid UTF-8 character or end of original string. */
165
if (unichar == (gunichar) -1 ||
166
unichar == (gunichar) -2)
171
/* Find next UTF-8 character */
172
next_utf8 = g_utf8_next_char (&tmp[i]);
173
utf8_len = next_utf8 - &tmp[i];
175
if (IS_CDM_UCS4 ((guint32) unichar))
177
/* If the given unichar is a combining diacritical mark,
178
* just update the original index, not the output one */
183
/* If already found a previous combining
184
* diacritical mark, indexes are different so
185
* need to copy characters. As output and input
186
* buffers may overlap, need to use memmove
187
* instead of memcpy */
190
memmove (&tmp[j], &tmp[i], utf8_len);
193
/* Update both indexes */
198
/* Force proper string end */
132
205
* shell_util_format_date:
133
206
* @format: a strftime-style string format, as parsed by
281
* shell_session_is_active_for_systemd:
283
* Checks whether the session we are running in is currently active,
284
* i.e. in the foreground and ready for user input.
286
* Returns: TRUE if session is active
289
shell_session_is_active_for_systemd (void)
291
/* If this isn't systemd, let's assume the session is active. */
294
if (sd_booted () <= 0)
297
return sd_session_is_active (NULL) != 0;
304
354
* shell_util_wifexited:
305
355
* @status: the status returned by wait() or waitpid()
306
356
* @exit: (out): the actual exit status of the process