* 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,
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);
* 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,
* 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,
* 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,
* 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,
* 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
*/
* 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
*/
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);
if (n != 0 && --n != 0)
do
{
- register gchar c = *s++;
+ gchar c = *s++;
*d++ = c;
if (c == 0)
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);
*
* 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.)
*
* 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.)
*
* 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()
gchar*
g_strdown (gchar *string)
{
- register guchar *s;
+ guchar *s;
g_return_val_if_fail (string != NULL, NULL);
*
* 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()
gchar*
g_strup (gchar *string)
{
- register guchar *s;
+ guchar *s;
g_return_val_if_fail (string != NULL, NULL);
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;
* 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
* 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
* 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
* 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
*
* Both @s1 and @s2 must be non-%NULL.
*
- * Return value: 0 if the strings match, a negative value if @s1 < @s2,
+ * Returns: 0 if the strings match, a negative value if @s1 < @s2,
* or a positive value if @s1 > @s2.
*/
gint
* 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 < @s2,
+ * Returns: 0 if the strings match, a negative value if @s1 < @s2,
* or a positive value if @s1 > @s2.
*/
gint
* 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 < @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
* 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 < @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
const gchar *delimiters,
gchar new_delim)
{
- register gchar *c;
+ gchar *c;
g_return_val_if_fail (string != NULL, NULL);
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);
* @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
* 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**
* %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
* 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
* 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)
* 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 *
* 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 *
* 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 *
*
* 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
*/
*
* 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
*/
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;
}
/**
* 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
*/
{
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);
result = split_words (string);
- /* TODO: proper iconv transliteration (locale-dependent) */
if (ascii_alternates)
{
gint i, j, n;
{
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);
}
}
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);