sprint 1-alpha
|
00001 /****************************************************************************** 00002 * SPRINT::utils::string 00003 * 00004 * Copyright (C) 2005-2010 Paolo Medici <www.pmx.it> 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * This library 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 GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 * 00020 *******************************************************************************/ 00021 00022 #ifndef _SPRINT_UTILS_STRING_H 00023 #define _SPRINT_UTILS_STRING_H 00024 00028 #include "hex.h" 00029 00030 #ifdef __cplusplus 00031 extern "C" { 00032 #endif 00033 00034 #include <stdio.h> 00035 00036 #define PARSE_UNKNOWN -1 00037 00041 int strlistcmp(const char *string, const char **list); 00042 00046 int strlisticmp(const char *string, const char **list); 00047 00053 int strlistcmpex(const char *string, const char **list); 00054 00055 int strarraycmp(const char *string, const char **array, unsigned int nitem); 00056 00058 void strtolower(char *str); 00060 char *remove_endl(char *src); 00061 00064 int findendl(char *src, int pos); 00065 00068 int remove_lastchar(char *buffer); 00069 00083 unsigned int parse_vector(void *data, const char *str, unsigned int item_size); 00084 00086 unsigned int parse_byte_vector(unsigned char *ptr, const char *str, unsigned int max_item); 00087 00090 unsigned int parse_hexbyte_vector(unsigned char *ptr, const char *str, unsigned int max_item); 00091 unsigned int hextoarray(const char *hex, unsigned char *array, unsigned int array_size); 00092 00095 unsigned int flagtoui(const char *src); 00097 unsigned int itoflag(char *buffer, unsigned int flag); 00098 00103 int parse_bitvector(const char *string); 00104 00106 unsigned int parse_stringvector(const char *string, const char **list); 00107 00111 int split_string(char *string, char **argv, unsigned int max_argc); 00112 00118 char *compose_string(char *buffer, unsigned int buf_size, const char **argv, unsigned int argc, char sep=' '); 00119 00120 00121 00126 char *strnav(char **_string); 00127 00128 int split_assign(char *string, char **data); 00129 void split_assign_special(char *line, char **data); 00130 00131 const char *skip_to_next_line(const char *ptr); 00132 00134 char *skipspace(char *src); 00135 00140 char *reverseskipspace(char *src); 00141 00144 char *splitstr(char *src, char separator); 00145 00146 /* ******************************************************* */ 00147 00148 bool atobool(const char* iBool); 00149 00150 const char *find_next_valid_line(const char *buffer); 00151 int count_valid_line(const char *buffer); 00152 int split_txt_buffer(char *buffer, char **ptr, int list_size); 00153 00154 /* ******************************************************* */ 00155 const char *memchrr(const char *src, char c, int len); 00156 int crlfstr(char *dst, const char *src, int line_size); 00157 00162 const char *strextract(char *out, const char *src); 00163 00168 int memextract(char *out, const char *src, int max_len); 00169 00182 const char *strccpy(char *varbuffer, const char *ptr, int character, int buf_size); 00183 00187 char *strcpyv(char *dst, char *src); 00188 00190 void smemcpy(char *dst, char *src, char *end); 00191 00193 char *memrnchr(char *start, char c); 00194 00196 char *nstrchr(char *start, char c); 00197 00199 int strcount(char *string, int c); 00200 00201 /* ******************************************************* */ 00202 00203 typedef int (* EXTERNALPARAMPROC) (void *param, const char *variable); 00204 00214 int parse_formula(const char *formula, EXTERNALPARAMPROC proc, void *param); 00215 00216 00220 int strcmpex(const char *src, const char *target); 00221 int stricmpex(const char *src, const char *target); 00222 00226 int strword(const char *src, const char *target); 00227 00230 int strwildcardcmp(const char *src, const char *target); 00231 00232 #define CMP_DIFFERENT 0 00233 #define CMP_EQUAL 1 00234 #define CMP_SRC_MORE_LONG 2 00235 #define CMP_TRG_MORE_LONG 3 00236 00237 /* *********************************************************** */ 00238 00242 char *fcfgparse(char *buffer, unsigned int buffer_size, FILE *fp); 00243 00244 #ifdef __cplusplus 00245 } 00246 #endif 00247 00249 00250 #ifdef __cplusplus 00251 00253 class CFormula { 00254 private: 00255 int parse(const char **data); 00256 public: 00257 virtual ~CFormula() {} 00258 virtual int get(const char *variable) = 0; 00259 00260 int operator() (const char *formula) 00261 { 00262 return parse(&formula); 00263 } 00264 }; 00265 00266 00267 #endif 00268 00269 #endif 00270