remove some dead code
This commit is contained in:
@ -39,7 +39,11 @@ mu_date_str_s (const char* frm, time_t t)
|
||||
g_return_val_if_fail (frm, NULL);
|
||||
|
||||
tmbuf = localtime(&t);
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
||||
len = strftime (buf, sizeof(buf) - 1, frm, tmbuf);
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
if (len == 0)
|
||||
return ""; /* not necessarily an error... */
|
||||
|
||||
|
||||
@ -22,6 +22,9 @@
|
||||
#include "config.h"
|
||||
#endif /*HAVE_CONFIG_H*/
|
||||
|
||||
#ifndef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE (500)
|
||||
#endif /*_XOPEN_SOURCE*/
|
||||
|
||||
#include <glib.h>
|
||||
#include <string.h>
|
||||
@ -38,7 +41,7 @@ mu_str_size_s (size_t s)
|
||||
static char buf[32];
|
||||
char *tmp;
|
||||
|
||||
tmp = g_format_size_for_display ((goffset)s);
|
||||
tmp = g_format_size((goffset)s);
|
||||
strncpy (buf, tmp, sizeof(buf));
|
||||
buf[sizeof(buf) -1] = '\0'; /* just in case */
|
||||
g_free (tmp);
|
||||
@ -46,13 +49,6 @@ mu_str_size_s (size_t s)
|
||||
return buf;
|
||||
}
|
||||
|
||||
char*
|
||||
mu_str_size (size_t s)
|
||||
{
|
||||
return g_strdup (mu_str_size_s(s));
|
||||
}
|
||||
|
||||
|
||||
char*
|
||||
mu_str_summarize (const char* str, size_t max_lines)
|
||||
{
|
||||
@ -94,34 +90,6 @@ mu_str_summarize (const char* str, size_t max_lines)
|
||||
return summary;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
char*
|
||||
mu_str_replace (const char *str, const char *substr, const char *repl)
|
||||
{
|
||||
GString *gstr;
|
||||
const char *cur;
|
||||
|
||||
g_return_val_if_fail (str, NULL);
|
||||
g_return_val_if_fail (substr, NULL);
|
||||
g_return_val_if_fail (repl, NULL);
|
||||
|
||||
gstr = g_string_sized_new (2 * strlen (str));
|
||||
|
||||
for (cur = str; *cur; ++cur) {
|
||||
if (g_str_has_prefix (cur, substr)) {
|
||||
g_string_append (gstr, repl);
|
||||
cur += strlen (substr) - 1;
|
||||
} else
|
||||
g_string_append_c (gstr, *cur);
|
||||
}
|
||||
|
||||
return g_string_free (gstr, FALSE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
char*
|
||||
mu_str_from_list (const GSList *lst, char sepa)
|
||||
{
|
||||
@ -179,69 +147,6 @@ mu_str_to_list (const char *str, char sepa, gboolean strip)
|
||||
return lst;
|
||||
}
|
||||
|
||||
GSList*
|
||||
mu_str_esc_to_list (const char *strings)
|
||||
{
|
||||
GSList *lst;
|
||||
GString *part;
|
||||
unsigned u;
|
||||
gboolean quoted, escaped;
|
||||
|
||||
g_return_val_if_fail (strings, NULL);
|
||||
|
||||
part = g_string_new (NULL);
|
||||
|
||||
for (u = 0, lst = NULL, quoted = FALSE, escaped = FALSE;
|
||||
u != strlen (strings); ++u) {
|
||||
|
||||
char kar;
|
||||
kar = strings[u];
|
||||
|
||||
if (kar == '\\') {
|
||||
if (escaped)
|
||||
g_string_append_c (part, '\\');
|
||||
escaped = !escaped;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (quoted && kar != '"') {
|
||||
g_string_append_c (part, kar);
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (kar) {
|
||||
case '"':
|
||||
if (!escaped)
|
||||
quoted = !quoted;
|
||||
else
|
||||
g_string_append_c (part, kar);
|
||||
continue;
|
||||
case ' ':
|
||||
if (part->len > 0) {
|
||||
lst = g_slist_prepend
|
||||
(lst, g_string_free (part, FALSE));
|
||||
part = g_string_new (NULL);
|
||||
}
|
||||
continue;
|
||||
default:
|
||||
g_string_append_c (part, kar);
|
||||
}
|
||||
}
|
||||
|
||||
if (part->len)
|
||||
lst = g_slist_prepend (lst, g_string_free (part, FALSE));
|
||||
|
||||
return g_slist_reverse (lst);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
mu_str_free_list (GSList *lst)
|
||||
{
|
||||
g_slist_foreach (lst, (GFunc)g_free, NULL);
|
||||
g_slist_free (lst);
|
||||
}
|
||||
|
||||
|
||||
/* this function is critical for sorting performance; therefore, no
|
||||
* regexps, but just some good old c pointer magic */
|
||||
@ -306,34 +211,6 @@ mu_str_fullpath_s (const char* path, const char* name)
|
||||
}
|
||||
|
||||
|
||||
char*
|
||||
mu_str_escape_c_literal (const gchar* str, gboolean in_quotes)
|
||||
{
|
||||
const char* cur;
|
||||
GString *tmp;
|
||||
|
||||
g_return_val_if_fail (str, NULL);
|
||||
|
||||
tmp = g_string_sized_new (2 * strlen(str));
|
||||
|
||||
if (in_quotes)
|
||||
g_string_append_c (tmp, '"');
|
||||
|
||||
for (cur = str; *cur; ++cur)
|
||||
switch (*cur) {
|
||||
case '\\': tmp = g_string_append (tmp, "\\\\"); break;
|
||||
case '"': tmp = g_string_append (tmp, "\\\""); break;
|
||||
default: tmp = g_string_append_c (tmp, *cur);
|
||||
}
|
||||
|
||||
if (in_quotes)
|
||||
g_string_append_c (tmp, '"');
|
||||
|
||||
return g_string_free (tmp, FALSE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* turn \0-terminated buf into ascii (which is a utf8 subset); convert
|
||||
* any non-ascii into '.'
|
||||
*/
|
||||
|
||||
@ -40,8 +40,6 @@ G_BEGIN_DECLS
|
||||
* 10-based SI units, _not_ the powers-of-2 based ones.
|
||||
*
|
||||
* mu_str_size_s returns a ptr to a static buffer,
|
||||
* while mu_str_size returns dynamically allocated
|
||||
* memory that must be freed after use.
|
||||
*
|
||||
* @param t the size as an size_t
|
||||
*
|
||||
@ -49,20 +47,6 @@ G_BEGIN_DECLS
|
||||
* for what to do with it
|
||||
*/
|
||||
const char* mu_str_size_s (size_t s);
|
||||
char* mu_str_size (size_t s) G_GNUC_WARN_UNUSED_RESULT;
|
||||
|
||||
|
||||
/**
|
||||
* Replace all occurrences of substr in str with repl
|
||||
*
|
||||
* @param str a string
|
||||
* @param substr some string to replace
|
||||
* @param repl a replacement string
|
||||
*
|
||||
* @return a newly allocated string with the substr replaced by repl; free with g_free
|
||||
*/
|
||||
char *mu_str_replace (const char *str, const char *substr, const char *repl);
|
||||
|
||||
|
||||
/**
|
||||
* get a 'summary' of the string, ie. the first /n/ lines of the
|
||||
@ -87,18 +71,6 @@ char* mu_str_summarize (const char* str, size_t max_lines)
|
||||
*/
|
||||
const char* mu_str_fullpath_s (const char* path, const char* name);
|
||||
|
||||
/**
|
||||
* escape a string like a string literal in C; ie. replace \ with \\,
|
||||
* and " with \"
|
||||
*
|
||||
* @param str a non-NULL str
|
||||
* @param in_quotes whether the result should be enclosed in ""
|
||||
*
|
||||
* @return the escaped string, newly allocated (free with g_free)
|
||||
*/
|
||||
char* mu_str_escape_c_literal (const gchar* str, gboolean in_quotes)
|
||||
G_GNUC_WARN_UNUSED_RESULT;
|
||||
|
||||
/**
|
||||
* turn a string into plain ascii by replacing each non-ascii
|
||||
* character with a dot ('.'). Replacement is done in-place.
|
||||
@ -162,24 +134,12 @@ char* mu_str_from_list (const GSList *lst, char sepa);
|
||||
*/
|
||||
GSList* mu_str_to_list (const char *str, char sepa, gboolean strip);
|
||||
|
||||
/**
|
||||
* convert a string (with possible escaping) to a list. list items are
|
||||
* separated by one or more spaces. list items can be quoted (using
|
||||
* '"').
|
||||
*
|
||||
* @param str a string
|
||||
*
|
||||
* @return a list of elements or NULL in case of error, free with
|
||||
* mu_str_free_list
|
||||
*/
|
||||
GSList* mu_str_esc_to_list (const char *str);
|
||||
|
||||
/**
|
||||
* free a GSList consisting of allocated strings
|
||||
*
|
||||
* @param lst a GSList
|
||||
*/
|
||||
void mu_str_free_list (GSList *lst);
|
||||
#define mu_str_free_list(lst) g_slist_free_full(lst, g_free)
|
||||
|
||||
/**
|
||||
* strip the subject of Re:, Fwd: etc.
|
||||
|
||||
@ -23,9 +23,11 @@
|
||||
#include <config.h>
|
||||
#endif /*HAVE_CONFIG_H*/
|
||||
|
||||
#include "mu-util.h"
|
||||
#define _XOPEN_SOURCE 500
|
||||
#ifndef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE (500)
|
||||
#endif /*_XOPEN_SOURCE*/
|
||||
|
||||
#include "mu-util.h"
|
||||
#ifdef HAVE_WORDEXP_H
|
||||
#include <wordexp.h> /* for shell-style globbing */
|
||||
#endif /*HAVE_WORDEXP_H*/
|
||||
|
||||
@ -32,73 +32,6 @@
|
||||
|
||||
#include "mu-str.h"
|
||||
|
||||
|
||||
static void
|
||||
test_mu_str_size_01 (void)
|
||||
{
|
||||
struct lconv *lc;
|
||||
char *tmp2;
|
||||
|
||||
lc = localeconv();
|
||||
|
||||
g_assert_cmpstr (mu_str_size_s (0), ==, "0 bytes");
|
||||
|
||||
tmp2 = g_strdup_printf ("97%s7 KB", lc->decimal_point);
|
||||
g_assert_cmpstr (mu_str_size_s (100000), ==, tmp2);
|
||||
g_free (tmp2);
|
||||
|
||||
tmp2 = g_strdup_printf ("1%s0 MB", lc->decimal_point);
|
||||
g_assert_cmpstr (mu_str_size_s (1100*1000), ==, tmp2);
|
||||
g_free (tmp2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
test_mu_str_size_02 (void)
|
||||
{
|
||||
struct lconv *lc;
|
||||
char *tmp1, *tmp2;
|
||||
|
||||
lc = localeconv();
|
||||
|
||||
tmp2 = g_strdup_printf ("1%s0 MB", lc->decimal_point);
|
||||
tmp1 = mu_str_size (999999);
|
||||
g_assert_cmpstr (tmp1, !=, tmp2);
|
||||
|
||||
g_free (tmp1);
|
||||
g_free (tmp2);
|
||||
}
|
||||
|
||||
static void
|
||||
test_mu_str_esc_to_list (void)
|
||||
{
|
||||
int i;
|
||||
struct {
|
||||
const char* str;
|
||||
const char* strs[3];
|
||||
} strings [] = {
|
||||
{ "maildir:foo",
|
||||
{"maildir:foo", NULL, NULL}},
|
||||
{ "maildir:sent items",
|
||||
{"maildir:sent", "items", NULL}},
|
||||
{ "\"maildir:sent items\"",
|
||||
{"maildir:sent items", NULL, NULL}},
|
||||
};
|
||||
|
||||
for (i = 0; i != G_N_ELEMENTS(strings); ++i) {
|
||||
GSList *lst, *cur;
|
||||
unsigned u;
|
||||
lst = mu_str_esc_to_list (strings[i].str);
|
||||
for (cur = lst, u = 0; cur; cur = g_slist_next(cur), ++u)
|
||||
g_assert_cmpstr ((const char*)cur->data,==,
|
||||
strings[i].strs[u]);
|
||||
mu_str_free_list (lst);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
assert_cmplst (GSList *lst, const char *items[])
|
||||
{
|
||||
@ -189,33 +122,6 @@ test_mu_str_to_list_strip (void)
|
||||
mu_str_free_list (lst);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
test_mu_str_replace (void)
|
||||
{
|
||||
unsigned u;
|
||||
struct {
|
||||
const char* str;
|
||||
const char* sub;
|
||||
const char *repl;
|
||||
const char *exp;
|
||||
} strings [] = {
|
||||
{ "hello", "ll", "xx", "hexxo" },
|
||||
{ "hello", "hello", "hi", "hi" },
|
||||
{ "hello", "foo", "bar", "hello" }
|
||||
};
|
||||
|
||||
for (u = 0; u != G_N_ELEMENTS(strings); ++u) {
|
||||
char *res;
|
||||
res = mu_str_replace (strings[u].str,
|
||||
strings[u].sub,
|
||||
strings[u].repl);
|
||||
g_assert_cmpstr (res,==,strings[u].exp);
|
||||
g_free (res);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
test_mu_str_remove_ctrl_in_place (void)
|
||||
{
|
||||
@ -248,12 +154,6 @@ main (int argc, char *argv[])
|
||||
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
|
||||
/* mu_str_size */
|
||||
g_test_add_func ("/mu-str/mu-str-size-01",
|
||||
test_mu_str_size_01);
|
||||
g_test_add_func ("/mu-str/mu-str-size-02",
|
||||
test_mu_str_size_02);
|
||||
|
||||
g_test_add_func ("/mu-str/mu-str-from-list",
|
||||
test_mu_str_from_list);
|
||||
g_test_add_func ("/mu-str/mu-str-to-list",
|
||||
@ -261,12 +161,6 @@ main (int argc, char *argv[])
|
||||
g_test_add_func ("/mu-str/mu-str-to-list-strip",
|
||||
test_mu_str_to_list_strip);
|
||||
|
||||
g_test_add_func ("/mu-str/mu-str-replace",
|
||||
test_mu_str_replace);
|
||||
|
||||
g_test_add_func ("/mu-str/mu-str-esc-to-list",
|
||||
test_mu_str_esc_to_list);
|
||||
|
||||
g_test_add_func ("/mu-str/mu_str_remove_ctrl_in_place",
|
||||
test_mu_str_remove_ctrl_in_place);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user