Skip to content

Commit

Permalink
Specify anonymous namespace explicitly.
Browse files Browse the repository at this point in the history
  • Loading branch information
dojyorin committed Nov 9, 2023
1 parent 3dfd71e commit d65314d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name=percent_encode
author=dojyorin
version=2.0.1
version=2.0.2
architectures=*
includes=arduino_percent.hpp
sentence=Convert between URL-unsafe string and percent encoded string.
Expand Down
18 changes: 9 additions & 9 deletions src/percent.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#include "./arduino_percent.hpp"

namespace{
constexpr char symbols[] = "0123456789ABCDEF";
constexpr char unreserved[] = "-._~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
constexpr char CODE[] = "0123456789ABCDEF";
constexpr char UNRESERVED[] = "-._~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

uint8_t indexOf(char search){
if('`' < search){
search -= ' ';
}

for(uint8_t i = 0; i < 16; i++){
if(symbols[i] == search){
if(::CODE[i] == search){
return i;
}
}
Expand All @@ -19,7 +19,7 @@ namespace{
}

bool isUnreserved(char search){
for(const auto &v: unreserved){
for(const auto &v: ::UNRESERVED){
if(v == search){
return true;
}
Expand All @@ -31,13 +31,13 @@ namespace{

void percent::encode(const char* input, char* output){
while(*input != '\0'){
if(isUnreserved(*input)){
if(::isUnreserved(*input)){
*output++ = *input;
}
else{
*output++ = '%';
*output++ = symbols[*input >> 0x04];
*output++ = symbols[*input & 0x0F];
*output++ = ::CODE[*input >> 0x04];
*output++ = ::CODE[*input & 0x0F];
}

input++;
Expand All @@ -50,7 +50,7 @@ size_t percent::encodeLength(const char* input){
size_t length = 0;

while(*input != '\0'){
length += isUnreserved(*input++) ? 1 : 3;
length += ::isUnreserved(*input++) ? 1 : 3;
}

return length + 1;
Expand All @@ -59,7 +59,7 @@ size_t percent::encodeLength(const char* input){
void percent::decode(const char* input, char* output){
while(*input != '\0'){
if(*input == '%'){
*output++ = (indexOf(*++input) << 4) + indexOf(*++input);
*output++ = (::indexOf(*++input) << 4) + ::indexOf(*++input);
}
else{
*output++ = *input;
Expand Down

0 comments on commit d65314d

Please sign in to comment.