/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* gstring-util : utilities for gstring object */ /* * * Author : * Bertrand Guiheneuf * * Copyright 1999, 2000 HelixCode (http://www.helixcode.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 the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * 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 */ #include #include "gstring-util.h" #include "camel-log.h" #include /** * 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 (g_strdup (string->str) ); } /** * g_string_dichotomy: * @sep : separator * @prefix: pointer to be field by the prefix object * the prefix is not returned when the given pointer is NULL * @suffix: pointer to be field by the suffix object * the suffix is not returned when the given pointer is NULL * * Return the strings before and/or after * the last occurence of the specified separator * * This routine returns the string before and/or after * a character given as an argument. * if the separator is the last character, prefix and/or * suffix is set to NULL and result is set to 'l' * if the separator is not in the list, prefix and/or * suffix is set to NULL and result is set to 'n' * When the operation succedeed, the return value is 'o' * * @Return Value : result of the operation ('o', 'l' or 'n') * **/ gchar g_string_dichotomy (GString *string, gchar sep, GString **prefix, GString **suffix, GStringDichotomyOption options) { gchar *str, *tmp; gint pos, len, first; CAMEL_LOG_FULL_DEBUG (\ "Entering string_dichotomy: \n\tseparator=%c \n\tprefix=%p \n\tsuffix=%p \n\toptions=%ld\n",\ sep, prefix, suffix, options); g_assert (tmp=string->str); len = strlen (tmp); if (!len) { if (prefix) *prefix=NULL; if (suffix) *suffix=NULL; CAMEL_LOG_FULL_DEBUG ("string_dichotomy: string is empty\n"); return 'n'; } first = 0; if ((options & GSTRING_DICHOTOMY_STRIP_LEADING ) && (tmp[first] == sep) ) do {first++;} while ( (first=first) && (tmp[pos]!=sep)); } else { pos = first; do { pos++; } while ((pos=len) ) { if (suffix) *suffix=NULL; if (prefix) *prefix=NULL; CAMEL_LOG_FULL_DEBUG ("string_dichotomy: separator not found\n"); return 'n'; } /* if we have stripped trailing separators, we should */ /* never enter here */ if (pos==len-1) { if (suffix) *suffix=NULL; if (prefix) *prefix=NULL; CAMEL_LOG_FULL_DEBUG ("string_dichotomy: separator is last character\n"); return 'l'; } /* if we have stripped leading separators, we should */ /* never enter here */ if (pos==first) { if (suffix) *suffix=NULL; if (prefix) *prefix=NULL; CAMEL_LOG_FULL_DEBUG ("string_dichotomy: separator is first character\n"); return 'l'; } if (prefix) /* return the prefix */ { str = g_strndup(tmp,pos); *prefix = g_string_new(str); g_free(str); } if (suffix) /* return the suffix */ { str = g_strdup(tmp+pos+1); *suffix = g_string_new(str); g_free(str); } return 'o'; } /** * 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); g_assert(other_string->str); 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: **/ g_string_equal_for_hash (gconstpointer v, gconstpointer v2) { return strcmp ( ((const GString*)v)->str, ((const GString*)v2)->str) == 0; } 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--; CAMEL_LOG_FULL_DEBUG ("g_string_split:: trim options: %d\n", trim_options); 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; CAMEL_LOG_FULL_DEBUG ("**\nentering g_string_trim::\n"); if ((!string) || (!string->str)) return; str = string->str; length = strlen (str); if (!length) return; first_ok = 0; last_ok = length - 1; CAMEL_LOG_FULL_DEBUG ("g_string_trim:: trim_options:%d\n", options); 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++; CAMEL_LOG_FULL_DEBUG ("g_string_trim::\n\t\"%s\":first ok:%d last_ok:%d\n", string->str, first_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); } ef797900afb03f80ce774'>Update claws-mail ports to 3.8.0 releasepawel2011-12-183-19/+23 * - Add LDFLAGS to CONFIGURE_ENV and MAKE_ENV (as it was done with LDFLAGS)amdmi32011-09-241-1/+1 * - update to 3.7.10 releasepawel2011-08-303-8/+8 * Chase libnotify, libproxy and webkit-gtk2 shlib changes, and fix build where ...kwm2011-08-241-0/+1 * - Update to 3.7.9 bugfix releasepawel2011-04-182-8/+8 * - Update my email to FreeBSDpawel2011-03-241-1/+1 * - Update to 3.7.8miwi2010-12-161-2/+3 * Sync to new bsd.autotools.mkade2010-12-041-1/+1 * - Update claws-mail plugins to newest versions from 3.7.7 releasemiwi2010-12-012-7/+8 * Punt autoconf267->autoconf268ade2010-10-161-1/+1 * Autotools update. Read ports/UPDATING 20100915 for details.ade2010-09-161-2/+2 * Bounce PORTREVISION for gettext-related ports. Have fun, ya'll.ade2010-05-311-0/+1 * - Update to 0.25miwi2010-05-162-7/+6 * - update to 1.4.1dinoex2010-03-281-1/+1 * - Update to 3.7.5miwi2010-02-081-3/+3 * - update to jpeg-8dinoex2010-02-051-0/+1 * - Update to 0.24miwi2010-01-223-6/+21 * - Update to 0.23miwi2009-11-283-7/+7 * Add/Update WWW records in pkg-descr filesskreuzer2009-08-051-0/+2 * - bump all port that indirectly depends on libjpeg and have not yet been bump...dinoex2009-07-311-0/+1 * - Update to 0.22miwi2009-07-053-6/+8 * - Update to 0.21miwi2009-03-072-6/+6 * - Update to 0.20miwi2009-01-123-6/+7 * Conversion from (now defunct) autoconf-2.61 to autoconf-2.62ade2008-08-201-1/+1 * - Update to 0.17miwi2008-06-283-18/+24 * Bump portrevision due to upgrade of devel/gettext.edwin2008-06-061-0/+1 * - Update to 0.16miwi2008-04-202-8/+8 * - Get rid of USE_XLIBmiwi2008-03-221-2/+1 * - Bump PORTREVISION after claws-mail updatemiwi2008-02-281-2/+3 * - Update to 0.15miwi2008-02-132-8/+10 * - Bump PORTREVISION after claws-mail updatemiwi2007-10-021-1/+1 * - File was rerolledmiwi2007-09-182-3/+4 * - Update to 0.12.1miwi2007-09-113-14/+4 * - Update to 0.12miwi2007-09-073-7/+17 * - Bump PORTREVISION after claws-mail updatemiwi2007-09-071-3/+3 * - Install translation filesmiwi2007-07-101-1/+11 * - Update to 0.11miwi2007-07-073-14/+10 * - Update to 2.9.2miwi2007-05-291-1/+1 * - Welcome X.org 7.2 \o/.flz2007-05-201-1/+1 * - Update to 2.9.1miwi2007-04-191-0/+1 * - Update to 0.10miwi2007-04-183-10/+11 * - Update CM to 2.8.1.netchild2007-03-121-0/+2 * - Update to 0.9miwi2007-03-012-6/+5 * - Update CM to 2.8.0.netchild2007-02-281-1/+1 * - Update CM to 2.7.2, themes to 20070116.netchild2007-01-271-1/+1 * Update CM to 2.7.1 and bump the revision of the plugins.netchild2007-01-161-0/+1 * update to 0.8itetcu2007-01-122-5/+4 * Update claws-mail to 2.7.0.netchild2007-01-101-0/+1 * sylpheed-claws was renamed upstream to claws-mail. Compleate repocopies ofitetcu2006-12-312-13/+12 * - Update SC to 2.6.0.netchild2006-12-041-1/+2 * - Update to 0.6miwi2006-11-092-4/+4 * - Update to 0.5miwi2006-09-302-6/+6 * - Update to 0.3miwi2006-08-092-4/+4 * - update to 0.2.1itetcu2006-06-212-5/+5 * - update to version 0.1.2garga2006-05-103-19/+4