/*=====================================================================================================================
                    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 <string>
#include <map>
#include <vector>
using namespace std;
#ifdef __cplusplus
    extern "C"
    {
#endif

// @{{ String assister
#define IS_NULL(S)   ((S)==NULL)
#define IS_EMPTY(S)  (((S)==NULL) || !(*(S)))
// @}}
		void Split( string strArg, string spliter, vector<string> &ans );
    /**
    * Clones the string.
    * @param dst - <OF> the output string.
    * @param src - <I>  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 - <O> the output string.
    * @param src - <I>  the string to be cloned.
    * @param dstSize - <I> 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   - <OF> the output string.
    * @param value - <I>  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      - <O> the destination string.
    * @param digitNum - <I> the digit number of the value.
    * @param value    - <I> 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 - <I> string 1
    * @param s2 - <I> string 2
    * @return - <OF> new string
    */
    extern char* GSTR_string_append( const char *s1, const char *s2 );

    /**
    * Whether the string is float type
    * @param str   - <I> 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   - <I> 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 - <I> ascii char
    * @return - return true if it is.
    */
    extern logical GSTR_is_ascii(char ch);

    /**
    * Trims the string's prefix.
    * @param str - <I> The string
    * @param s   - <I> 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 );

#ifdef __cplusplus
    }
#endif


#endif //STRING_UTILS_H
