Skip to content

Commit

Permalink
code format
Browse files Browse the repository at this point in the history
  • Loading branch information
dojyorin committed Jul 4, 2024
1 parent 658f777 commit d8022cb
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 33 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
"runs-on": "ubuntu-latest",
"steps": [{
"name": "clone repository",
"uses": "actions/checkout@v3"
"uses": "actions/checkout@v4"
}, {
"name": "dispatch release",
"uses": "softprops/action-gh-release@v1",
"uses": "softprops/action-gh-release@v2",
"with": {
"generate_release_notes": true
}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: clone repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: dispatch release
uses: softprops/action-gh-release@v1
uses: softprops/action-gh-release@v2
with:
generate_release_notes: true
2 changes: 1 addition & 1 deletion .github/workflows/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
},
"steps": [{
"name": "clone repository",
"uses": "actions/checkout@v3"
"uses": "actions/checkout@v4"
}, {
"name": "install arduino and run test",
"uses": "arduino/compile-sketches@v1",
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
vendor: teensy
steps:
- name: clone repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: install arduino and run test
uses: arduino/compile-sketches@v1
with:
Expand Down
6 changes: 4 additions & 2 deletions examples/decode/decode.ino
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "arduino_percent.hpp"

void setup(){
void setup() {
Serial.begin(115200);
while(!Serial);

Expand All @@ -11,4 +11,6 @@ void setup(){
Serial.println(output);
}

void loop(){}
void loop() {
// nop
}
6 changes: 4 additions & 2 deletions examples/encode/encode.ino
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "arduino_percent.hpp"

void setup(){
void setup() {
Serial.begin(115200);
while(!Serial);

Expand All @@ -11,4 +11,6 @@ void setup(){
Serial.println(output);
}

void loop(){}
void loop() {
// nop
}
2 changes: 1 addition & 1 deletion src/arduino_percent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Convert between URL-unsafe string and percent encoded string.
* @see https://github.com/dojyorin/arduino_percent
*/
namespace percent{
namespace percent {
/**
* Convert URL-unsafe string to percent encoded string.
* @example
Expand Down
42 changes: 20 additions & 22 deletions src/percent.cpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
#include "./arduino_percent.hpp"

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

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

for(uint8_t i = 0; i < 16; i++){
if(::CODE[i] == search){
for(uint8_t i = 0; i < 16; i++) {
if(::CODE[i] == search) {
return i;
}
}

return 0xFF;
}

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

void percent::encode(const char* input, char* output){
while(*input != '\0'){
if(::isUnreserved(*input)){
void percent::encode(const char* input, char* output) {
while(*input != '\0') {
if(::isUnreserved(*input)) {
*output++ = *input;
}
else{
} else {
*output++ = '%';
*output++ = ::CODE[*input >> 0x04];
*output++ = ::CODE[*input & 0x0F];
Expand All @@ -46,22 +45,21 @@ void percent::encode(const char* input, char* output){
*output = '\0';
}

size_t percent::encodeLength(const char* input){
size_t percent::encodeLength(const char* input) {
size_t length = 0;

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

return length + 1;
}

void percent::decode(const char* input, char* output){
while(*input != '\0'){
if(*input == '%'){
void percent::decode(const char* input, char* output) {
while(*input != '\0') {
if(*input == '%') {
*output++ = (::indexOf(*++input) << 4) + ::indexOf(*++input);
}
else{
} else {
*output++ = *input;
}

Expand All @@ -71,10 +69,10 @@ void percent::decode(const char* input, char* output){
*output = '\0';
}

size_t percent::decodeLength(const char* input){
size_t percent::decodeLength(const char* input) {
size_t length = 0;

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

0 comments on commit d8022cb

Please sign in to comment.