summaryrefslogtreecommitdiff
path: root/eel
diff options
context:
space:
mode:
authorErnestas Kulik <ernestask@gnome.org>2018-03-05 11:25:23 +0200
committerErnestas Kulik <ernestask@gnome.org>2018-03-05 11:26:49 +0200
commit7447f62fc70671ada9a18620546d8f3700d1bebc (patch)
treef4409f03942c56eb67941e5c1934bc00333d1df8 /eel
parent9df807799d6678be0723b93b6df259c3e2962cd5 (diff)
downloadnautilus-7447f62fc70671ada9a18620546d8f3700d1bebc.tar.gz
eel: string: remove custom strdup_printf functions
These aren’t used anywhere and cause Clang to spit out errors about format strings not being literals.
Diffstat (limited to 'eel')
-rw-r--r--eel/eel-string.c513
-rw-r--r--eel/eel-string.h14
2 files changed, 0 insertions, 527 deletions
diff --git a/eel/eel-string.c b/eel/eel-string.c
index 4ebef3bf1..d7e31988e 100644
--- a/eel/eel-string.c
+++ b/eel/eel-string.c
@@ -345,435 +345,6 @@ enum
ARG_TYPE_POINTER
};
-typedef int ArgType; /* An int, because custom are < 0 */
-
-
-static const char *
-get_position (const char *format,
- int *i)
-{
- const char *p;
-
- p = format;
-
- if (g_ascii_isdigit (*p))
- {
- p++;
-
- while (g_ascii_isdigit (*p))
- {
- p++;
- }
-
- if (*p == '$')
- {
- if (i != NULL)
- {
- *i = atoi (format) - 1;
- }
- return p + 1;
- }
- }
-
- return format;
-}
-
-static gboolean
-is_flag (char c)
-{
- return strchr ("#0- +'I", c) != NULL;
-}
-
-static gboolean
-is_length_modifier (char c)
-{
- return strchr ("hlLjzt", c) != NULL;
-}
-
-
-static ArgType
-get_arg_type_from_format (EelPrintfHandler *custom_handlers,
- const char *format,
- int len)
-{
- int i;
- char c;
-
- c = format[len - 1];
-
- if (custom_handlers != NULL)
- {
- for (i = 0; custom_handlers[i].character != 0; i++)
- {
- if (custom_handlers[i].character == c)
- {
- return -(i + 1);
- }
- }
- }
-
- switch (c)
- {
- case 'd':
- case 'i':
- case 'o':
- case 'u':
- case 'x':
- case 'X':
- {
- if (g_str_has_prefix (format, "ll"))
- {
- return ARG_TYPE_LONG_LONG;
- }
- if (g_str_has_prefix (format, "l"))
- {
- return ARG_TYPE_LONG;
- }
- if (g_str_has_prefix (format, "l"))
- {
- return ARG_TYPE_LONG;
- }
- if (g_str_has_prefix (format, "z"))
- {
- return ARG_TYPE_SIZE;
- }
- return ARG_TYPE_INT;
- }
- break;
-
- case 'e':
- case 'E':
- case 'f':
- case 'F':
- case 'g':
- case 'G':
- case 'a':
- case 'A':
- {
- if (g_str_has_prefix (format, "L"))
- {
- return ARG_TYPE_LONG_DOUBLE;
- }
- return ARG_TYPE_DOUBLE;
- }
- break;
-
- case 'c':
- {
- return ARG_TYPE_INT;
- }
- break;
-
- case 's':
- case 'p':
- case 'n':
- {
- return ARG_TYPE_POINTER;
- }
- break;
- }
- return ARG_TYPE_INVALID;
-}
-
-static void
-skip_argv (va_list *va,
- ArgType type,
- EelPrintfHandler *custom_handlers)
-{
- if (type < 0)
- {
- custom_handlers[-type - 1].skip (va);
- return;
- }
-
- switch (type)
- {
- default:
- case ARG_TYPE_INVALID:
- {
- return;
- }
-
- case ARG_TYPE_INT:
- {
- (void) va_arg (*va, int);
- }
- break;
-
- case ARG_TYPE_LONG:
- {
- (void) va_arg (*va, long int);
- }
- break;
-
- case ARG_TYPE_LONG_LONG:
- {
- (void) va_arg (*va, long long int);
- }
- break;
-
- case ARG_TYPE_SIZE:
- {
- (void) va_arg (*va, gsize);
- }
- break;
-
- case ARG_TYPE_LONG_DOUBLE:
- {
- (void) va_arg (*va, long double);
- }
- break;
-
- case ARG_TYPE_DOUBLE:
- {
- (void) va_arg (*va, double);
- }
- break;
-
- case ARG_TYPE_POINTER:
- {
- (void) va_arg (*va, void *);
- }
- break;
- }
-}
-
-static void
-skip_to_arg (va_list *va,
- ArgType *types,
- EelPrintfHandler *custom_handlers,
- int n)
-{
- int i;
- for (i = 0; i < n; i++)
- {
- skip_argv (va, types[i], custom_handlers);
- }
-}
-
-char *
-eel_strdup_vprintf_with_custom (EelPrintfHandler *custom,
- const char *format,
- va_list va_orig)
-{
- va_list va;
- const char *p;
- int num_args, i, j;
- ArgType *args;
- ArgType type;
- ConversionInfo *conversions;
- GString *f, *str;
- const char *flags, *width, *prec, *mod, *pos;
- char *s;
-
- num_args = 0;
- for (p = format; *p != 0; p++)
- {
- if (*p == '%')
- {
- p++;
- if (*p != '%')
- {
- num_args++;
- }
- }
- }
-
- args = g_new0 (ArgType, num_args * 3 + 1);
- conversions = g_new0 (ConversionInfo, num_args);
-
- /* i indexes conversions, j indexes args */
- i = 0;
- j = 0;
- p = format;
- while (*p != 0)
- {
- if (*p != '%')
- {
- p++;
- continue;
- }
- p++;
- if (*p == '%')
- {
- p++;
- continue;
- }
-
- /* We got a real conversion: */
- f = g_string_new ("%");
- conversions[i].start = p - 1;
-
- /* First comes the positional arg */
-
- pos = p;
- p = get_position (p, NULL);
-
- /* Then flags */
- flags = p;
- while (is_flag (*p))
- {
- p++;
- }
- g_string_append_len (f, flags, p - flags);
-
- /* Field width */
-
- if (*p == '*')
- {
- p++;
- p = get_position (p, &j);
- args[j] = ARG_TYPE_INT;
- conversions[i].width_pos = j++;
- conversions[i].width_format_index = f->len;
- }
- else
- {
- conversions[i].width_pos = -1;
- conversions[i].width_format_index = -1;
- width = p;
- while (g_ascii_isdigit (*p))
- {
- p++;
- }
- g_string_append_len (f, width, p - width);
- }
-
- /* Precision */
- conversions[i].precision_pos = -1;
- conversions[i].precision_format_index = -1;
- if (*p == '.')
- {
- g_string_append_c (f, '.');
- p++;
-
- if (*p == '*')
- {
- p++;
- p = get_position (p, &j);
- args[j] = ARG_TYPE_INT;
- conversions[i].precision_pos = j++;
- conversions[i].precision_format_index = f->len;
- }
- else
- {
- prec = p;
- while (g_ascii_isdigit (*p) || *p == '-')
- {
- p++;
- }
- g_string_append_len (f, prec, p - prec);
- }
- }
-
- /* length modifier */
-
- mod = p;
-
- while (is_length_modifier (*p))
- {
- p++;
- }
-
- /* conversion specifier */
- if (*p != 0)
- {
- p++;
- }
-
- g_string_append_len (f, mod, p - mod);
-
- get_position (pos, &j);
- args[j] = get_arg_type_from_format (custom, mod, p - mod);
- conversions[i].arg_pos = j++;
- conversions[i].format = f;
- conversions[i].end = p;
-
- i++;
- }
-
- g_assert (i == num_args);
-
- str = g_string_new ("");
-
- p = format;
- for (i = 0; i < num_args; i++)
- {
- g_string_append_len (str, p, conversions[i].start - p);
- p = conversions[i].end;
-
- if (conversions[i].precision_pos != -1)
- {
- char *val;
-
- G_VA_COPY (va, va_orig);
- skip_to_arg (&va, args, custom, conversions[i].precision_pos);
- val = g_strdup_vprintf ("%d", va);
- va_end (va);
-
- g_string_insert (conversions[i].format,
- conversions[i].precision_format_index,
- val);
-
- g_free (val);
- }
-
- if (conversions[i].width_pos != -1)
- {
- char *val;
-
- G_VA_COPY (va, va_orig);
- skip_to_arg (&va, args, custom, conversions[i].width_pos);
- val = g_strdup_vprintf ("%d", va);
- va_end (va);
-
- g_string_insert (conversions[i].format,
- conversions[i].width_format_index,
- val);
-
- g_free (val);
- }
-
- G_VA_COPY (va, va_orig);
- skip_to_arg (&va, args, custom, conversions[i].arg_pos);
- type = args[conversions[i].arg_pos];
- if (type < 0)
- {
- s = custom[-type - 1].to_string (conversions[i].format->str, va);
- g_string_append (str, s);
- g_free (s);
- }
- else
- {
- g_string_append_vprintf (str, conversions[i].format->str, va);
- }
- va_end (va);
-
- g_string_free (conversions[i].format, TRUE);
- }
- g_string_append (str, p);
-
- g_free (args);
- g_free (conversions);
-
- return g_string_free (str, FALSE);
-}
-
-char *
-eel_strdup_printf_with_custom (EelPrintfHandler *handlers,
- const char *format,
- ...)
-{
- va_list va;
- char *res;
-
- va_start (va, format);
- res = eel_strdup_vprintf_with_custom (handlers, format, va);
- va_end (va);
-
- return res;
-}
-
/*********** refcounted strings ****************/
G_LOCK_DEFINE_STATIC (unique_ref_strs);
@@ -891,82 +462,6 @@ retry_atomic_decrement:
#if !defined (EEL_OMIT_SELF_CHECK)
-static void
-verify_printf (const char *format,
- ...)
-{
- va_list va;
- char *orig, *new;
-
- va_start (va, format);
- orig = g_strdup_vprintf (format, va);
- va_end (va);
-
- va_start (va, format);
- new = eel_strdup_vprintf_with_custom (NULL, format, va);
- va_end (va);
-
- EEL_CHECK_STRING_RESULT (new, orig);
-
- g_free (orig);
-}
-
-static char *
-custom1_to_string (char *format,
- va_list va)
-{
- int i;
-
- i = va_arg (va, int);
-
- return g_strdup_printf ("c1-%d-", i);
-}
-
-static void
-custom1_skip (va_list *va)
-{
- (void) va_arg (*va, int);
-}
-
-static char *
-custom2_to_string (char *format,
- va_list va)
-{
- char *s;
-
- s = va_arg (va, char *);
-
- return g_strdup_printf ("c2-%s-", s);
-}
-
-static void
-custom2_skip (va_list *va)
-{
- (void) va_arg (*va, char *);
-}
-
-static EelPrintfHandler handlers[] =
-{
- { 'N', custom1_to_string, custom1_skip },
- { 'Y', custom2_to_string, custom2_skip },
- { 0 }
-};
-
-static void
-verify_custom (const char *orig,
- const char *format,
- ...)
-{
- char *new;
- va_list va;
-
- va_start (va, format);
- new = eel_strdup_vprintf_with_custom (handlers, format, va);
- va_end (va);
-
- EEL_CHECK_STRING_RESULT (new, orig);
-}
-
void
eel_self_check_string (void)
{
@@ -1035,14 +530,6 @@ eel_self_check_string (void)
EEL_CHECK_STRING_RESULT (eel_str_replace_substring ("fff", "f", "foo"), "foofoofoo");
EEL_CHECK_STRING_RESULT (eel_str_replace_substring ("foofoofoo", "foo", "f"), "fff");
EEL_CHECK_STRING_RESULT (eel_str_replace_substring ("foofoofoo", "f", ""), "oooooo");
-
- verify_printf ("%.*s", 2, "foo");
- verify_printf ("%*.*s", 2, 4, "foo");
- verify_printf ("before %5$*1$.*2$s between %6$*3$.*4$d after",
- 4, 5, 6, 7, "foo", G_PI);
- verify_custom ("c1-42- c2-foo-", "%N %Y", 42, "foo");
- verify_custom ("c1-42- bar c2-foo-", "%N %s %Y", 42, "bar", "foo");
- verify_custom ("c1-42- bar c2-foo-", "%3$N %2$s %1$Y", "foo", "bar", 42);
}
#endif /* !EEL_OMIT_SELF_CHECK */
diff --git a/eel/eel-string.h b/eel/eel-string.h
index 23485104a..91c370aa1 100644
--- a/eel/eel-string.h
+++ b/eel/eel-string.h
@@ -88,18 +88,4 @@ void eel_ref_str_unref (eel_ref_str str);
#define eel_ref_str_peek(__str) ((const char *)(__str))
-
-typedef struct {
- char character;
- char *(*to_string) (char *format, va_list va);
- void (*skip) (va_list *va);
-} EelPrintfHandler;
-
-char *eel_strdup_printf_with_custom (EelPrintfHandler *handlers,
- const char *format,
- ...);
-char *eel_strdup_vprintf_with_custom (EelPrintfHandler *custom,
- const char *format,
- va_list va);
-
#endif /* EEL_STRING_H */