/*===================================================================================================================== Copyright(c) 2005 ORIGIN PLM Software Corp. All rights reserved. Unpublished - All rights reserved ======================================================================================================================= File description: Filename: string_utils.h Module : Common module. This file includes some operations of the string. ======================================================================================================================= Date Name Description of Change 14-Jul-2009 Ray Li Initialize creation $HISTORY$ =====================================================================================================================*/ #ifndef STRING_UTILS_H #define STRING_UTILS_H #include #include #include #include #include #include using namespace std; #ifdef __cplusplus extern "C" { #endif // @{{ String assister #define IS_NULL(S) ((S)==NULL) #define IS_EMPTY(S) (((S)==NULL) || !(*(S))) // @}} extern void Split( string strArg, string spliter, vector &ans ); //extern void Split(string strArg, char spliter, vector &ans); /** * Clones the string. * @param dst - the output string. * @param src - the string to be cloned. * @return - the destinatin string pointer. */ extern char* GSTR_clone( char **dst, const char *src ); /** * Copy safely the string with null end. * @param dst - the output string. * @param src - the string to be cloned. * @param dstSize - the size of output string. * @return - the destinatin string pointer. */ extern char *GSTR_copy( char *dst, const char *src, int dstSize ); /** * Converts int to string. * @param dst - the output string. * @param value - the int to be cloned. * @return - the destinatin string pointer. */ extern char* GSTR_int_to_string( char **dst, int value ); /** * Formats the int/string value as string. * @param dst - the destination string. * @param digitNum - the digit number of the value. * @param value - the value to be converted. * @return - N/A. */ extern void GSTR_format_int_to_string( char *dst, int digitNum, int value ); extern void GSTR_format_string( const char *dst, int m, const char *fill_char, char **out ); /** * Appends the strings( never null returned ) * @param s1 - string 1 * @param s2 - string 2 * @return - new string */ extern char* GSTR_string_append( const char *s1, const char *s2 ); /** * Whether the string is float type * @param str - The string * * NOTE: it's only check whether each word is in "+-.0123456789", not care the float with "E" or the float rule, * like "00-1.+01", it will return true. * @return - return true if it is one. */ extern logical GSTR_is_float(const char *str); /** * Whether all char of the string are number * @param str - The string * * NOTE: it's only check whether each word is in "0123456789" * @return - return true if it is one. */ extern logical GSTR_is_number(const char *str); /** * Is ascii char * @param ch - ascii char * @return - return true if it is. */ extern logical GSTR_is_ascii(char ch); /** * Trims the string's prefix. * @param str - The string * @param s - The char * * @return - count. */ extern int GSTR_trim_l( char *str, char s ); extern int GSTR_trim_r( char *str, char s ); /** * Remove the zero. * For Example: * floatValue="50.00" -> = "50" * floatValue="50.0100" -> = "50.01" * @return - count. */ extern void GSTR_trim_float( char *floatValue ); /** * contains * if contains return 0, else return 1 * @return - count. */ extern int contains(const char *parent, char target); extern bool contains1(char **array, char *str); extern bool contains2(char **array, int len, const char *str); bool contains3(vector array, const char *str); string replace(string str, string s1, string s2); string stringToUTF8(const std::string str); string GbkToUtf8(const char *src_str); string Utf8ToGbk(const char *src_str); void createDir(); #ifdef __cplusplus } #endif #endif //STRING_UTILS_H