HGGitLab

Commit d31a1c09 authored by luoliangyi's avatar luoliangyi

新建HGString.h和HGString.cpp文件,将字符串转换功能独立出来

parent 7b40c493
......@@ -30,6 +30,7 @@
<ClCompile Include="..\..\..\imgfmt\HGPdf.cpp" />
<ClCompile Include="..\..\..\imgfmt\HGPng.cpp" />
<ClCompile Include="..\..\..\imgfmt\HGTiff.cpp" />
<ClCompile Include="..\..\..\utility\HGString.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\imgfmt\HGBmp.h" />
......@@ -41,6 +42,7 @@
<ClInclude Include="..\..\..\imgfmt\HGPdf.h" />
<ClInclude Include="..\..\..\imgfmt\HGPng.h" />
<ClInclude Include="..\..\..\imgfmt\HGTiff.h" />
<ClInclude Include="..\..\..\utility\HGString.h" />
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
......
......@@ -31,6 +31,7 @@
<ClCompile Include="..\..\..\third_party\base64\base64.cpp" />
<ClCompile Include="..\..\..\third_party\json\cJSON.c" />
<ClCompile Include="..\..\..\third_party\sha1\sha1.cpp" />
<ClCompile Include="..\..\..\utility\HGString.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\sdk\webservice\HttpHead.h" />
......@@ -45,6 +46,7 @@
<ClInclude Include="..\..\..\third_party\base64\base64.h" />
<ClInclude Include="..\..\..\third_party\json\cJSON.h" />
<ClInclude Include="..\..\..\third_party\sha1\sha1.h" />
<ClInclude Include="..\..\..\utility\HGString.h" />
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
......
#include "HGOfdImpl.hpp"
#include "../base/HGInc.h"
#include "../base/HGUtility.h"
#include "../utility/HGString.h"
#define A4page_page_PhysicalBox_Width 210.000000
#define A4page_page_PhysicalBox_Height 297.000000
#if defined(HG_CMP_MSC)
static std::string AnsiToUtf8(const char* text)
{
int wlen = ::MultiByteToWideChar(CP_ACP, 0, text, -1, NULL, 0);
WCHAR* pUnicode = new WCHAR[wlen];
::MultiByteToWideChar(CP_ACP, 0, text, -1, pUnicode, wlen);
int len = ::WideCharToMultiByte(CP_UTF8, 0, pUnicode, -1, NULL, 0, NULL, NULL);
CHAR* pUTF8 = new CHAR[len];
::WideCharToMultiByte(CP_UTF8, 0, pUnicode, -1, pUTF8, len, NULL, NULL);
delete[] pUnicode;
std::string ret = pUTF8;
delete[] pUTF8;
return ret;
}
#endif
static std::string StdStringToUtf8(const char* str)
{
#if defined(HG_CMP_MSC)
return AnsiToUtf8(str);
#else
return str;
#endif
}
HGOfdReaderImpl::HGOfdReaderImpl()
{
m_zip = NULL;
......
......@@ -3,6 +3,7 @@
#include "mupdf/pdf.h"
#include "mupdf/fitz.h"
#include "pdflib.h"
#include "../utility/HGString.h"
#include <string>
struct HGPdfReaderImpl
......@@ -60,31 +61,6 @@ struct HGPdfImageWriterImpl
PDF* m_pPdf;
};
#if defined(HG_CMP_MSC)
static std::string AnsiToUtf8(const char* text)
{
int wlen = ::MultiByteToWideChar(CP_ACP, 0, text, -1, NULL, 0);
WCHAR* pUnicode = new WCHAR[wlen];
::MultiByteToWideChar(CP_ACP, 0, text, -1, pUnicode, wlen);
int len = ::WideCharToMultiByte(CP_UTF8, 0, pUnicode, -1, NULL, 0, NULL, NULL);
CHAR* pUTF8 = new CHAR[len];
::WideCharToMultiByte(CP_UTF8, 0, pUnicode, -1, pUTF8, len, NULL, NULL);
delete[] pUnicode;
std::string ret = pUTF8;
delete[] pUTF8;
return ret;
}
#endif
static std::string StdStringToUtf8(const char* str)
{
#if defined(HG_CMP_MSC)
return AnsiToUtf8(str);
#else
return str;
#endif
}
#if defined(HG_CMP_MSC)
static WCHAR* GetUnicodeStr(const char* text)
{
......
#include "HttpHead.h"
#include "../../utility/HGString.h"
const unsigned int asciiTableData[256] =
{
......@@ -285,13 +286,6 @@ void HttpHead::AnalysisHead(const std::string& head, std::string& requestMethod,
}
}
void HttpHead::TrimString(std::string& str)
{
int s = (int)str.find_first_not_of(" ");
int e = (int)str.find_last_not_of(" ");
str = str.substr(s, e - s + 1);
}
/*判断ascii码是否是数字0-9*/
static bool asciiIsDigit(char c)
{
......
......@@ -34,7 +34,6 @@ public:
HttpPairs& requestURIQueryInfos, std::string& requestURIFragment, std::string &httpVersion, HttpPairs & headInfos);
private:
static void TrimString(std::string& str);
static std::string AnalyURIString(const std::string& str);
private:
......
......@@ -9,6 +9,7 @@
#include "../../imgfmt/HGPdf.h"
#include "../../imgfmt/HGTiff.h"
#include "../../imgfmt/HGImgFmt.h"
#include "../../utility/HGString.h"
extern "C"
{
#include "zip.h"
......@@ -16,60 +17,6 @@ extern "C"
#include <list>
#include <algorithm>
#if defined(HG_CMP_MSC)
static std::string AnsiToUtf8(const char* text)
{
int wlen = ::MultiByteToWideChar(CP_ACP, 0, text, -1, NULL, 0);
WCHAR* pUnicode = new WCHAR[wlen];
::MultiByteToWideChar(CP_ACP, 0, text, -1, pUnicode, wlen);
int len = ::WideCharToMultiByte(CP_UTF8, 0, pUnicode, -1, NULL, 0, NULL, NULL);
CHAR* pUTF8 = new CHAR[len];
::WideCharToMultiByte(CP_UTF8, 0, pUnicode, -1, pUTF8, len, NULL, NULL);
delete[] pUnicode;
std::string ret = pUTF8;
delete[] pUTF8;
return ret;
}
static std::string Utf8ToAnsi(const char* text)
{
int wlen = ::MultiByteToWideChar(CP_UTF8, 0, text, -1, NULL, 0);
WCHAR* pUnicode = new WCHAR[wlen];
::MultiByteToWideChar(CP_UTF8, 0, text, -1, pUnicode, wlen);
int len = ::WideCharToMultiByte(CP_ACP, 0, pUnicode, -1, NULL, 0, NULL, NULL);
CHAR* pAnsi = new CHAR[len];
::WideCharToMultiByte(CP_ACP, 0, pUnicode, -1, pAnsi, len, NULL, NULL);
delete[] pUnicode;
std::string ret = pAnsi;
delete[] pAnsi;
return ret;
}
#endif
static std::string Utf8ToStdString(const char* utf8)
{
#if defined(HG_CMP_MSC)
return Utf8ToAnsi(utf8);
#else
return utf8;
#endif
}
static std::string StdStringToUtf8(const char* str)
{
#if defined(HG_CMP_MSC)
return AnsiToUtf8(str);
#else
return str;
#endif
}
static void TrimString(std::string& str)
{
int s = (int)str.find_first_not_of(" ");
int e = (int)str.find_last_not_of(" ");
str = str.substr(s, e - s + 1);
}
DevParam::DevParam()
{
Reset();
......
#include "HGString.h"
#include "../base/HGDef.h"
#include "../base/HGInc.h"
#include <algorithm>
void TrimString(std::string& str)
{
std::string str1;
bool add1 = false;
std::string::const_iterator iter1;
for (iter1 = str.begin(); iter1 != str.end(); ++iter1)
{
int c = (HGByte)(*iter1);
if (!add1)
{
if (!isspace(c))
{
str1.push_back(c);
add1 = true;
}
}
else
{
str1.push_back(c);
}
}
if (str1.empty())
{
str.clear();
return;
}
std::string str2;
bool add2 = false;
std::string::const_reverse_iterator iter2;
for (iter2 = str1.rbegin(); iter2 != str1.rend(); ++iter2)
{
int c = (HGByte)(*iter2);
if (!add2)
{
if (!isspace(c))
{
str2.push_back(c);
add2 = true;
}
}
else
{
str2.push_back(c);
}
}
if (str2.empty())
{
str.clear();
return;
}
str = std::string(str2.rbegin(), str2.rend());
}
#if defined(HG_CMP_MSC)
static std::string AnsiToUtf8(const char* text)
{
int wlen = ::MultiByteToWideChar(CP_ACP, 0, text, -1, NULL, 0);
WCHAR* pUnicode = new WCHAR[wlen];
::MultiByteToWideChar(CP_ACP, 0, text, -1, pUnicode, wlen);
int len = ::WideCharToMultiByte(CP_UTF8, 0, pUnicode, -1, NULL, 0, NULL, NULL);
CHAR* pUTF8 = new CHAR[len];
::WideCharToMultiByte(CP_UTF8, 0, pUnicode, -1, pUTF8, len, NULL, NULL);
delete[] pUnicode;
std::string ret = pUTF8;
delete[] pUTF8;
return ret;
}
static std::string Utf8ToAnsi(const char* text)
{
int wlen = ::MultiByteToWideChar(CP_UTF8, 0, text, -1, NULL, 0);
WCHAR* pUnicode = new WCHAR[wlen];
::MultiByteToWideChar(CP_UTF8, 0, text, -1, pUnicode, wlen);
int len = ::WideCharToMultiByte(CP_ACP, 0, pUnicode, -1, NULL, 0, NULL, NULL);
CHAR* pAnsi = new CHAR[len];
::WideCharToMultiByte(CP_ACP, 0, pUnicode, -1, pAnsi, len, NULL, NULL);
delete[] pUnicode;
std::string ret = pAnsi;
delete[] pAnsi;
return ret;
}
#endif
std::string Utf8ToStdString(const char* utf8)
{
#if defined(HG_CMP_MSC)
return Utf8ToAnsi(utf8);
#else
return utf8;
#endif
}
std::string StdStringToUtf8(const char* str)
{
#if defined(HG_CMP_MSC)
return AnsiToUtf8(str);
#else
return str;
#endif
}
\ No newline at end of file
#ifndef __HGSTRING_H__
#define __HGSTRING_H__
#include <string>
// 标准字符串:windows下为ansi编码,linux下为utf8编码
// 去掉前后空格
void TrimString(std::string& str);
// UTF8转标准字符串
std::string Utf8ToStdString(const char* utf8);
// 标准字符串转UTF8
std::string StdStringToUtf8(const char* str);
#endif /* __HGSTRING_H__ */
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment