From 8ea6d363df77de2dca288397da8d4f9c3d3a5c4d Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期五, 18 十月 2024 18:41:57 +0800
Subject: [PATCH] '项目完善'

---
 common/StringUtil.h |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 46 insertions(+), 0 deletions(-)

diff --git a/common/StringUtil.h b/common/StringUtil.h
index dfc701e..bad5142 100644
--- a/common/StringUtil.h
+++ b/common/StringUtil.h
@@ -9,6 +9,11 @@
 #include <vector>
 using namespace std;
 
+const std::string base64_chars =
+"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+"abcdefghijklmnopqrstuvwxyz"
+"0123456789+/";
+
 class StringUtil {
 
 public:
@@ -40,6 +45,12 @@
 		WideCharToMultiByte(0, 0, getbuf, -1, chRtn, iLen, NULL, NULL);  //将TCHAR 类型的数据转换为 CHAR 类型。
 		std::string str(chRtn);
 		return str;
+	}
+
+	static  std::string cstring2StringV2(CString getbuf) {
+		std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
+		std::string utf8String = converter.to_bytes(getbuf);
+		return utf8String;
 	}
 
 	static string to_string(double val) {
@@ -84,4 +95,39 @@
 		}
 		return result;
 	}
+	
+	static std::string base64_encode(const std::string& input) {
+		std::string encoded;
+		int val = 0, valb = -6;
+		for (unsigned char c : input) {
+			val = (val << 8) + c;
+			valb += 8;
+			while (valb >= 0) {
+				encoded.push_back(base64_chars[(val >> valb) & 0x3F]);
+				valb -= 6;
+			}
+		}
+		if (valb > -6) encoded.push_back(base64_chars[((val << 8) >> (valb + 8)) & 0x3F]);
+		while (encoded.size() % 4) encoded.push_back('=');
+		return encoded;
+	}
+
+	static std::string base64_decode(const std::string& input) {
+		std::string decoded;
+		std::vector<int> T(256, -1);
+		for (int i = 0; i < 64; i++) T[base64_chars[i]] = i;
+
+		int val = 0, valb = -8;
+		for (unsigned char c : input) {
+			if (T[c] == -1) break;
+			val = (val << 6) + T[c];
+			valb += 6;
+			if (valb >= 0) {
+				decoded.push_back(char((val >> valb) & 0xFF));
+				valb -= 8;
+			}
+		}
+		return decoded;
+	}
+
 };
\ No newline at end of file

--
Gitblit v1.8.0