mns_common_tool.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright (C) 2015, Alibaba Cloud Computing
  2. #ifndef MNS_SDK_COMMON_TOOL_H
  3. #define MNS_SDK_COMMON_TOOL_H
  4. #include <iostream>
  5. #include <fstream>
  6. #include <sstream>
  7. #include <map>
  8. #include <vector>
  9. namespace mns
  10. {
  11. namespace sdk
  12. {
  13. class StringTool
  14. {
  15. public:
  16. template <typename T>
  17. static std::string ToString(const T& i)
  18. {
  19. std::ostringstream s;
  20. s << i;
  21. return s.str();
  22. };
  23. static std::string TrimString(const std::string& str, const char leftTrimChar = ' ', const char rightTrimChar = ' ');
  24. static std::string LeftTrimString(const std::string& str, const char trimChar = ' ');
  25. static std::string RightTrimString(const std::string& str, const char trimChar = ' ');
  26. static std::vector<std::string> StringToVector(const std::string& string, const std::string& delim = ",");
  27. static bool StartWith(const std::string& input, const std::string& pattern);
  28. };
  29. class Base64Tool
  30. {
  31. public:
  32. static void Base64Encoding(std::istream&, std::ostream&, char makeupChar = '=', const char* alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");
  33. static void Base64Decoding(std::istream&, std::ostream&, char plus = '+', char slash = '/');
  34. };
  35. class TimeTool
  36. {
  37. public:
  38. static std::string GetDateTime();
  39. };
  40. }
  41. }
  42. #endif