| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4045c85 commit d739407
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,6 +9,7 @@ | |||
| 9 | 9 | ArduinoHttpClient KEYWORD1 | |
| 10 | 10 | HttpClient KEYWORD1 | |
| 11 | 11 | WebSocketClient KEYWORD1 | |
| 12 | + URLEncoder KEYWORD1 | ||
| 12 | 13 | ||
| 13 | 14 | ####################################### | |
| 14 | 15 | # Methods and Functions (KEYWORD2) | |
@@ -47,6 +48,8 @@ isFinal KEYWORD2 | |||
| 47 | 48 | readString KEYWORD2 | |
| 48 | 49 | ping KEYWORD2 | |
| 49 | 50 | ||
| 51 | + encode KEYWORD2 | ||
| 52 | + | ||
| 50 | 53 | ####################################### | |
| 51 | 54 | # Constants (LITERAL1) | |
| 52 | 55 | ####################################### | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,5 +7,6 @@ | |||
| 7 | 7 | ||
| 8 | 8 | #include "HttpClient.h" | |
| 9 | 9 | #include "WebSocketClient.h" | |
| 10 | + #include "URLEncoder.h" | ||
| 10 | 11 | ||
| 11 | 12 | #endif | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,53 @@ | |||
| 1 | + // Library to simplify HTTP fetching on Arduino | ||
| 2 | + // (c) Copyright Arduino. 2019 | ||
| 3 | + // Released under Apache License, version 2.0 | ||
| 4 | + | ||
| 5 | + #include "URLEncoder.h" | ||
| 6 | + | ||
| 7 | + URLEncoderClass::URLEncoderClass() | ||
| 8 | + { | ||
| 9 | + } | ||
| 10 | + | ||
| 11 | + URLEncoderClass::~URLEncoderClass() | ||
| 12 | + { | ||
| 13 | + } | ||
| 14 | + | ||
| 15 | + String URLEncoderClass::encode(const char* str) | ||
| 16 | + { | ||
| 17 | + return encode(str, strlen(str)); | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + String URLEncoderClass::encode(const String& str) | ||
| 21 | + { | ||
| 22 | + return encode(str.c_str(), str.length()); | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + String URLEncoderClass::encode(const char* str, int length) | ||
| 26 | + { | ||
| 27 | + String encoded; | ||
| 28 | + | ||
| 29 | + encoded.reserve(length); | ||
| 30 | + | ||
| 31 | + for (int i = 0; i < length; i++) { | ||
| 32 | + char c = str[i]; | ||
| 33 | + | ||
| 34 | + const char HEX_DIGIT_MAPPER[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; | ||
| 35 | + | ||
| 36 | + if (isAlphaNumeric(c) || (c == '-') || (c == '.') || (c == '_') || (c == '~')) { | ||
| 37 | + encoded += c; | ||
| 38 | + } else { | ||
| 39 | + char s[4]; | ||
| 40 | + | ||
| 41 | + s[0] = '%'; | ||
| 42 | + s[1] = HEX_DIGIT_MAPPER[(c >> 4) & 0xf]; | ||
| 43 | + s[2] = HEX_DIGIT_MAPPER[(c & 0x0f)]; | ||
| 44 | + s[3] = 0; | ||
| 45 | + | ||
| 46 | + encoded += s; | ||
| 47 | + } | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + return encoded; | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + URLEncoderClass URLEncoder; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,25 @@ | |||
| 1 | + // Library to simplify HTTP fetching on Arduino | ||
| 2 | + // (c) Copyright Arduino. 2019 | ||
| 3 | + // Released under Apache License, version 2.0 | ||
| 4 | + | ||
| 5 | + #ifndef URL_ENCODER_H | ||
| 6 | + #define URL_ENCODER_H | ||
| 7 | + | ||
| 8 | + #include <Arduino.h> | ||
| 9 | + | ||
| 10 | + class URLEncoderClass | ||
| 11 | + { | ||
| 12 | + public: | ||
| 13 | + URLEncoderClass(); | ||
| 14 | + virtual ~URLEncoderClass(); | ||
| 15 | + | ||
| 16 | + String encode(const char* str); | ||
| 17 | + String encode(const String& str); | ||
| 18 | + | ||
| 19 | + private: | ||
| 20 | + String encode(const char* str, int length); | ||
| 21 | + }; | ||
| 22 | + | ||
| 23 | + extern URLEncoderClass URLEncoder; | ||
| 24 | + | ||
| 25 | + #endif | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments