c_string.h

Go to the documentation of this file.
00001 /*
00002  * cynapses libc functions
00003  *
00004  * Copyright (c) 2008 by Andreas Schneider <mail@cynapses.org>
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00019  *
00020  * vim: ts=2 sw=2 et cindent
00021  */
00022 
00023 /**
00024  * @file c_string.h
00025  *
00026  * @brief Interface of the cynapses string implementations
00027  *
00028  * @defgroup cynStringInternals cynapses libc string functions
00029  * @ingroup cynLibraryAPI
00030  *
00031  * @{
00032  */
00033 #ifndef _C_STR_H
00034 #define _C_STR_H
00035 
00036 struct c_strlist_s; typedef struct c_strlist_s c_strlist_t;
00037 
00038 /**
00039  * @brief Structure for a stringlist
00040  *
00041  * Using a for loop you can access the strings saved in the vector.
00042  *
00043  * c_strlist_t strlist;
00044  * int i;
00045  * for (i = 0; i < strlist->count; i++) {
00046  *   printf("value: %s", strlist->vector[i];
00047  * }
00048  */
00049 struct c_strlist_s {
00050   /** The string vector */
00051   char **vector;
00052   /** The count of the strings saved in the vector */
00053   size_t count;
00054   /** Size of strings allocated */
00055   size_t size;
00056 };
00057 
00058 /**
00059  * @brief Compare to strings if they are equal.
00060  *
00061  * @param a  First string to compare.
00062  * @param b  Second string to compare.
00063  *
00064  * @return  1 if they are equal, 0 if not.
00065  */
00066 int c_streq(const char *a, const char *b);
00067 
00068 /**
00069  * @brief Create a new stringlist.
00070  *
00071  * @param size  Size to allocate.
00072  *
00073  * @return  Pointer to the newly allocated stringlist. NULL if an error occured.
00074  */
00075 c_strlist_t *c_strlist_new(size_t size);
00076 
00077 /**
00078  * @brief Expand the stringlist
00079  *
00080  * @param strlist  Stringlist to expand
00081  * @param size     New size of the strlinglist to expand
00082  *
00083  * @return  Pointer to the expanded stringlist. NULL if an error occured.
00084  */
00085 c_strlist_t *c_strlist_expand(c_strlist_t *strlist, size_t size);
00086 
00087 /**
00088  * @brief  Add a string to the stringlist.
00089  *
00090  * Duplicates the string and stores it in the stringlist.
00091  *
00092  * @param strlist  Stringlist to add the string.
00093  * @param string   String to add.
00094  *
00095  * @return  0 on success, less than 0 and errno set if an error occured.
00096  *          ENOBUFS if the list is full.
00097  */
00098 int c_strlist_add(c_strlist_t *strlist, const char *string);
00099 
00100 /**
00101  * @brief Destroy the memory of the stringlist.
00102  *
00103  * Frees the strings and the stringlist.
00104  *
00105  * @param strlist  Stringlist to destroy
00106  */
00107 void c_strlist_destroy(c_strlist_t *strlist);
00108 
00109 /**
00110  * @breif Replace a string with another string in a source string.
00111  *
00112  * @param src      String to search for pattern.
00113  *
00114  * @param pattern  Pattern to search for in the source string.
00115  *
00116  * @param repl     The string which which should replace pattern if found.
00117  *
00118  * @return  Return a pointer to the source string.
00119  */
00120 char *c_strreplace(char *src, const char *pattern, const char *repl);
00121 
00122 /**
00123  * @brief Uppercase a string.
00124  *
00125  * @param  str     The String to uppercase.
00126  *
00127  * @return The malloced uppered string or NULL on error.
00128  */
00129 char *c_uppercase(const char* str);
00130 
00131 /**
00132  * @brief Lowercase a string.
00133  *
00134  * @param  str     The String to lowercase.
00135  *
00136  * @return The malloced lowered string or NULL on error.
00137  */
00138 char *c_lowercase(const char* str);
00139 
00140 /**
00141  * }@
00142  */
00143 #endif /* _C_STR_H */
00144 

Generated on Mon May 4 17:43:35 2009 for doc by  doxygen 1.5.6