BBS2chProxyFormData.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #pragma once
  2. #include <vector>
  3. #include <string>
  4. #include <map>
  5. #include <string>
  6. #if (defined(__clang__) && defined(_LIBCPP_VERSION)) || (__cplusplus >= 201103L)
  7. #include <memory>
  8. #else
  9. #include <tr1/memory>
  10. #endif
  11. class BBS2chProxyURLEncodedValue {
  12. private:
  13. std::string _value;
  14. std::string _encodedValue;
  15. bool _hasValue;
  16. bool _hasEncodedValue;
  17. public:
  18. BBS2chProxyURLEncodedValue();
  19. BBS2chProxyURLEncodedValue(const std::string &value, bool encoded=false);
  20. BBS2chProxyURLEncodedValue(const char *value, size_t length, bool encoded=false);
  21. const std::string& get();
  22. const std::string& getEncoded();
  23. void set(const std::string &value, bool encoded=false);
  24. bool empty();
  25. BBS2chProxyURLEncodedValue& operator=(const std::string &value);
  26. };
  27. class BBS2chProxyFormData {
  28. private:
  29. std::map<std::string, BBS2chProxyURLEncodedValue> _fields;
  30. std::vector<std::string> _order;
  31. std::string _body;
  32. bool _dirty;
  33. public:
  34. typedef std::map<std::string, BBS2chProxyURLEncodedValue>::iterator iterator;
  35. BBS2chProxyFormData() {};
  36. BBS2chProxyFormData(const char *data, size_t length);
  37. std::string get(const std::string &key);
  38. std::string getEncoded(const std::string &key);
  39. void append(const std::string &key, const std::string &value, bool encoded=false);
  40. void set(const std::string &key, const std::string &value, bool encoded=false);
  41. bool has(const std::string &key);
  42. void remove(const std::string &key);
  43. void reorder(const std::vector<std::string> &order);
  44. const std::string& toString();
  45. size_t size();
  46. iterator begin();
  47. iterator end();
  48. std::string operator[](const std::string &key);
  49. static std::string decodeURIComponent(const char *input, size_t inputLength, bool decodePlus);
  50. static std::string encodeURIComponent(const char *input, size_t inputLength, bool spaceAsPlus);
  51. };
  52. #if (defined(__clang__) && defined(_LIBCPP_VERSION)) || (__cplusplus >= 201103L)
  53. typedef std::shared_ptr<BBS2chProxyFormData> PBBS2chProxyFormData;
  54. #else
  55. typedef std::tr1::shared_ptr<BBS2chProxyFormData> PBBS2chProxyFormData;
  56. #endif