Update to version 2.33.1
[profile/ivi/glib2.git] / glib / goption.c
index c1c520d..7f8af97 100644 (file)
@@ -258,36 +258,15 @@ _g_unichar_get_width (gunichar c)
 }
 
 static glong
-_g_utf8_strwidth (const gchar *p,
-                  gssize       max)
+_g_utf8_strwidth (const gchar *p)
 {
   glong len = 0;
-  const gchar *start = p;
-  g_return_val_if_fail (p != NULL || max == 0, 0);
+  g_return_val_if_fail (p != NULL, 0);
 
-  if (max < 0)
+  while (*p)
     {
-      while (*p)
-        {
-          len += _g_unichar_get_width (g_utf8_get_char (p));
-          p = g_utf8_next_char (p);
-        }
-    }
-  else
-    {
-      if (max == 0 || !*p)
-        return 0;
-
-      /* this case may not be quite correct */
-
       len += _g_unichar_get_width (g_utf8_get_char (p));
       p = g_utf8_next_char (p);
-
-      while (p - start < max && *p)
-        {
-          len += _g_unichar_get_width (g_utf8_get_char (p));
-          p = g_utf8_next_char (p);
-        }
     }
 
   return len;
@@ -559,7 +538,7 @@ g_option_context_get_main_group (GOptionContext *context)
  * g_option_context_add_main_entries:
  * @context: a #GOptionContext
  * @entries: a %NULL-terminated array of #GOptionEntry<!-- -->s
- * @translation_domain: a translation domain to use for translating
+ * @translation_domain: (allow-none): a translation domain to use for translating
  *    the <option>--help</option> output for the options in @entries
  *    with gettext(), or %NULL
  *
@@ -597,13 +576,13 @@ calculate_max_length (GOptionGroup *group)
       if (entry->flags & G_OPTION_FLAG_HIDDEN)
         continue;
 
-      len = _g_utf8_strwidth (entry->long_name, -1);
+      len = _g_utf8_strwidth (entry->long_name);
 
       if (entry->short_name)
         len += 4;
 
       if (!NO_ARG (entry) && entry->arg_description)
-        len += 1 + _g_utf8_strwidth (TRANSLATE (group, entry->arg_description), -1);
+        len += 1 + _g_utf8_strwidth (TRANSLATE (group, entry->arg_description));
 
       max_length = MAX (max_length, len);
     }
@@ -636,7 +615,7 @@ print_entry (GOptionGroup       *group,
     g_string_append_printf (str, "=%s", TRANSLATE (group, entry->arg_description));
 
   g_string_append_printf (string, "%s%*s %s\n", str->str,
-                          (int) (max_length + 4 - _g_utf8_strwidth (str->str, -1)), "",
+                          (int) (max_length + 4 - _g_utf8_strwidth (str->str)), "",
                           entry->description ? TRANSLATE (group, entry->description) : "");
   g_string_free (str, TRUE);
 }
@@ -716,7 +695,7 @@ context_has_h_entry (GOptionContext *context)
  * g_option_context_get_help:
  * @context: a #GOptionContext
  * @main_help: if %TRUE, only include the main group
- * @group: the #GOptionGroup to create help for, or %NULL
+ * @group: (allow-none): the #GOptionGroup to create help for, or %NULL
  *
  * Returns a formatted, translated help text for the given context.
  * To obtain the text produced by <option>--help</option>, call
@@ -830,11 +809,11 @@ g_option_context_get_help (GOptionContext *context,
 
   list = context->groups;
 
-  max_length = _g_utf8_strwidth ("-?, --help", -1);
+  max_length = _g_utf8_strwidth ("-?, --help");
 
   if (list)
     {
-      len = _g_utf8_strwidth ("--help-all", -1);
+      len = _g_utf8_strwidth ("--help-all");
       max_length = MAX (max_length, len);
     }
 
@@ -849,7 +828,7 @@ g_option_context_get_help (GOptionContext *context,
       GOptionGroup *g = list->data;
 
       /* First, we check the --help-<groupname> options */
-      len = _g_utf8_strwidth ("--help-", -1) + _g_utf8_strwidth (g->name, -1);
+      len = _g_utf8_strwidth ("--help-") + _g_utf8_strwidth (g->name);
       max_length = MAX (max_length, len);
 
       /* Then we go through the entries */
@@ -2087,9 +2066,9 @@ g_option_context_parse (GOptionContext   *context,
  * @help_description: a description for the <option>--help-</option>@name option.
  *   This string is translated using the translation domain or translation function
  *   of the group
- * @user_data: user data that will be passed to the pre- and post-parse hooks,
+ * @user_data: (allow-none): user data that will be passed to the pre- and post-parse hooks,
  *   the error hook and to callbacks of %G_OPTION_ARG_CALLBACK options, or %NULL
- * @destroy: a function that will be called to free @user_data, or %NULL
+ * @destroy: (allow-none): a function that will be called to free @user_data, or %NULL
  *
  * Creates a new #GOptionGroup.
  *
@@ -2208,8 +2187,8 @@ g_option_group_add_entries (GOptionGroup       *group,
 /**
  * g_option_group_set_parse_hooks:
  * @group: a #GOptionGroup
- * @pre_parse_func: a function to call before parsing, or %NULL
- * @post_parse_func: a function to call after parsing, or %NULL
+ * @pre_parse_func: (allow-none): a function to call before parsing, or %NULL
+ * @post_parse_func: (allow-none): a function to call after parsing, or %NULL
  *
  * Associates two functions with @group which will be called
  * from g_option_context_parse() before the first option is parsed
@@ -2258,9 +2237,9 @@ g_option_group_set_error_hook (GOptionGroup     *group,
 /**
  * g_option_group_set_translate_func:
  * @group: a #GOptionGroup
- * @func: the #GTranslateFunc, or %NULL
- * @data: user data to pass to @func, or %NULL
- * @destroy_notify: a function which gets called to free @data, or %NULL
+ * @func: (allow-none): the #GTranslateFunc, or %NULL
+ * @data: (allow-none): user data to pass to @func, or %NULL
+ * @destroy_notify: (allow-none): a function which gets called to free @data, or %NULL
  *
  * Sets the function which is used to translate user-visible
  * strings, for <option>--help</option> output. Different
@@ -2320,9 +2299,9 @@ g_option_group_set_translation_domain (GOptionGroup *group,
 /**
  * g_option_context_set_translate_func:
  * @context: a #GOptionContext
- * @func: the #GTranslateFunc, or %NULL
- * @data: user data to pass to @func, or %NULL
- * @destroy_notify: a function which gets called to free @data, or %NULL
+ * @func: (allow-none): the #GTranslateFunc, or %NULL
+ * @data: (allow-none): user data to pass to @func, or %NULL
+ * @destroy_notify: (allow-none): a function which gets called to free @data, or %NULL
  *
  * Sets the function which is used to translate the contexts
  * user-visible strings, for <option>--help</option> output.
@@ -2379,7 +2358,7 @@ g_option_context_set_translation_domain (GOptionContext *context,
 /**
  * g_option_context_set_summary:
  * @context: a #GOptionContext
- * @summary: a string to be shown in <option>--help</option> output
+ * @summary: (allow-none): a string to be shown in <option>--help</option> output
  *  before the list of options, or %NULL
  *
  * Adds a string to be displayed in <option>--help</option> output
@@ -2424,7 +2403,7 @@ g_option_context_get_summary (GOptionContext *context)
 /**
  * g_option_context_set_description:
  * @context: a #GOptionContext
- * @description: a string to be shown in <option>--help</option> output
+ * @description: (allow-none): a string to be shown in <option>--help</option> output
  *   after the list of options, or %NULL
  *
  * Adds a string to be displayed in <option>--help</option> output