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

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