url.h 1.5 KB

123456789101112131415161718192021222324252627282930313233
  1. #ifndef _URL_H
  2. #define _URL_H
  3. #include <bfc/common.h>
  4. #include <bfc/string/StringW.h>
  5. //#define URLENCODE_NOTHING 1 // encode nothing (add some flags!), default is to start with everything
  6. #define URLENCODE_EXCLUDEALPHANUM 2 // do not encode characters that are alphanumeric (a-z,0-1) or _ - and .
  7. #define URLENCODE_EXCLUDESLASH 4 // don't encode '/' or ':'
  8. //#define URLENCODE_EXCLUDEHTTPPREFIX 8 // don't encode "http://"
  9. //#define URLENCODE_EXCLUDE_8BIT 16 // do not encode > 127
  10. #define URLENCODE_EXCLUDE_ABOVEEQ32 32 // do not encode >= 32
  11. //#define URLENCODE_ENCODESPACE 64 // force encoding space
  12. //#define URLENCODE_ENCODEXML 128 // force encoding '>' and '<'
  13. #define URLENCODE_DEFAULT URLENCODE_EXCLUDEALPHANUM
  14. //#define URLENCODE_FULLURL (URLENCODE_DEFAULT|URLENCODE_EXCLUDEHTTPPREFIX|URLENCODE_EXCLUDESLASH|URLENCODE_EXCLUDE_7BIT_ABOVEEQ32|URLENCODE_ENCODESPACE)
  15. class Url {
  16. public:
  17. static void encode(StringW &dest, int use_plus_for_space = FALSE, int encoding = URLENCODE_DEFAULT, int style=URLENCODE_STYLE_PERCENT);
  18. static void encode(String &dest, int use_plus_for_space = FALSE, int encoding = URLENCODE_DEFAULT, int style=URLENCODE_STYLE_PERCENT);
  19. static void decode(StringW &str, int use_plus_for_space = FALSE);
  20. static void decode(wchar_t *str); // in place url decode
  21. enum {
  22. URLENCODE_STYLE_PERCENT = 0, // %AB
  23. URLENCODE_STYLE_ANDPOUND = 1, // &#171;
  24. URLENCODE_STYLE_ANDPOUNDX = 2, // &#xAB;
  25. };
  26. };
  27. #endif