日期:2014-05-16 浏览次数:21029 次
/////////////////////////////////////////////// Spliter //////////////////////////////////////////////
/**
 * This class used to split string according to the delimiter.The string which wanted to be splited shall
 * not be changed after splited.
 */
class CSpliter
{
public:
    CSpliter(void);
    /**
     * CSpliter object constructor.
     * @param [in]    apcDelimiter        a pointer pointed to the string which used as delimiter.
     * @param [in]    abIsSkipBlankField  a flag specifies if the null character shall save.
     */
    CSpliter( char const* apcDelimiter, bool abIsSkipBlankField = true );
    /**
     * This function used to specify the delimiter.
     * @param [in]    apcDelimiter        a pointer pointed to the string which used as delimiter.
     * @param [in]    abIsSkipBlankField  a flag specifies if the null character shall save.
     */
    void Delimiter ( char const* apcDelimiter, bool abIsSkipBlankField = true );
    /**
     * This function used to set the preserve area.The area shall identify by the begin and end character.
     * @param [in]    acStart    specifies the start character of the preserve area.
     * @param [in]    acStop     specifies the end character of the preserve area.
     * @param [in]    abIsStrip  specifies if the area's edge shall remain or not.
     * @retval 0    successful.
     */
    apl_int_t Preserve( char acStart, char acStop, bool abIsStrip = true );
    ~CSpliter(void);
    /**
     * This function shall split the string pointed by apcInput.
     * @param [in]    apcInput    a pointer pointed to the string which wanted to be splited.
     * @retval >=0    This value specifies the number of parts the string splited.
     */
    apl_ssize_t Parse( char const* apcInput );
    /**
     * Overloaded function.
     * @param [in]    aoInput   the string which wanted to be splited.
     * @retval >=0    This value specifies the number of parts the string splited.
     */
    apl_ssize_t Parse( std::string const& aoInput );
    /**
     * This function shall get the number of parts the string which is the first argment of the function Parse() splited.
     * @retval >=0     This value specifies the number of parts the string is splited.
     */
    apl_size_t GetSize(void) const;
    /**
     * This function shall get the specific part of the string which has been splited.
     * @param [in]    aiN    specifies the location of the substrig which wanted to be got.
     * @retval null    Get substring fail.
     * @retval >0      Get substring successfully, the return value is a pointer pointed to the substring.
     */
    char const* GetField( apl_size_t aiN );
protected:
    bool IsDelimiter( char const* apcInput ) const;
    bool IsPreserve( char acStart, char& acStop, bool& abIsStrip ) const;
    void GetToken( apl_size_t aiFieldID, char const* apcFirst, apl_size_t aiLen );
    CSpliter& operator = ( CSpliter const& );
    CSpliter( CSpliter const& );
private:
    struct CPreserve
    {
        char mcStart;
        char mcStop;
        bool mbIsStrip;
    };
    std::string moDelimiter;
    bool mbIsSkipBlankFie