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 #include "c_private.h"
00037 #include "c_macro.h"
00038 
00039 #include <stdlib.h>
00040 
00041 struct c_strlist_s; typedef struct c_strlist_s c_strlist_t;
00042 
00043 /**
00044  * @brief Structure for a stringlist
00045  *
00046  * Using a for loop you can access the strings saved in the vector.
00047  *
00048  * c_strlist_t strlist;
00049  * int i;
00050  * for (i = 0; i < strlist->count; i++) {
00051  *   printf("value: %s", strlist->vector[i];
00052  * }
00053  */
00054 struct c_strlist_s {
00055   /** The string vector */
00056   char **vector;
00057   /** The count of the strings saved in the vector */
00058   size_t count;
00059   /** Size of strings allocated */
00060   size_t size;
00061 };
00062 
00063 /**
00064  * @brief Compare to strings if they are equal.
00065  *
00066  * @param a  First string to compare.
00067  * @param b  Second string to compare.
00068  *
00069  * @return  1 if they are equal, 0 if not.
00070  */
00071 int c_streq(const char *a, const char *b);
00072 
00073 /**
00074  * @brief Create a new stringlist.
00075  *
00076  * @param size  Size to allocate.
00077  *
00078  * @return  Pointer to the newly allocated stringlist. NULL if an error occured.
00079  */
00080 c_strlist_t *c_strlist_new(size_t size);
00081 
00082 /**
00083  * @brief Expand the stringlist
00084  *
00085  * @param strlist  Stringlist to expand
00086  * @param size     New size of the strlinglist to expand
00087  *
00088  * @return  Pointer to the expanded stringlist. NULL if an error occured.
00089  */
00090 c_strlist_t *c_strlist_expand(c_strlist_t *strlist, size_t size);
00091 
00092 /**
00093  * @brief  Add a string to the stringlist.
00094  *
00095  * Duplicates the string and stores it in the stringlist.
00096  *
00097  * @param strlist  Stringlist to add the string.
00098  * @param string   String to add.
00099  *
00100  * @return  0 on success, less than 0 and errno set if an error occured.
00101  *          ENOBUFS if the list is full.
00102  */
00103 int c_strlist_add(c_strlist_t *strlist, const char *string);
00104 
00105 /**
00106  * @brief Destroy the memory of the stringlist.
00107  *
00108  * Frees the strings and the stringlist.
00109  *
00110  * @param strlist  Stringlist to destroy
00111  */
00112 void c_strlist_destroy(c_strlist_t *strlist);
00113 
00114 /**
00115  * @breif Replace a string with another string in a source string.
00116  *
00117  * @param src      String to search for pattern.
00118  *
00119  * @param pattern  Pattern to search for in the source string.
00120  *
00121  * @param repl     The string which which should replace pattern if found.
00122  *
00123  * @return  Return a pointer to the source string.
00124  */
00125 char *c_strreplace(char *src, const char *pattern, const char *repl);
00126 
00127 /**
00128  * @brief Uppercase a string.
00129  *
00130  * @param  str     The String to uppercase.
00131  *
00132  * @return The malloced uppered string or NULL on error.
00133  */
00134 char *c_uppercase(const char* str);
00135 
00136 /**
00137  * @brief Lowercase a string.
00138  *
00139  * @param  str     The String to lowercase.
00140  *
00141  * @return The malloced lowered string or NULL on error.
00142  */
00143 char *c_lowercase(const char* str);
00144 
00145 /**
00146  * @brief Convert a multibyte string to utf8 (Win32).
00147  *
00148  * @param  str     The multibyte encoded string to convert
00149  *
00150  * @return The malloced converted string or NULL on error.
00151  */
00152  char*   c_utf8(const _TCHAR *str);
00153 
00154 /**
00155  * @brief Convert a utf8 encoded string to multibyte (Win32).
00156  *
00157  * @param  str     The utf8 string to convert.
00158  *
00159  * @return The malloced converted multibyte string or NULL on error.
00160  */
00161 _TCHAR* c_multibyte(const char *wstr);
00162 
00163 #if defined(_WIN32) || defined(WITH_ICONV)
00164 /**
00165  * @brief Free buffer malloced by c_multibyte.
00166  *
00167  * @param  buf     The buffer to free.
00168  */
00169 
00170 #define c_free_multibyte(x) SAFE_FREE(x)
00171 
00172 /**
00173  * @brief Free buffer malloced by c_utf8.
00174  *
00175  * @param  buf     The buffer to free.
00176  *
00177  */
00178 #define c_free_utf8(x) SAFE_FREE(x)
00179 #else
00180 #define c_free_multibyte(x) (void)x
00181 #define c_free_utf8(x) (void)x
00182 #endif
00183 
00184 
00185 /**
00186  * }@
00187  */
00188 #endif /* _C_STR_H */
00189 

Generated on Mon Aug 18 13:58:05 2014 for doc by  doxygen 1.5.6