BBS2chProxyFormData.h 1.6 KB

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