82 lines
2.2 KiB
C++
82 lines
2.2 KiB
C++
#pragma once
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
|
|
namespace dp {
|
|
/************************************************************************/
|
|
/* 字符串编码转换 */
|
|
/************************************************************************/
|
|
class StringConvert
|
|
{
|
|
public:
|
|
static std::string UnicodeToUTF8(const std::wstring & wstr);
|
|
static std::wstring UTF8ToUnicode(const std::string & str);
|
|
|
|
static std::string UnicodeToANSI(const std::wstring & wstr);
|
|
static std::wstring ANSIToUnicode(const std::string & str);
|
|
|
|
/*删除指定字符*/
|
|
static std::string DeleteChar(std::string str, char c);
|
|
static std::wstring DeleteWchar(std::wstring wstr, wchar_t c);
|
|
|
|
/*删除前后空格*/
|
|
static std::string StringTrim(std::string str);
|
|
static std::wstring WStringTrim(std::wstring wstr);
|
|
|
|
// 字符串分割
|
|
static int StringSplit(std::vector<std::string>& dst, const std::string& src, const std::string& separator);
|
|
static int WStringSplit(std::vector<std::wstring>& dst, const std::wstring& src, const std::wstring& separator);
|
|
|
|
//大小写转换
|
|
static std::string StringTolower(std::string str);
|
|
static std::string StringToupper(std::string str);
|
|
|
|
private:
|
|
StringConvert();
|
|
~StringConvert();
|
|
};
|
|
|
|
std::string CurrDir();
|
|
std::string ReadFile(const std::string& file_path);
|
|
|
|
|
|
/************************************************************************/
|
|
/* 日期时间 字符串处理 */
|
|
/************************************************************************/
|
|
enum TIME_STYLE
|
|
{
|
|
HMS_1 = 0, //000000
|
|
HMS_2, //00:00:00
|
|
HMS_3, //00-00-00
|
|
TIMESTAMP_SECOND,
|
|
TIMESTAMP_MILLISECOND,
|
|
TIMESTAMP_MICROSECOND
|
|
};
|
|
|
|
enum DATE_STYLE
|
|
{
|
|
YMD_1, //2020/11/16
|
|
YMD_2 //2020-11-16
|
|
};
|
|
|
|
class TimeString {
|
|
private:
|
|
TimeString() {};
|
|
~TimeString() {};
|
|
public:
|
|
static std::string GetDateString(DATE_STYLE style);
|
|
static std::string GetTimeString(TIME_STYLE style);
|
|
static std::string GetTimestamp(TIME_STYLE style);
|
|
|
|
/*毫秒时间戳转标准时间*/
|
|
static std::string TimestampToStdTime(int64_t timestamp);
|
|
|
|
//"2020-05-20 13:14:52"
|
|
static std::string StdTimeToTimestamp(std::string strTime);
|
|
};
|
|
|
|
|
|
}
|
|
|