diff options
author | bertrand <Bertrand.Guiheneuf@inria.fr> | 1999-04-18 18:44:38 +0800 |
---|---|---|
committer | Bertrand Guiheneuf <bertrand@src.gnome.org> | 1999-04-18 18:44:38 +0800 |
commit | 0057293c1cb3f3d001ba3dd262ac3e715378452a (patch) | |
tree | 2f7899e813d6a8bf2237c18729889f45020e6632 /camel/gstring-util.c | |
parent | 8fcb90785fb673c5dc14c36b54af45502ae65b83 (diff) | |
download | gsoc2013-evolution-0057293c1cb3f3d001ba3dd262ac3e715378452a.tar gsoc2013-evolution-0057293c1cb3f3d001ba3dd262ac3e715378452a.tar.gz gsoc2013-evolution-0057293c1cb3f3d001ba3dd262ac3e715378452a.tar.bz2 gsoc2013-evolution-0057293c1cb3f3d001ba3dd262ac3e715378452a.tar.lz gsoc2013-evolution-0057293c1cb3f3d001ba3dd262ac3e715378452a.tar.xz gsoc2013-evolution-0057293c1cb3f3d001ba3dd262ac3e715378452a.tar.zst gsoc2013-evolution-0057293c1cb3f3d001ba3dd262ac3e715378452a.zip |
some work log system for camel some utilities for GString objects
1999-04-18 bertrand <Bertrand.Guiheneuf@inria.fr>
* camel/camel-folder.c: some work
* camel/camel-log.c: log system for camel
* camel/gstring-util.c: some utilities for GString objects
Work on obmail translation.
Bertrand
svn path=/trunk/; revision=851
Diffstat (limited to 'camel/gstring-util.c')
-rw-r--r-- | camel/gstring-util.c | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/camel/gstring-util.c b/camel/gstring-util.c new file mode 100644 index 0000000000..9a1357babd --- /dev/null +++ b/camel/gstring-util.c @@ -0,0 +1,159 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* gstring-util : utilities for gstring object */ + +/* + * + * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@inria.fr> . + * + * 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 "gstring-util.h" +#include "camel-log.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( g_strdup(string->str) ); +} + + + + +/** + * right_dichotomy : 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' + * + * @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 Value : result of the operation ('o', 'l' or 'n') + * + **/ +gchar +g_string_right_dichotomy( GString *string, gchar sep, GString **prefix, GString **suffix, DichotomyOption options) +{ + gchar *str, *tmp; + gint pos, len, first; + + CAMEL_LOG(FULL_DEBUG,\ + "Entering rightDichotomy: \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,"rightDichotomy: string is empty\n"); + return 'n'; + } + first = 0; + + if ( (options & STRIP_LEADING ) && (tmp[first] == sep) ) + do {first++;} while ( (first<len) && (tmp[first] == sep) ); + + if (options & STRIP_TRAILING ) + while (tmp[len-1] == sep) + len--; + + if (first==len) { + if (prefix) *prefix=NULL; + if (suffix) *suffix=NULL; + CAMEL_LOG(FULL_DEBUG,"rightDichotomy: after stripping, string is empty\n"); + return 'n'; + } + + pos = len; + + do { + pos--; + } while ((pos>=first) && (tmp[pos]!=sep)); + + + if (pos<first) + { + if (suffix) *suffix=NULL; + if (prefix) *prefix=NULL; + CAMEL_LOG(FULL_DEBUG,"rightDichotomy: separator not found\n"); + return 'n'; + } + + /* if we have stripped trailongs separators, we should */ + /* never enter here */ + if (pos==len-1) + { + if (suffix) *suffix=NULL; + if (prefix) *prefix=NULL; + CAMEL_LOG(FULL_DEBUG,"rightDichotomy: separator is last 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'; +} + |