eis/inc/base/ByteTool.h

249 lines
9.0 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*********************************************************************
*
* 文 件: ByteTool.h 提供字符串的操作
*
* 版权所有: Shanghai Baosight Software Co., Ltd.
*
* 概述:
* :
* :
*
* 版本历史
* 1.0 2010-09-02 echo_li 增加注释
* modify 2010-12-23 rmbai add char fill functions
*
*********************************************************************/
#ifndef _H_BYTETOOL_H
#define _H_BYTETOOL_H
#ifndef _WIN32
#include <iconv.h>
#endif
#include <stdio.h>
#include <ctype.h>
#include <stdarg.h>
#include <vector>
#include <string>
#include <stdlib.h>
using namespace std;
namespace baosight
{
/*********************************************************************
* 类 名: ByteTool
* 版权所有: Shanghai Baosight Software Co., Ltd.
* 类 职 责:提供移除字符串空格,字符串比较等
* :
* :
* 版本历史
* 1.0 2010-09-02 echo_li 增加注释
*
*********************************************************************/
class ByteTool
{
public:
/**********************************************************************
* 概述: 移除空格
* 函数名: TrimMove
* 返回值: char* 失败返回NULL
* 参数列表: 参数类型 取值范围 描述
* src: char * 需要处理的字符指针
* length: int src的最大长度
*
* 版本历史
* 1.0 2010-09-02 echo_li 增加注释
*
**********************************************************************/
static char* TrimMove( char *src, int length);
/**********************************************************************
* 概述: 移除空格并拷贝到另一字符串中。使用方法同strncpy
* 函数名: TrimCopy
* 返回值: void
* 参数列表: 参数类型 取值范围 描述
* des: char * 目标字符指针
* src: char * 数据源指针
* length: int 需要处理的最大长度
* (建议使用目标和源最小的长度)
*
* 版本历史
* 1.0 2010-09-02 echo_li 增加注释
*
**********************************************************************/
static void TrimCopy( char *des, const char *src, int length);
/**********************************************************************
* 概述:
* 函数名: SeqPlus
* 返回值: std::vector<char>
* 参数列表: 参数类型 取值范围 描述
* num: int
* : ...
*
* 版本历史
* 1.0 2010-09-02 echo_li 增加注释
*
**********************************************************************/
//static std::vector<char> SeqPlus( int num, ...);
/**********************************************************************
* 概述: double转换成int
* 函数名: DataRound
* 返回值: int
* 参数列表: 参数类型 取值范围 描述
* : double
*
* 版本历史
* 1.0 2010-09-02 echo_li 增加注释
*
**********************************************************************/
static int DataRound( double);
/**********************************************************************
* 概述: float转化成int
* 函数名: DataRound
* 返回值: int
* 参数列表: 参数类型 取值范围 描述
* : float
*
* 版本历史
* 1.0 2010-09-02 echo_li 增加注释
*
**********************************************************************/
static int DataRound( float);
/**********************************************************************
* 概述: 比较两个字符串是否相等
* 函数名: Compare
* 返回值: int
* 参数列表: 参数类型 取值范围 描述
* src: const char *
* dest: const char *
* ignoreCase: bool
*
* 版本历史
* 1.0 2010-09-02 echo_li 增加注释
*
**********************************************************************/
static int Compare(const char* src,const char* dest,bool ignoreCase);
/**********************************************************************
* 概述: 比较两个字符串是否相等
* 函数名: Compare
* 返回值: int
* 参数列表: 参数类型 取值范围 描述
* src: const char *
* dest: const char *
* length: int
* ignoreCase: bool
*
* 版本历史
* 1.0 2010-09-02 echo_li 增加注释
*
**********************************************************************/
static int Compare(const char* src,const char* dest,int length,bool ignoreCase);
/**********************************************************************
* Pre Fill char for filling source string by fillchar at length
* 概述: pre fill source by fillchar
* 函数名: PreFill
* 返回值: int
* 参数列表: 参数类型 取值范围 描述
* dest: string &
* src: const char *
* length: const int
* fillchar: const char
*
* 版本历史
* 1.0 2010-09-02 echo_rmbai 增加注释
*
**********************************************************************/
static int LeftFill(string &dest,const char *src,int length,const char fillchar=' ');
/**********************************************************************
* Pre Fill char for filling source string by fillchar at length
* 概述: pre fill source by fillchar
* 函数名: PreFill
* 返回值: int
* 参数列表: 参数类型 取值范围 描述
* src: string &
* length: const int
* fillchar: const char
*
* 版本历史
* 1.0 2010-09-02 echo_rmbai 增加注释
*
**********************************************************************/
static int LeftFill(string &src,const int length,const char fillchar=' ');
/**********************************************************************
* Post Fill char for filling source string by fillchar at length
* 概述: post fill source by fillchar
* 函数名: PosFill
* 返回值: int
* 参数列表: 参数类型 取值范围 描述
* dest: string &
* src: const char *
* length: int
* fillchar: const char
*
* 版本历史
* 1.0 2010-09-02 echo_rmbai 增加注释
*
**********************************************************************/
static int RightFill(string &dest,const char *src,int length,const char fillchar=' ');
/**********************************************************************
* Post Fill char for filling source string by fillchar at length
* 概述: post fill source by fillchar
* 函数名: PosFill
* 返回值: int
* 参数列表: 参数类型 取值范围 描述
* src: string &
* length: const int
* fillchar: const char
*
* 版本历史
* 1.0 2010-09-02 echo_rmbai 增加注释
*
**********************************************************************/
static int RightFill(string &src,const int length,const char fillchar=' ');
/**********************************************************************
* Clear Underscode from char
* 概述:
* 函数名: NoUnderscode
* 返回值: char * 去掉下划线后的字符串
* 参数列表: 参数类型 取值范围 描述
* src: unsigned char *
* length: const int
*
* 版本历史
* 1.0 2010-09-02 echo_rmbai 增加注释
*
**********************************************************************/
static int NoUnderscode( char *dest, const char *src, char byte = '_');
/**********************************************************************
* 概述: Convert pagecode from one to another
* 函数名: CodeConvert
* 返回值: int
* 参数列表: 参数类型 取值范围 描述
* from_charset: const char * "UTF-8""GBK" "GB2312" 源编码
* to_charset: const char * "UTF-8""GBK" "GB2312 目标编码
* inbuf: char * 输入字符串地址
* inlen: int 输入地址长度
* outbuf: char * 输出字符串地址
* outlen int 输出地址长度
* 版本历史
* 1.0 2010-09-02 echo_rmbai 增加注释
*
**********************************************************************/
#ifndef _WIN32
static int CodeConvert( const char *from_charset, const char *to_charset, char *inbuf, size_t inlen, char *outbuf, size_t outlen);
#endif
static char *destChar;//for Fill char
private:
//fill count of length src by fillchar
static void FillCharByPost(string &src ,int length,const char fillChar=' ');
};
}
#endif