glib: Improve documentation for g_strfreev()
[platform/upstream/glib.git] / glib / gstrfuncs.c
index aad8ab4..0a9b109 100644 (file)
  *
  * Note that the functions g_printf(), g_fprintf(), g_sprintf(),
  * g_snprintf(), g_vprintf(), g_vfprintf(), g_vsprintf() and g_vsnprintf()
- * are declared in the header <filename>gprintf.h</filename> which is
- * not included in <filename>glib.h</filename>
- * (otherwise using <filename>glib.h</filename> would drag in
- * <filename>stdio.h</filename>), so you'll have to explicitly include
- * <literal>&lt;glib/gprintf.h&gt;</literal> in order to use the GLib
+ * are declared in the header `gprintf.h` which is not included in `glib.h`
+ * (otherwise using `glib.h` would drag in `stdio.h`), so you'll have to
+ * explicitly include `<glib/gprintf.h>` in order to use the GLib
  * printf() functions.
  *
- * <para id="string-precision">While you may use the printf() functions
- * to format UTF-8 strings, notice that the precision of a
- * <literal>&percnt;Ns</literal> parameter is interpreted as the
- * number of bytes, not characters to print. On top of that, the GNU
- * libc implementation of the printf() functions has the "feature" that
- * it checks that the string given for the <literal>&percnt;Ns</literal>
+ * ## String precision pitfalls # {#string-precision}
+ *
+ * While you may use the printf() functions to format UTF-8 strings,
+ * notice that the precision of a \%Ns parameter is interpreted
+ * as the number of bytes, not characters to print. On top of that,
+ * the GNU libc implementation of the printf() functions has the
+ * "feature" that it checks that the string given for the \%Ns
  * parameter consists of a whole number of characters in the current
  * encoding. So, unless you are sure you are always going to be in an
  * UTF-8 locale or your know your text is restricted to ASCII, avoid
- * using <literal>&percnt;Ns</literal>. If your intention is to format
- * strings for a certain number of columns, then
- * <literal>&percnt;Ns</literal> is not a correct solution anyway, since it
- * fails to take wide characters (see g_unichar_iswide()) into account.
- * </para>
+ * using \%Ns. If your intention is to format strings for a
+ * certain number of columns, then \%Ns is not a correct solution
+ * anyway, since it fails to take wide characters (see g_unichar_iswide())
+ * into account.
  */
 
 /**
@@ -403,8 +401,8 @@ g_memdup (gconstpointer mem,
  * %NULL it returns %NULL. The returned value should be freed when no longer
  * needed.
  *
- * To copy a number of characters from a UTF-8 encoded string, use
- * g_utf8_strncpy() instead.
+ * To copy a number of characters from a UTF-8 encoded string,
+ * use g_utf8_strncpy() instead.
  *
  * Returns: a newly-allocated buffer containing the first @n bytes
  *     of @str, nul-terminated
@@ -460,7 +458,7 @@ g_strnfill (gsize length,
  * This is useful for concatenating multiple strings together
  * without having to repeatedly scan for the end.
  *
- * Return value: a pointer to trailing nul byte.
+ * Returns: a pointer to trailing nul byte.
  **/
 gchar *
 g_stpcpy (gchar       *dest,
@@ -471,8 +469,8 @@ g_stpcpy (gchar       *dest,
   g_return_val_if_fail (src != NULL, NULL);
   return stpcpy (dest, src);
 #else
-  register gchar *d = dest;
-  register const gchar *s = src;
+  gchar *d = dest;
+  const gchar *s = src;
 
   g_return_val_if_fail (dest != NULL, NULL);
   g_return_val_if_fail (src != NULL, NULL);
@@ -487,7 +485,7 @@ g_stpcpy (gchar       *dest,
 /**
  * g_strdup_vprintf:
  * @format: a standard printf() format string, but notice
- *     <link linkend="string-precision">string precision pitfalls</link>
+ *     [string precision pitfalls][string-precision]
  * @args: the list of parameters to insert into the format string
  *
  * Similar to the standard C vsprintf() function but safer, since it
@@ -514,7 +512,7 @@ g_strdup_vprintf (const gchar *format,
 /**
  * g_strdup_printf:
  * @format: a standard printf() format string, but notice
- *     <link linkend="string-precision">string precision pitfalls</link>
+ *     [string precision pitfalls][string-precision]
  * @...: the parameters to insert into the format string
  *
  * Similar to the standard C sprintf() function but safer, since it
@@ -611,7 +609,7 @@ g_strconcat (const gchar *string1, ...)
  * separated lists of values, since the commas may be interpreted as a decimal
  * point in some locales, causing unexpected results.
  *
- * Return value: the #gdouble value.
+ * Returns: the #gdouble value.
  **/
 gdouble
 g_strtod (const gchar *nptr,
@@ -668,15 +666,15 @@ g_strtod (const gchar *nptr,
  * To convert from a #gdouble to a string in a locale-insensitive
  * way, use g_ascii_dtostr().
  *
- * If the correct value would cause overflow, plus or minus <literal>HUGE_VAL</literal>
- * is returned (according to the sign of the value), and <literal>ERANGE</literal> is
- * stored in <literal>errno</literal>. If the correct value would cause underflow,
- * zero is returned and <literal>ERANGE</literal> is stored in <literal>errno</literal>.
+ * If the correct value would cause overflow, plus or minus %HUGE_VAL
+ * is returned (according to the sign of the value), and %ERANGE is
+ * stored in %errno. If the correct value would cause underflow,
+ * zero is returned and %ERANGE is stored in %errno.
  *
- * This function resets <literal>errno</literal> before calling strtod() so that
+ * This function resets %errno before calling strtod() so that
  * you can reliably detect overflow and underflow.
  *
- * Return value: the #gdouble value.
+ * Returns: the #gdouble value.
  */
 gdouble
 g_ascii_strtod (const gchar *nptr,
@@ -862,7 +860,7 @@ g_ascii_strtod (const gchar *nptr,
  * guaranteed that the size of the resulting string will never
  * be larger than @G_ASCII_DTOSTR_BUF_SIZE bytes.
  *
- * Return value: The pointer to the buffer with the converted string.
+ * Returns: The pointer to the buffer with the converted string.
  **/
 gchar *
 g_ascii_dtostr (gchar       *buffer,
@@ -891,7 +889,7 @@ g_ascii_dtostr (gchar       *buffer,
  * If you just want to want to serialize the value into a
  * string, use g_ascii_dtostr().
  *
- * Return value: The pointer to the buffer with the converted string.
+ * Returns: The pointer to the buffer with the converted string.
  */
 gchar *
 g_ascii_formatd (gchar       *buffer,
@@ -1138,13 +1136,13 @@ g_parse_long_long (const gchar  *nptr,
  * locale-sensitive system strtoull() function.
  *
  * If the correct value would cause overflow, %G_MAXUINT64
- * is returned, and <literal>ERANGE</literal> is stored in <literal>errno</literal>.
+ * is returned, and `ERANGE` is stored in `errno`.
  * If the base is outside the valid range, zero is returned, and
- * <literal>EINVAL</literal> is stored in <literal>errno</literal>.
+ * `EINVAL` is stored in `errno`.
  * If the string conversion fails, zero is returned, and @endptr returns
  * @nptr (if @endptr is non-%NULL).
  *
- * Return value: the #guint64 value or zero on error.
+ * Returns: the #guint64 value or zero on error.
  *
  * Since: 2.2
  */
@@ -1185,13 +1183,13 @@ g_ascii_strtoull (const gchar *nptr,
  * locale-sensitive system strtoll() function.
  *
  * If the correct value would cause overflow, %G_MAXINT64 or %G_MININT64
- * is returned, and <literal>ERANGE</literal> is stored in <literal>errno</literal>.
+ * is returned, and `ERANGE` is stored in `errno`.
  * If the base is outside the valid range, zero is returned, and
- * <literal>EINVAL</literal> is stored in <literal>errno</literal>. If the
+ * `EINVAL` is stored in `errno`. If the
  * string conversion fails, zero is returned, and @endptr returns @nptr
  * (if @endptr is non-%NULL).
  *
- * Return value: the #gint64 value or zero on error.
+ * Returns: the #gint64 value or zero on error.
  *
  * Since: 2.12
  */
@@ -1236,7 +1234,7 @@ g_ascii_strtoll (const gchar *nptr,
  * not all platforms support the strerror() function.
  *
  * Returns: a UTF-8 string describing the error code. If the error code
- *     is unknown, it returns "unknown error (&lt;code&gt;)".
+ *     is unknown, it returns "unknown error (<code>)".
  */
 const gchar *
 g_strerror (gint errnum)
@@ -1258,8 +1256,7 @@ g_strerror (gint errnum)
 
 /**
  * g_strsignal:
- * @signum: the signal number. See the <literal>signal</literal>
- *     documentation
+ * @signum: the signal number. See the `signal` documentation
  *
  * Returns a string describing the given signal, e.g. "Segmentation fault".
  * You should use this function in preference to strsignal(), because it
@@ -1267,7 +1264,7 @@ g_strerror (gint errnum)
  * the strsignal() function.
  *
  * Returns: a UTF-8 string describing the signal. If the signal is unknown,
- *     it returns "unknown signal (&lt;signum&gt;)".
+ *     it returns "unknown signal (<signum>)".
  */
 const gchar *
 g_strsignal (gint signum)
@@ -1351,9 +1348,9 @@ g_strlcpy (gchar       *dest,
            const gchar *src,
            gsize        dest_size)
 {
-  register gchar *d = dest;
-  register const gchar *s = src;
-  register gsize n = dest_size;
+  gchar *d = dest;
+  const gchar *s = src;
+  gsize n = dest_size;
 
   g_return_val_if_fail (dest != NULL, 0);
   g_return_val_if_fail (src  != NULL, 0);
@@ -1362,7 +1359,7 @@ g_strlcpy (gchar       *dest,
   if (n != 0 && --n != 0)
     do
       {
-        register gchar c = *s++;
+        gchar c = *s++;
 
         *d++ = c;
         if (c == 0)
@@ -1412,9 +1409,9 @@ g_strlcat (gchar       *dest,
            const gchar *src,
            gsize        dest_size)
 {
-  register gchar *d = dest;
-  register const gchar *s = src;
-  register gsize bytes_left = dest_size;
+  gchar *d = dest;
+  const gchar *s = src;
+  gsize bytes_left = dest_size;
   gsize dlength;  /* Logically, MIN (strlen (d), dest_size) */
 
   g_return_val_if_fail (dest != NULL, 0);
@@ -1451,7 +1448,7 @@ g_strlcat (gchar       *dest,
  *
  * Converts all upper case ASCII letters to lower case ASCII letters.
  *
- * Return value: a newly-allocated string, with all the upper case
+ * Returns: a newly-allocated string, with all the upper case
  *     characters in @str converted to lower case, with semantics that
  *     exactly match g_ascii_tolower(). (Note that this is unlike the
  *     old g_strdown(), which modified the string in place.)
@@ -1481,7 +1478,7 @@ g_ascii_strdown (const gchar *str,
  *
  * Converts all lower case ASCII letters to upper case ASCII letters.
  *
- * Return value: a newly allocated string, with all the lower case
+ * Returns: a newly allocated string, with all the lower case
  *     characters in @str converted to upper case, with semantics that
  *     exactly match g_ascii_toupper(). (Note that this is unlike the
  *     old g_strup(), which modified the string in place.)
@@ -1506,22 +1503,22 @@ g_ascii_strup (const gchar *str,
 
 /**
  * g_str_is_ascii:
- * @string: a string
+ * @str: a string
  *
- * Determines if a string is pure ASCII.  A string is pure ASCII if it
+ * Determines if a string is pure ASCII. A string is pure ASCII if it
  * contains no bytes with the high bit set.
  *
- * Returns: %TRUE if @string is ascii
+ * Returns: %TRUE if @str is ASCII
  *
  * Since: 2.40
  */
 gboolean
-g_str_is_ascii (const gchar *string)
+g_str_is_ascii (const gchar *str)
 {
   gint i;
 
-  for (i = 0; string[i]; i++)
-    if (string[i] & 0x80)
+  for (i = 0; str[i]; i++)
+    if (str[i] & 0x80)
       return FALSE;
 
   return TRUE;
@@ -1533,7 +1530,7 @@ g_str_is_ascii (const gchar *string)
  *
  * Converts a string to lower case.
  *
- * Return value: the string
+ * Returns: the string
  *
  * Deprecated:2.2: This function is totally broken for the reasons discussed
  * in the g_strncasecmp() docs - use g_ascii_strdown() or g_utf8_strdown()
@@ -1542,7 +1539,7 @@ g_str_is_ascii (const gchar *string)
 gchar*
 g_strdown (gchar *string)
 {
-  register guchar *s;
+  guchar *s;
 
   g_return_val_if_fail (string != NULL, NULL);
 
@@ -1564,7 +1561,7 @@ g_strdown (gchar *string)
  *
  * Converts a string to upper case.
  *
- * Return value: the string
+ * Returns: the string
  *
  * Deprecated:2.2: This function is totally broken for the reasons
  *     discussed in the g_strncasecmp() docs - use g_ascii_strup()
@@ -1573,7 +1570,7 @@ g_strdown (gchar *string)
 gchar*
 g_strup (gchar *string)
 {
-  register guchar *s;
+  guchar *s;
 
   g_return_val_if_fail (string != NULL, NULL);
 
@@ -1594,8 +1591,7 @@ g_strup (gchar *string)
  * @string: the string to reverse
  *
  * Reverses all of the bytes in a string. For example,
- * <literal>g_strreverse ("abcdef")</literal> will result
- * in "fedcba".
+ * `g_strreverse ("abcdef")` will result in "fedcba".
  *
  * Note that g_strreverse() doesn't work on UTF-8 strings
  * containing multibyte characters. For that purpose, use
@@ -1610,14 +1606,14 @@ g_strreverse (gchar *string)
 
   if (*string)
     {
-      register gchar *h, *t;
+      gchar *h, *t;
 
       h = string;
       t = string + strlen (string) - 1;
 
       while (h < t)
         {
-          register gchar c;
+          gchar c;
 
           c = *h;
           *h = *t;
@@ -1644,7 +1640,7 @@ g_strreverse (gchar *string)
  * don't call it on %EOF but no need to worry about casting to #guchar
  * before passing a possibly non-ASCII character in.
  *
- * Return value: the result of converting @c to lower case. If @c is
+ * Returns: the result of converting @c to lower case. If @c is
  *     not an ASCII upper case letter, @c is returned unchanged.
  */
 gchar
@@ -1667,7 +1663,7 @@ g_ascii_tolower (gchar c)
  * don't call it on %EOF but no need to worry about casting to #guchar
  * before passing a possibly non-ASCII character in.
  *
- * Return value: the result of converting @c to upper case. If @c is not
+ * Returns: the result of converting @c to upper case. If @c is not
  *    an ASCII lower case letter, @c is returned unchanged.
  */
 gchar
@@ -1684,7 +1680,7 @@ g_ascii_toupper (gchar c)
  * Differs from g_unichar_digit_value() because it takes a char, so
  * there's no worry about sign extension if characters are signed.
  *
- * Return value: If @c is a decimal digit (according to g_ascii_isdigit()),
+ * Returns: If @c is a decimal digit (according to g_ascii_isdigit()),
  *    its numeric value. Otherwise, -1.
  */
 int
@@ -1704,7 +1700,7 @@ g_ascii_digit_value (gchar c)
  * a char, so there's no worry about sign extension if characters
  * are signed.
  *
- * Return value: If @c is a hex digit (according to g_ascii_isxdigit()),
+ * Returns: If @c is a hex digit (according to g_ascii_isxdigit()),
  *     its numeric value. Otherwise, -1.
  */
 int
@@ -1738,8 +1734,8 @@ g_ascii_xdigit_value (gchar c)
  *
  * Both @s1 and @s2 must be non-%NULL.
  *
- * Return value: 0 if the strings match, a negative value if @s1 &lt; @s2,
- *     or a positive value if @s1 &gt; @s2.
+ * Returns: 0 if the strings match, a negative value if @s1 < @s2,
+ *     or a positive value if @s1 > @s2.
  */
 gint
 g_ascii_strcasecmp (const gchar *s1,
@@ -1779,8 +1775,8 @@ g_ascii_strcasecmp (const gchar *s1,
  * function only on strings known to be in encodings where bytes
  * corresponding to ASCII letters always represent themselves.
  *
- * Return value: 0 if the strings match, a negative value if @s1 &lt; @s2,
- *     or a positive value if @s1 &gt; @s2.
+ * Returns: 0 if the strings match, a negative value if @s1 < @s2,
+ *     or a positive value if @s1 > @s2.
  */
 gint
 g_ascii_strncasecmp (const gchar *s1,
@@ -1816,8 +1812,8 @@ g_ascii_strncasecmp (const gchar *s1,
  * A case-insensitive string comparison, corresponding to the standard
  * strcasecmp() function on platforms which support it.
  *
- * Return value: 0 if the strings match, a negative value if @s1 &lt; @s2,
- *     or a positive value if @s1 &gt; @s2.
+ * Returns: 0 if the strings match, a negative value if @s1 < @s2,
+ *     or a positive value if @s1 > @s2.
  *
  * Deprecated:2.2: See g_strncasecmp() for a discussion of why this
  *     function is deprecated and how to replace it.
@@ -1864,8 +1860,8 @@ g_strcasecmp (const gchar *s1,
  * to g_strcasecmp() except it only compares the first @n characters of
  * the strings.
  *
- * Return value: 0 if the strings match, a negative value if @s1 &lt; @s2,
- *     or a positive value if @s1 &gt; @s2.
+ * Returns: 0 if the strings match, a negative value if @s1 < @s2,
+ *     or a positive value if @s1 > @s2.
  *
  * Deprecated:2.2: The problem with g_strncasecmp() is that it does
  *     the comparison by calling toupper()/tolower(). These functions
@@ -1938,7 +1934,7 @@ g_strdelimit (gchar       *string,
               const gchar *delimiters,
               gchar        new_delim)
 {
-  register gchar *c;
+  gchar *c;
 
   g_return_val_if_fail (string != NULL, NULL);
 
@@ -1975,7 +1971,7 @@ g_strcanon (gchar       *string,
             const gchar *valid_chars,
             gchar        substitutor)
 {
-  register gchar *c;
+  gchar *c;
 
   g_return_val_if_fail (string != NULL, NULL);
   g_return_val_if_fail (valid_chars != NULL, NULL);
@@ -2250,6 +2246,10 @@ g_strchomp (gchar *string)
  * @delimiter. If @max_tokens is reached, the remainder of @string is
  * appended to the last token.
  *
+ * As an example, the result of g_strsplit (":a:bc::d:", ":", -1) is a
+ * %NULL-terminated vector containing the six strings "", "a", "bc", "", "d"
+ * and "".
+ *
  * As a special case, the result of splitting the empty string "" is an empty
  * vector, not a vector containing a single string. The reason for this
  * special case is that being able to represent a empty vector is typically
@@ -2257,7 +2257,7 @@ g_strchomp (gchar *string)
  * to represent empty elements, you'll need to check for the empty string
  * before calling g_strsplit().
  *
- * Return value: a newly-allocated %NULL-terminated array of strings. Use
+ * Returns: a newly-allocated %NULL-terminated array of strings. Use
  *    g_strfreev() to free it.
  */
 gchar**
@@ -2329,7 +2329,7 @@ g_strsplit (const gchar *string,
  * %NULL-terminated vector containing the three strings "abc", "def",
  * and "ghi".
  *
- * The result if g_strsplit_set (":def/ghi:", ":/", -1) is a %NULL-terminated
+ * The result of g_strsplit_set (":def/ghi:", ":/", -1) is a %NULL-terminated
  * vector containing the four strings "", "def", "ghi", and "".
  *
  * As a special case, the result of splitting the empty string "" is an empty
@@ -2342,7 +2342,7 @@ g_strsplit (const gchar *string,
  * Note that this function works on bytes not characters, so it can't be used
  * to delimit UTF-8 strings for anything but ASCII characters.
  *
- * Return value: a newly-allocated %NULL-terminated array of strings. Use
+ * Returns: a newly-allocated %NULL-terminated array of strings. Use
  *    g_strfreev() to free it.
  *
  * Since: 2.4
@@ -2413,9 +2413,11 @@ g_strsplit_set (const gchar *string,
 /**
  * g_strfreev:
  * @str_array: a %NULL-terminated array of strings to free
-
- * Frees a %NULL-terminated array of strings, and the array itself.
- * If called on a %NULL value, g_strfreev() simply returns.
+ *
+ * Frees a %NULL-terminated array of strings, as well as each
+ * string it contains.
+ *
+ * If @str_array is %NULL, this function simply returns.
  */
 void
 g_strfreev (gchar **str_array)
@@ -2440,7 +2442,7 @@ g_strfreev (gchar **str_array)
  * the array itself. g_strfreev() does this for you. If called
  * on a %NULL value, g_strdupv() simply returns %NULL.
  *
- * Return value: a new %NULL-terminated array of strings.
+ * Returns: a new %NULL-terminated array of strings.
  */
 gchar**
 g_strdupv (gchar **str_array)
@@ -2605,7 +2607,7 @@ g_strjoin (const gchar *separator,
  * of the string @needle, limiting the length of the search
  * to @haystack_len.
  *
- * Return value: a pointer to the found occurrence, or
+ * Returns: a pointer to the found occurrence, or
  *    %NULL if not found.
  */
 gchar *
@@ -2657,7 +2659,7 @@ g_strstr_len (const gchar *haystack,
  * Searches the string @haystack for the last occurrence
  * of the string @needle.
  *
- * Return value: a pointer to the found occurrence, or
+ * Returns: a pointer to the found occurrence, or
  *    %NULL if not found.
  */
 gchar *
@@ -2708,7 +2710,7 @@ g_strrstr (const gchar *haystack,
  * of the string @needle, limiting the length of the search
  * to @haystack_len.
  *
- * Return value: a pointer to the found occurrence, or
+ * Returns: a pointer to the found occurrence, or
  *    %NULL if not found.
  */
 gchar *
@@ -2760,7 +2762,7 @@ g_strrstr_len (const gchar *haystack,
  *
  * Looks whether the string @str ends with @suffix.
  *
- * Return value: %TRUE if @str end with @suffix, %FALSE otherwise.
+ * Returns: %TRUE if @str end with @suffix, %FALSE otherwise.
  *
  * Since: 2.2
  */
@@ -2790,7 +2792,7 @@ g_str_has_suffix (const gchar *str,
  *
  * Looks whether the string @str begins with @prefix.
  *
- * Return value: %TRUE if @str begins with @prefix, %FALSE otherwise.
+ * Returns: %TRUE if @str begins with @prefix, %FALSE otherwise.
  *
  * Since: 2.2
  */
@@ -2798,19 +2800,10 @@ gboolean
 g_str_has_prefix (const gchar *str,
                   const gchar *prefix)
 {
-  int str_len;
-  int prefix_len;
-
   g_return_val_if_fail (str != NULL, FALSE);
   g_return_val_if_fail (prefix != NULL, FALSE);
 
-  str_len = strlen (str);
-  prefix_len = strlen (prefix);
-
-  if (str_len < prefix_len)
-    return FALSE;
-
-  return strncmp (str, prefix, prefix_len) == 0;
+  return strncmp (str, prefix, strlen (prefix)) == 0;
 }
 
 /**
@@ -2820,7 +2813,7 @@ g_str_has_prefix (const gchar *str,
  * Returns the length of the given %NULL-terminated
  * string array @str_array.
  *
- * Return value: length of @str_array.
+ * Returns: length of @str_array.
  *
  * Since: 2.6
  */
@@ -2957,6 +2950,8 @@ g_str_tokenize_and_fold (const gchar   *string,
 {
   gchar **result;
 
+  g_return_val_if_fail (string != NULL, NULL);
+
   if (ascii_alternates && g_str_is_ascii (string))
     {
       *ascii_alternates = g_new0 (gchar *, 0 + 1);
@@ -2965,7 +2960,6 @@ g_str_tokenize_and_fold (const gchar   *string,
 
   result = split_words (string);
 
-  /* TODO: proper iconv transliteration (locale-dependent) */
   if (ascii_alternates)
     {
       gint i, j, n;
@@ -2978,21 +2972,26 @@ g_str_tokenize_and_fold (const gchar   *string,
         {
           if (!g_str_is_ascii (result[i]))
             {
-              gchar *decomposed;
+              gchar *composed;
               gchar *ascii;
-              gint k = 0;
-              gint l = 0;
+              gint k;
+
+              composed = g_utf8_normalize (result[i], -1, G_NORMALIZE_ALL_COMPOSE);
 
-              decomposed = g_utf8_normalize (result[i], -1, G_NORMALIZE_ALL);
-              ascii = g_malloc (strlen (decomposed) + 1);
+              ascii = g_str_to_ascii (composed, translit_locale);
 
-              for (k = 0; decomposed[k]; k++)
-                if (~decomposed[k] & 0x80)
-                  ascii[l++] = decomposed[k];
-              ascii[l] = '\0';
+              /* Only accept strings that are now entirely alnums */
+              for (k = 0; ascii[k]; k++)
+                if (!g_ascii_isalnum (ascii[k]))
+                  break;
 
-              (*ascii_alternates)[j++] = ascii;
-              g_free (decomposed);
+              if (ascii[k] == '\0')
+                /* Made it to the end... */
+                (*ascii_alternates)[j++] = ascii;
+              else
+                g_free (ascii);
+
+              g_free (composed);
             }
         }
 
@@ -3046,6 +3045,9 @@ g_str_match_string (const gchar *search_term,
   gboolean matched;
   gint i, j;
 
+  g_return_val_if_fail (search_term != NULL, FALSE);
+  g_return_val_if_fail (potential_hit != NULL, FALSE);
+
   term_tokens = g_str_tokenize_and_fold (search_term, NULL, NULL);
   hit_tokens = g_str_tokenize_and_fold (potential_hit, NULL, accept_alternates ? &alternates : NULL);