Util.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #pragma once
  2. #include <string>
  3. #include <vector>
  4. #include <map>
  5. using std::string;
  6. using std::vector;
  7. using std::map;
  8. #include "Poco/Types.h"
  9. class CUtil
  10. {
  11. public:
  12. static string& Ltrim(string &str);
  13. static string& Rtrim(string &str);
  14. static string& Trim(string &str);
  15. static string DoubleToString(long double dValue, int decplaces=6);
  16. static string ULongToString(unsigned long nValue);
  17. static unsigned long StringToULong(string stringValue);
  18. static string UIntToString(unsigned int nValue);
  19. static string Int64ToString(Poco::Int64 nValue);
  20. static string GetMd5(const char* bufSrc, int nLength);
  21. static int GetMd5(string stringFilePath, string& stringMd5);
  22. static int GetFileSize(string stringFilePath, unsigned long& nFileSize);
  23. static unsigned long GetFileSize(string stringFilePath);
  24. static int GetXmlFieldVaule(int nSaveType, string stringXmlContent, string stringXmlPath, string stringField, string& stringVaule);
  25. static int GetOrReplaceImagePathVector(int nSaveType, string stringXmlContent, string stringXmlPath, vector<string>& vImagePath);//不再处理Replace
  26. static int GetMapFromRequestXml(string stringXmlContent, string stringKey, map<string, string>& mapParam);
  27. static string GetErrorMsg(int nError);
  28. static int GBKToUTF8(string stringGbk, string& stringUtf8);
  29. static int UTF8ToGBK(string stringUtf8, string& stringGBK);
  30. static int EnvToUtf8(string stringEnv, string& stringUtf8);
  31. static string EnvToUtf8(string stringEnv);
  32. static int UTF8ToEnv(string stringUtf8, string& stringEnv);
  33. static string GetCurrentAppDir();
  34. static bool IsLegalGBK(string stringSrc);
  35. static bool IsLegalKOI8R(string stringSrc);
  36. static bool IsLegalUTF8(string stringSrc);
  37. static void SetAppDir(string stringWorkDir);//用于Android外部设置工作目录
  38. static void ReplaceStringInFile(string stringPath, string stringSrc, string stringDst);
  39. static void ReplaceString(string& stringContent, string stringSrc, string stringDst);//替换源字符串中的所有stringSrc,而非第一个
  40. static string GetFileNameFromPath(string stringPath);
  41. static void ParseJsonObjectWithoutArray(int nSaveType, string stringJsonContent, string stringJsonPath, map<string, string>& mapResult);
  42. static string MapToJson(map<string, string> mapParam);
  43. static int ParseStandardQueryString(string stringQuery, string& stringId, string& stringIdType);
  44. private:
  45. static string m_stringAppDir;
  46. };