Remove a ton of useless snot.
2002-10-31 Jeffrey Stedfast <fejj@ximian.com> Remove a ton of useless snot. * Makefile.am: Remove gstring-util.[c,h] from the build. * gstring-util.[c,h]: Removed. * string-utils.c (string_equal_for_glist): Removed. (string_split): Removed. (string_trim): Removed. (string_prefix): Removed. (string_unquote): Removed. (strip): Removed. * hash-table-utils.c (g_hash_table_generic_free): Removed. g_str[n]casecmp functions are deprecated in glib2. * string-utils.c (strstrcase): Use strncasecmp instead of g_strncasecmp. * hash-table-utils.c (g_strcase_equal): Use strcasecmp instead of g_strcasecmp. * camel-smime-utils.c (camel_smime_is_smime_v3_signed): Same. (camel_smime_is_smime_v3_encrypted): Here too. * camel-sasl-digest-md5.c (decode_data_type): And here. (parse_server_challenge): Again here. * camel-pgp-mime.c (camel_pgp_mime_is_rfc2015_signed): Same. (camel_pgp_mime_is_rfc2015_encrypted): Same * camel-mime-part-utils.c (check_html_charset): Here too. * camel-folder-summary.c (camel_system_flag): Same. svn path=/trunk/; revision=18472
This commit is contained in:

committed by
Jeffrey Stedfast

parent
613453b109
commit
f48db35928
@ -1,3 +1,41 @@
|
|||||||
|
2002-10-31 Jeffrey Stedfast <fejj@ximian.com>
|
||||||
|
|
||||||
|
Remove a ton of useless snot.
|
||||||
|
|
||||||
|
* Makefile.am: Remove gstring-util.[c,h] from the build.
|
||||||
|
|
||||||
|
* gstring-util.[c,h]: Removed.
|
||||||
|
|
||||||
|
* string-utils.c (string_equal_for_glist): Removed.
|
||||||
|
(string_split): Removed.
|
||||||
|
(string_trim): Removed.
|
||||||
|
(string_prefix): Removed.
|
||||||
|
(string_unquote): Removed.
|
||||||
|
(strip): Removed.
|
||||||
|
|
||||||
|
* hash-table-utils.c (g_hash_table_generic_free): Removed.
|
||||||
|
|
||||||
|
g_str[n]casecmp functions are deprecated in glib2.
|
||||||
|
|
||||||
|
* string-utils.c (strstrcase): Use strncasecmp instead of
|
||||||
|
g_strncasecmp.
|
||||||
|
|
||||||
|
* hash-table-utils.c (g_strcase_equal): Use strcasecmp
|
||||||
|
instead of g_strcasecmp.
|
||||||
|
|
||||||
|
* camel-smime-utils.c (camel_smime_is_smime_v3_signed): Same.
|
||||||
|
(camel_smime_is_smime_v3_encrypted): Here too.
|
||||||
|
|
||||||
|
* camel-sasl-digest-md5.c (decode_data_type): And here.
|
||||||
|
(parse_server_challenge): Again here.
|
||||||
|
|
||||||
|
* camel-pgp-mime.c (camel_pgp_mime_is_rfc2015_signed): Same.
|
||||||
|
(camel_pgp_mime_is_rfc2015_encrypted): Same
|
||||||
|
|
||||||
|
* camel-mime-part-utils.c (check_html_charset): Here too.
|
||||||
|
|
||||||
|
* camel-folder-summary.c (camel_system_flag): Same.
|
||||||
|
|
||||||
2002-10-25 Jeffrey Stedfast <fejj@ximian.com>
|
2002-10-25 Jeffrey Stedfast <fejj@ximian.com>
|
||||||
|
|
||||||
* camel-gpg-context.c (gpg_ctx_parse_status): Don't prematurely
|
* camel-gpg-context.c (gpg_ctx_parse_status): Don't prematurely
|
||||||
|
@ -114,7 +114,6 @@ libcamel_la_SOURCES = \
|
|||||||
camel-vee-store.c \
|
camel-vee-store.c \
|
||||||
camel-vtrash-folder.c \
|
camel-vtrash-folder.c \
|
||||||
camel.c \
|
camel.c \
|
||||||
gstring-util.c \
|
|
||||||
hash-table-utils.c \
|
hash-table-utils.c \
|
||||||
string-utils.c
|
string-utils.c
|
||||||
|
|
||||||
@ -214,7 +213,6 @@ libcamelinclude_HEADERS = \
|
|||||||
camel-vee-store.h \
|
camel-vee-store.h \
|
||||||
camel-vtrash-folder.h \
|
camel-vtrash-folder.h \
|
||||||
camel.h \
|
camel.h \
|
||||||
gstring-util.h \
|
|
||||||
hash-table-utils.h \
|
hash-table-utils.h \
|
||||||
string-utils.h
|
string-utils.h
|
||||||
|
|
||||||
|
@ -2482,7 +2482,7 @@ camel_system_flag (const char *name)
|
|||||||
g_return_val_if_fail (name != NULL, 0);
|
g_return_val_if_fail (name != NULL, 0);
|
||||||
|
|
||||||
for (flag = flag_names; *flag->name; flag++)
|
for (flag = flag_names; *flag->name; flag++)
|
||||||
if (!g_strcasecmp (name, flag->name))
|
if (!strcasecmp (name, flag->name))
|
||||||
return flag->value;
|
return flag->value;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -81,9 +81,9 @@ check_html_charset(char *buffer, int length)
|
|||||||
case CAMEL_HTML_PARSER_ELEMENT:
|
case CAMEL_HTML_PARSER_ELEMENT:
|
||||||
val = camel_html_parser_tag(hp);
|
val = camel_html_parser_tag(hp);
|
||||||
d(printf("Got tag: %s\n", val));
|
d(printf("Got tag: %s\n", val));
|
||||||
if (g_strcasecmp(val, "meta") == 0
|
if (strcasecmp(val, "meta") == 0
|
||||||
&& (val = camel_html_parser_attr(hp, "http-equiv"))
|
&& (val = camel_html_parser_attr(hp, "http-equiv"))
|
||||||
&& g_strcasecmp(val, "content-type") == 0
|
&& strcasecmp(val, "content-type") == 0
|
||||||
&& (val = camel_html_parser_attr(hp, "content"))
|
&& (val = camel_html_parser_attr(hp, "content"))
|
||||||
&& (ct = header_content_type_decode(val))) {
|
&& (ct = header_content_type_decode(val))) {
|
||||||
charset = header_content_type_param(ct, "charset");
|
charset = header_content_type_param(ct, "charset");
|
||||||
|
@ -63,7 +63,7 @@ camel_pgp_mime_is_rfc2015_signed (CamelMimePart *mime_part)
|
|||||||
#ifdef ENABLE_PEDANTIC_PGPMIME
|
#ifdef ENABLE_PEDANTIC_PGPMIME
|
||||||
/* check that we have a protocol param with the value: "application/pgp-signature" */
|
/* check that we have a protocol param with the value: "application/pgp-signature" */
|
||||||
param = header_content_type_param (type, "protocol");
|
param = header_content_type_param (type, "protocol");
|
||||||
if (!param || g_strcasecmp (param, "application/pgp-signature"))
|
if (!param || strcasecmp (param, "application/pgp-signature"))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
/* check that we have a micalg parameter */
|
/* check that we have a micalg parameter */
|
||||||
@ -126,7 +126,7 @@ camel_pgp_mime_is_rfc2015_encrypted (CamelMimePart *mime_part)
|
|||||||
#ifdef ENABLE_PEDANTIC_PGPMIME
|
#ifdef ENABLE_PEDANTIC_PGPMIME
|
||||||
/* check that we have a protocol param with the value: "application/pgp-encrypted" */
|
/* check that we have a protocol param with the value: "application/pgp-encrypted" */
|
||||||
param = header_content_type_param (type, "protocol");
|
param = header_content_type_param (type, "protocol");
|
||||||
if (!param || g_strcasecmp (param, "application/pgp-encrypted"))
|
if (!param || strcasecmp (param, "application/pgp-encrypted"))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
#endif /* ENABLE_PEDANTIC_PGPMIME */
|
#endif /* ENABLE_PEDANTIC_PGPMIME */
|
||||||
|
|
||||||
|
@ -360,7 +360,7 @@ decode_data_type (DataType *dtype, const char *name)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; dtype[i].name; i++) {
|
for (i = 0; dtype[i].name; i++) {
|
||||||
if (!g_strcasecmp (dtype[i].name, name))
|
if (!strcasecmp (dtype[i].name, name))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -467,7 +467,7 @@ parse_server_challenge (const char *tokens, gboolean *abort)
|
|||||||
break;
|
break;
|
||||||
case DIGEST_STALE:
|
case DIGEST_STALE:
|
||||||
PARANOID (digest_abort (&got_stale, abort));
|
PARANOID (digest_abort (&got_stale, abort));
|
||||||
if (!g_strcasecmp (param->value, "true"))
|
if (!strcasecmp (param->value, "true"))
|
||||||
challenge->stale = TRUE;
|
challenge->stale = TRUE;
|
||||||
else
|
else
|
||||||
challenge->stale = FALSE;
|
challenge->stale = FALSE;
|
||||||
|
@ -53,7 +53,7 @@ camel_smime_is_smime_v3_signed (CamelMimePart *mime_part)
|
|||||||
|
|
||||||
/* check that we have a protocol param with the value: "application/pkcs7-signature" */
|
/* check that we have a protocol param with the value: "application/pkcs7-signature" */
|
||||||
param = header_content_type_param (type, "protocol");
|
param = header_content_type_param (type, "protocol");
|
||||||
if (!param || g_strcasecmp (param, "application/pkcs7-signature"))
|
if (!param || strcasecmp (param, "application/pkcs7-signature"))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
/* check that we have a micalg parameter */
|
/* check that we have a micalg parameter */
|
||||||
@ -109,7 +109,7 @@ camel_smime_is_smime_v3_encrypted (CamelMimePart *mime_part)
|
|||||||
param = header_content_type_param (type, "name");
|
param = header_content_type_param (type, "name");
|
||||||
if (param && *param && strlen (param) > 4) {
|
if (param && *param && strlen (param) > 4) {
|
||||||
for (i = 0; types[i]; i++)
|
for (i = 0; types[i]; i++)
|
||||||
if (!g_strcasecmp (param + strlen (param)-4, types[i]))
|
if (!strcasecmp (param + strlen (param)-4, types[i]))
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,7 +117,7 @@ camel_smime_is_smime_v3_encrypted (CamelMimePart *mime_part)
|
|||||||
filename = camel_mime_part_get_filename (mime_part);
|
filename = camel_mime_part_get_filename (mime_part);
|
||||||
if (filename && *filename && strlen (filename) > 4) {
|
if (filename && *filename && strlen (filename) > 4) {
|
||||||
for (i = 0; types[i]; i++)
|
for (i = 0; types[i]; i++)
|
||||||
if (!g_strcasecmp (filename + strlen (filename)-4, types[i]))
|
if (!strcasecmp (filename + strlen (filename)-4, types[i]))
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,216 +0,0 @@
|
|||||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
|
|
||||||
/* gstring-util : utilities for gstring object */
|
|
||||||
|
|
||||||
/*
|
|
||||||
*
|
|
||||||
* Author :
|
|
||||||
* Bertrand Guiheneuf <bertrand@helixcode.com>
|
|
||||||
*
|
|
||||||
* Copyright 1999, 2000 Ximian, Inc. (www.ximian.com)
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of version 2 of the GNU General Public
|
|
||||||
* License as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
||||||
* USA
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
|
||||||
#include <config.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include "gstring-util.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* g_string_equals : test if two string are equal
|
|
||||||
*
|
|
||||||
* @string1 : first string
|
|
||||||
* @string2 : second string
|
|
||||||
*
|
|
||||||
* @Return Value : true if the strings equal, false otherwise
|
|
||||||
**/
|
|
||||||
gboolean
|
|
||||||
g_string_equals (GString *string1, GString *string2)
|
|
||||||
{
|
|
||||||
g_assert (string1);
|
|
||||||
g_assert (string2);
|
|
||||||
return !strcmp (string1->str, string2->str);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* g_string_clone : clone a GString
|
|
||||||
*
|
|
||||||
* @string : the string to clone
|
|
||||||
*
|
|
||||||
* @Return Value : the clone ...
|
|
||||||
**/
|
|
||||||
GString *
|
|
||||||
g_string_clone (GString *string)
|
|
||||||
{
|
|
||||||
return g_string_new (string->str);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* g_string_append_g_string : append a GString to another GString
|
|
||||||
*
|
|
||||||
* @dest_string : string which will be appended
|
|
||||||
* @other_string : string to append
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
void
|
|
||||||
g_string_append_g_string(GString *dest_string, GString *other_string)
|
|
||||||
{
|
|
||||||
g_assert(other_string);
|
|
||||||
g_assert(dest_string);
|
|
||||||
|
|
||||||
if (other_string->len)
|
|
||||||
g_string_append(dest_string, other_string->str);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* g_string_equal_for_hash: test equality of two GStrings for hash tables
|
|
||||||
* @v: string 1
|
|
||||||
* @v2: string 2
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* Return value:
|
|
||||||
**/
|
|
||||||
gint
|
|
||||||
g_string_equal_for_hash (gconstpointer v, gconstpointer v2)
|
|
||||||
{
|
|
||||||
return strcmp ( ((const GString*)v)->str, ((const GString*)v2)->str) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
gint
|
|
||||||
g_string_equal_for_glist (gconstpointer v, gconstpointer v2)
|
|
||||||
{
|
|
||||||
return !strcmp ( ((const GString*)v)->str, ((const GString*)v2)->str) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* g_string_hash: computes a hash value for a Gstring
|
|
||||||
* @v: Gstring object
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* Return value:
|
|
||||||
**/
|
|
||||||
guint
|
|
||||||
g_string_hash (gconstpointer v)
|
|
||||||
{
|
|
||||||
return g_str_hash(((const GString*)v)->str);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* utility func : frees a GString element in a GList */
|
|
||||||
static void
|
|
||||||
__g_string_list_free_string (gpointer data, gpointer user_data)
|
|
||||||
{
|
|
||||||
GString *string = (GString *)data;
|
|
||||||
g_string_free(string, TRUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
g_string_list_free (GList *string_list)
|
|
||||||
{
|
|
||||||
g_list_foreach(string_list, __g_string_list_free_string, NULL);
|
|
||||||
g_list_free(string_list);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GList *
|
|
||||||
g_string_split (GString *string, char sep, gchar *trim_chars, GStringTrimOption trim_options)
|
|
||||||
{
|
|
||||||
GList *result = NULL;
|
|
||||||
gint first, last, pos;
|
|
||||||
gchar *str;
|
|
||||||
gchar *new_str;
|
|
||||||
GString *new_gstring;
|
|
||||||
|
|
||||||
g_assert (string);
|
|
||||||
str = string->str;
|
|
||||||
if (!str) return NULL;
|
|
||||||
|
|
||||||
first = 0;
|
|
||||||
last = strlen(str) - 1;
|
|
||||||
|
|
||||||
/* strip leading and trailing separators */
|
|
||||||
while ( (first<=last) && (str[first]==sep) )
|
|
||||||
first++;
|
|
||||||
while ( (first<=last) && (str[last]==sep) )
|
|
||||||
last--;
|
|
||||||
|
|
||||||
|
|
||||||
while (first<=last) {
|
|
||||||
pos = first;
|
|
||||||
/* find next separator */
|
|
||||||
while ((pos<=last) && (str[pos]!=sep)) pos++;
|
|
||||||
if (first != pos) {
|
|
||||||
new_str = g_strndup (str+first, pos-first);
|
|
||||||
new_gstring = g_string_new (new_str);
|
|
||||||
g_free (new_str);
|
|
||||||
/* could do trimming in line to speed up this code */
|
|
||||||
if (trim_chars) g_string_trim (new_gstring, trim_chars, trim_options);
|
|
||||||
result = g_list_append (result, new_gstring);
|
|
||||||
}
|
|
||||||
first = pos + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
g_string_trim (GString *string, gchar *chars, GStringTrimOption options)
|
|
||||||
{
|
|
||||||
gint first_ok;
|
|
||||||
gint last_ok;
|
|
||||||
guint length;
|
|
||||||
gchar *str;
|
|
||||||
|
|
||||||
if ((!string) || (!string->str))
|
|
||||||
return;
|
|
||||||
str = string->str;
|
|
||||||
length = strlen (str);
|
|
||||||
if (!length)
|
|
||||||
return;
|
|
||||||
|
|
||||||
first_ok = 0;
|
|
||||||
last_ok = length - 1;
|
|
||||||
|
|
||||||
if (options & GSTRING_TRIM_STRIP_LEADING)
|
|
||||||
while ( (first_ok <= last_ok) && (strchr (chars, str[first_ok])) )
|
|
||||||
first_ok++;
|
|
||||||
|
|
||||||
if (options & GSTRING_TRIM_STRIP_TRAILING)
|
|
||||||
while ( (first_ok <= last_ok) && (strchr (chars, str[last_ok])) )
|
|
||||||
last_ok++;
|
|
||||||
|
|
||||||
if (first_ok > 0)
|
|
||||||
g_string_erase (string, 0, first_ok);
|
|
||||||
|
|
||||||
if (last_ok < length-1)
|
|
||||||
g_string_truncate (string, last_ok - first_ok +1);
|
|
||||||
|
|
||||||
}
|
|
@ -1,65 +0,0 @@
|
|||||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
|
|
||||||
/* gstring-util : utilities for gstring object */
|
|
||||||
|
|
||||||
/*
|
|
||||||
*
|
|
||||||
* Author :
|
|
||||||
* Bertrand Guiheneuf <bertrand@helixcode.com>
|
|
||||||
*
|
|
||||||
* Copyright 1999, 2000 Ximian, Inc. (www.ximian.com)
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of version 2 of the GNU General Public
|
|
||||||
* License as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
||||||
* USA
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef GSTRING_UTIL_H
|
|
||||||
#define GSTRING_UTIL_H 1
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#pragma }
|
|
||||||
#endif /* __cplusplus }*/
|
|
||||||
|
|
||||||
#include <glib.h>
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
GSTRING_TRIM_NONE = 0,
|
|
||||||
GSTRING_TRIM_STRIP_TRAILING = 1,
|
|
||||||
GSTRING_TRIM_STRIP_LEADING = 2
|
|
||||||
} GStringTrimOption;
|
|
||||||
|
|
||||||
|
|
||||||
gboolean g_string_equals (GString *string1, GString *string2);
|
|
||||||
GString *g_string_clone (GString *string);
|
|
||||||
void g_string_append_g_string (GString *dest_string,
|
|
||||||
GString *other_string);
|
|
||||||
|
|
||||||
gboolean g_string_equal_for_hash (gconstpointer v, gconstpointer v2);
|
|
||||||
gboolean g_string_equal_for_glist (gconstpointer v, gconstpointer v2);
|
|
||||||
guint g_string_hash (gconstpointer v);
|
|
||||||
void g_string_list_free (GList *string_list);
|
|
||||||
|
|
||||||
GList *g_string_split (GString *string, char sep,
|
|
||||||
gchar *trim_chars, GStringTrimOption trim_options);
|
|
||||||
void g_string_trim (GString *string, gchar *chars,
|
|
||||||
GStringTrimOption options);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
#endif /* GSTRING_UTIL_H */
|
|
@ -23,31 +23,20 @@
|
|||||||
* USA
|
* USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
#include "hash-table-utils.h"
|
#include "hash-table-utils.h"
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* free a (key/value) hash table pair.
|
|
||||||
* to be called in a g_hash_table_foreach()
|
|
||||||
* before g_hash_table_destroy().
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
g_hash_table_generic_free (gpointer key, gpointer value, gpointer user_data)
|
|
||||||
{
|
|
||||||
g_free (key);
|
|
||||||
g_free (value);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/***/
|
/***/
|
||||||
/* use these two funcs for case insensitive hash table */
|
/* use these two funcs for case insensitive hash table */
|
||||||
|
|
||||||
gint
|
gint
|
||||||
g_strcase_equal (gconstpointer a, gconstpointer b)
|
g_strcase_equal (gconstpointer a, gconstpointer b)
|
||||||
{
|
{
|
||||||
return (g_strcasecmp ((gchar *)a, (gchar *)b) == 0);
|
return (strcasecmp ((char *) a, (char *) b) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -70,9 +59,5 @@ g_strcase_hash (gconstpointer v)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return h /* % M */;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/***/
|
|
||||||
|
@ -35,8 +35,6 @@ extern "C" {
|
|||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
void g_hash_table_generic_free (gpointer key, gpointer value, gpointer user_data);
|
|
||||||
|
|
||||||
gint g_strcase_equal (gconstpointer a, gconstpointer b);
|
gint g_strcase_equal (gconstpointer a, gconstpointer b);
|
||||||
guint g_strcase_hash (gconstpointer v);
|
guint g_strcase_hash (gconstpointer v);
|
||||||
|
|
||||||
|
@ -1,16 +1,13 @@
|
|||||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
|
||||||
/* string-util : utilities for gchar* strings */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
* Authors: Jeffrey Stedfast <fejj@ximian.com>
|
||||||
*
|
*
|
||||||
* Authors: Bertrand Guiheneuf <bertrand@helixcode.com>
|
* Copyright 2002 Ximian, Inc. (www.ximian.com)
|
||||||
* Jeffrey Stedfast <fejj@ximian.com>
|
|
||||||
*
|
*
|
||||||
* Copyright 1999, 2000 Ximian, Inc. (www.ximian.com)
|
* This program is free software; you can redistribute it and/or modify
|
||||||
*
|
* it under the terms of the GNU General Public License as published by
|
||||||
* This program is free software; you can redistribute it and/or
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
* modify it under the terms of version 2 of the GNU General Public
|
* (at your option) any later version.
|
||||||
* License as published by the Free Software Foundation.
|
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
@ -19,192 +16,34 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
* Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
|
||||||
* USA
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "string-utils.h"
|
#include "string-utils.h"
|
||||||
#include "string.h"
|
|
||||||
|
|
||||||
gboolean
|
|
||||||
string_equal_for_glist (gconstpointer v, gconstpointer v2)
|
|
||||||
{
|
|
||||||
return (!strcmp ( ((const gchar *)v), ((const gchar*)v2))) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* utility func : frees a gchar element in a GList */
|
|
||||||
static void
|
static void
|
||||||
__string_list_free_string (gpointer data, gpointer user_data)
|
free_string (gpointer string, gpointer user_data)
|
||||||
{
|
{
|
||||||
gchar *string = (gchar *)data;
|
|
||||||
g_free (string);
|
g_free (string);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
string_list_free (GList *string_list)
|
string_list_free (GList *string_list)
|
||||||
{
|
{
|
||||||
if (string_list == NULL) return;
|
if (string_list == NULL)
|
||||||
|
|
||||||
g_list_foreach (string_list, __string_list_free_string, NULL);
|
|
||||||
g_list_free (string_list);
|
|
||||||
}
|
|
||||||
|
|
||||||
GList *
|
|
||||||
string_split (const gchar *string, char sep, const gchar *trim_chars, StringTrimOption trim_options)
|
|
||||||
{
|
|
||||||
GList *result = NULL;
|
|
||||||
gint first, last, pos;
|
|
||||||
gchar *new_string;
|
|
||||||
|
|
||||||
g_assert (string);
|
|
||||||
|
|
||||||
first = 0;
|
|
||||||
last = strlen(string) - 1;
|
|
||||||
|
|
||||||
/* strip leading and trailing separators */
|
|
||||||
while ( (first<=last) && (string[first]==sep) )
|
|
||||||
first++;
|
|
||||||
while ( (first<=last) && (string[last]==sep) )
|
|
||||||
last--;
|
|
||||||
|
|
||||||
|
|
||||||
while (first<=last) {
|
|
||||||
pos = first;
|
|
||||||
/* find next separator */
|
|
||||||
while ((pos<=last) && (string[pos]!=sep)) pos++;
|
|
||||||
if (first != pos) {
|
|
||||||
new_string = g_strndup (string+first, pos-first);
|
|
||||||
/* could do trimming in line to speed up this code */
|
|
||||||
if (trim_chars) string_trim (new_string, trim_chars, trim_options);
|
|
||||||
result = g_list_append (result, new_string);
|
|
||||||
}
|
|
||||||
first = pos + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
string_trim (gchar *string, const gchar *trim_chars, StringTrimOption options)
|
|
||||||
{
|
|
||||||
gint first_ok;
|
|
||||||
gint last_ok;
|
|
||||||
guint length;
|
|
||||||
|
|
||||||
g_return_if_fail (string);
|
|
||||||
length = strlen (string);
|
|
||||||
if (length==0)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
first_ok = 0;
|
g_list_foreach (string_list, free_string, NULL);
|
||||||
last_ok = length - 1;
|
g_list_free (string_list);
|
||||||
|
|
||||||
if (options & STRING_TRIM_STRIP_LEADING)
|
|
||||||
while ( (first_ok <= last_ok) && (strchr (trim_chars, string[first_ok])!=NULL) )
|
|
||||||
first_ok++;
|
|
||||||
|
|
||||||
if (options & STRING_TRIM_STRIP_TRAILING)
|
|
||||||
while ( (first_ok <= last_ok) && (strchr (trim_chars, string[last_ok])!=NULL) )
|
|
||||||
last_ok--;
|
|
||||||
|
|
||||||
if (first_ok > 0)
|
|
||||||
memmove (string, string+first_ok, last_ok - first_ok + 1);
|
|
||||||
string[last_ok - first_ok +1] = '\0';
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* remove_suffix: remove a suffix from a string
|
|
||||||
* @s: the string to remove the suffix from.
|
|
||||||
* @suffix: the suffix to remove
|
|
||||||
* @suffix_found : suffix found flag
|
|
||||||
*
|
|
||||||
* Remove a suffix from a string. If the
|
|
||||||
* string ends with the full suffix, a copy
|
|
||||||
* of the string without the suffix is returned and
|
|
||||||
* @suffix_found is set to %TRUE.
|
|
||||||
* Otherwise, NULL is returned and
|
|
||||||
* @suffix_found is set to %FALSE.
|
|
||||||
*
|
|
||||||
* Return value: an allocated copy of the string without the suffix or NULL if the suffix was not found.
|
|
||||||
**/
|
|
||||||
gchar *
|
|
||||||
string_prefix (const gchar *s, const gchar *suffix, gboolean *suffix_found)
|
|
||||||
{
|
|
||||||
guint s_len, suf_len;
|
|
||||||
guint suffix_pos;
|
|
||||||
char *result_string;
|
|
||||||
|
|
||||||
g_assert (s);
|
|
||||||
g_assert (suffix);
|
|
||||||
g_assert (suffix_found);
|
|
||||||
|
|
||||||
s_len = strlen (s);
|
|
||||||
suf_len = strlen (suffix);
|
|
||||||
|
|
||||||
/* if the string is shorter than the suffix, do nothing */
|
|
||||||
if (s_len < suf_len) {
|
|
||||||
*suffix_found = FALSE;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* theoretical position of the prefix */
|
|
||||||
suffix_pos = s_len - suf_len;
|
|
||||||
|
|
||||||
/* compare the right hand side of the string with the suffix */
|
|
||||||
if (!strncmp (s+suffix_pos, suffix, suf_len)) {
|
|
||||||
|
|
||||||
/* if the suffix matches, check that there are
|
|
||||||
characters before */
|
|
||||||
if (suffix_pos == 0) {
|
|
||||||
result_string = NULL;
|
|
||||||
*suffix_found = TRUE;
|
|
||||||
} else {
|
|
||||||
result_string = g_strndup (s, suffix_pos);
|
|
||||||
*suffix_found = TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
result_string = NULL;
|
|
||||||
*suffix_found = FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result_string;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
string_unquote (gchar *string)
|
|
||||||
{
|
|
||||||
/* if the string is quoted, unquote it */
|
|
||||||
|
|
||||||
g_return_if_fail (string != NULL);
|
|
||||||
|
|
||||||
if (*string == '"' && *(string + strlen (string) - 1) == '"') {
|
|
||||||
*(string + strlen (string) - 1) = '\0';
|
|
||||||
if (*string)
|
|
||||||
memmove (string, string+1, strlen (string));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
gchar *
|
|
||||||
strip (gchar *string, gchar c)
|
|
||||||
{
|
|
||||||
/* strip all occurances of c from the string */
|
|
||||||
gchar *src, *dst;
|
|
||||||
|
|
||||||
g_return_val_if_fail (string != NULL, NULL);
|
|
||||||
|
|
||||||
for (src = dst = string; *src; src++)
|
|
||||||
if (*src != c)
|
|
||||||
*dst++ = *src;
|
|
||||||
*dst = '\0';
|
|
||||||
|
|
||||||
return string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
@ -225,7 +64,7 @@ strstrcase (const char *haystack, const char *needle)
|
|||||||
return (char *) haystack;
|
return (char *) haystack;
|
||||||
|
|
||||||
for (ptr = haystack; *(ptr + len - 1) != '\0'; ptr++)
|
for (ptr = haystack; *(ptr + len - 1) != '\0'; ptr++)
|
||||||
if (!g_strncasecmp (ptr, needle, len))
|
if (!strncasecmp (ptr, needle, len))
|
||||||
return (char *) ptr;
|
return (char *) ptr;
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -1,16 +1,13 @@
|
|||||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
|
||||||
/* string-util : utilities for normal gchar * strings */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
* Authors: Jeffrey Stedfast <fejj@ximian.com>
|
||||||
*
|
*
|
||||||
* Authors: Bertrand Guiheneuf <bertrand@helixcode.com>
|
* Copyright 2002 Ximian, Inc. (www.ximian.com)
|
||||||
* Jeffrey Stedfast <fejj@ximian.com>
|
|
||||||
*
|
*
|
||||||
* Copyright 1999, 2000 Ximian, Inc. (www.ximian.com)
|
* This program is free software; you can redistribute it and/or modify
|
||||||
*
|
* it under the terms of the GNU General Public License as published by
|
||||||
* This program is free software; you can redistribute it and/or
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
* modify it under the terms of version 2 of the GNU General Public
|
* (at your option) any later version.
|
||||||
* License as published by the Free Software Foundation.
|
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
@ -19,47 +16,23 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
* Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
|
||||||
* USA
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef STRING_UTIL_H
|
#ifndef STRING_UTIL_H
|
||||||
#define STRING_UTIL_H 1
|
#define STRING_UTIL_H 1
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#pragma }
|
#pragma }
|
||||||
#endif /* __cplusplus }*/
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
STRING_TRIM_NONE = 0,
|
|
||||||
STRING_TRIM_STRIP_TRAILING = 1,
|
|
||||||
STRING_TRIM_STRIP_LEADING = 2
|
|
||||||
} StringTrimOption;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
gboolean string_equal_for_glist (gconstpointer v, gconstpointer v2);
|
|
||||||
|
|
||||||
void string_list_free (GList *string_list);
|
void string_list_free (GList *string_list);
|
||||||
|
|
||||||
GList *string_split (const gchar *string, char sep,
|
|
||||||
const gchar *trim_chars, StringTrimOption trim_options);
|
|
||||||
void string_trim (gchar *string, const gchar *chars,
|
|
||||||
StringTrimOption options);
|
|
||||||
|
|
||||||
gchar *string_prefix (const gchar *s, const gchar *suffix,
|
|
||||||
gboolean *suffix_found);
|
|
||||||
|
|
||||||
void string_unquote (gchar *string);
|
|
||||||
|
|
||||||
gchar *strip (gchar *string, gchar c);
|
|
||||||
|
|
||||||
char *strstrcase (const char *haystack, const char *needle);
|
char *strstrcase (const char *haystack, const char *needle);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
Reference in New Issue
Block a user