-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
155 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// тест утилит для парсинга | ||
#include <GParser.h> | ||
|
||
void setup() { | ||
Serial.begin(9600); | ||
// неправильно посчитает длину строки | ||
Serial.println(strlen("Привет!")); | ||
// правильно посчитает длину строки | ||
Serial.println(GP_unistrlen("Привет!")); | ||
|
||
Serial.println(GP_uniencode(0x27A1)); | ||
} | ||
|
||
void loop() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// тест утилит для парсинга | ||
#include <GParser.h> | ||
|
||
void setup() { | ||
Serial.begin(9600); | ||
String enc = GP_urlencode("https://kek.ru/#абвг"); | ||
Serial.println(enc); | ||
Serial.println(GP_urldecode(enc)); | ||
} | ||
|
||
void loop() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
name=GParser | ||
version=1.3.1 | ||
version=1.4 | ||
author=AlexGyver <alex@alexgyver.ru> | ||
maintainer=AlexGyver <alex@alexgyver.ru> | ||
sentence=Fast library for parsing cstring into substrings | ||
paragraph=Fast library for parsing cstring into substrings | ||
sentence=Fast library for parsing cstring into substrings, urlencode, unicode encode for Arduino | ||
paragraph=Fast library for parsing cstring into substrings, urlencode, unicode encode for Arduino | ||
category=Data Processing | ||
url=https://github.com/GyverLibs/GParser | ||
architectures=* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include "unicode.h" | ||
char* GP_uniencode(int32_t c, char* s) { | ||
if (c < 0x80) { | ||
s[0] = (c & 0x7F) | 0x00; | ||
s[1] = 0; | ||
} else if (c < 0x0800) { | ||
s[0] = (c >> 6 & 0x1F) | 0xC0; | ||
s[1] = (c & 0x3F) | 0x80; | ||
s[2] = 0; | ||
} else if (c < 0x010000) { | ||
s[0] = (c >> 12 & 0x0F) | 0xE0; | ||
s[1] = (c >> 6 & 0x3F) | 0x80; | ||
s[2] = (c & 0x3F) | 0x80; | ||
s[3] = 0; | ||
} else if (c < 0x110000) { | ||
s[0] = (c >> 18 & 0x07) | 0xF0; | ||
s[1] = (c >> 12 & 0x3F) | 0x80; | ||
s[2] = (c >> 6 & 0x3F) | 0x80; | ||
s[3] = (c & 0x3F) | 0x80; | ||
s[4] = 0; | ||
} | ||
return s; | ||
} | ||
|
||
String GP_uniencode(uint16_t c) { | ||
char str[5]; | ||
return String(GP_uniencode(c, str)); | ||
} | ||
|
||
uint16_t GP_unistrlen(char* data) { | ||
uint16_t i = 0, count = 0; | ||
while (data[i]) { | ||
if ((data[i] & 0xc0) != 0x80) count++; | ||
i++; | ||
} | ||
return count; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#pragma once | ||
#include <Arduino.h> | ||
char* GP_uniencode(int32_t c, char* s); | ||
String GP_uniencode(uint16_t c); | ||
uint16_t GP_unistrlen(char* data); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include "url.h" | ||
void GP_urlencode(const String& s, String& dest) { | ||
dest.reserve(s.length()); | ||
char c; | ||
for (uint16_t i = 0; i < s.length(); i++) { | ||
c = s[i]; | ||
if (c == ' ') dest += '+'; | ||
else if (!( | ||
(c >= '0' && c <= '9') || | ||
(c >= 'a' && c <= 'z') || | ||
(c >= 'A' && c <= 'Z') || | ||
c == '-' || c == '_' || c == '.' || c == '!' || c == '~' || | ||
c == '*' || c == '\'' || c == '(' || c == ')' | ||
)) { | ||
dest += '%'; | ||
dest += (char)((c >> 4) + (((c >> 4) > 9) ? 55 : 48)); | ||
dest += (char)((c & 0xF) + (((c & 0xF) > 9) ? 55 : 48)); | ||
} else dest += c; | ||
} | ||
} | ||
|
||
String GP_urlencode(const String& s) { | ||
String dest; | ||
GP_urlencode(s, dest); | ||
return dest; | ||
} | ||
|
||
void GP_urldecode(const String& s, String& dest) { | ||
dest.reserve(s.length()); | ||
char c; | ||
for (uint16_t i = 0; i < s.length(); i++) { | ||
c = s[i]; | ||
if (c != '%') dest += (c == '+') ? ' ' : c; | ||
else { | ||
c = s[++i]; | ||
uint8_t v1 = c - ((c <= '9') ? 48 : ((c <= 'F') ? 55 : 87)); | ||
c = s[++i]; | ||
uint8_t v2 = c - ((c <= '9') ? 48 : ((c <= 'F') ? 55 : 87)); | ||
dest += char(v2 | (v1 << 4)); | ||
} | ||
} | ||
} | ||
|
||
String GP_urldecode(const String& s) { | ||
String dest; | ||
GP_urldecode(s, dest); | ||
return dest; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#pragma once | ||
#include <Arduino.h> | ||
void GP_urlencode(const String& s, String& dest); | ||
String GP_urlencode(const String& s); | ||
void GP_urldecode(const String& s, String& dest); | ||
String GP_urldecode(const String& s); |