Skip to content

Commit

Permalink
Update workflows and refactor code format. (#9)
Browse files Browse the repository at this point in the history
* code format

* only arduino vendor.

* version.

* year
  • Loading branch information
dojyorin authored Aug 17, 2024
1 parent 658f777 commit ccfebd2
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 79 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
35 changes: 8 additions & 27 deletions .github/workflows/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,47 +31,28 @@
"matrix": {
"board": [{
"vendor": "arduino",
"arch": "samd",
"name": "arduino_zero_native"
"arch": "avr",
"name": "uno"
}, {
"vendor": "adafruit",
"vendor": "arduino",
"arch": "samd",
"name": "adafruit_trinket_m0"
}, {
"vendor": "STMicroelectronics",
"arch": "stm32",
"name": "GenH5"
"name": "arduino_zero_native"
}, {
"vendor": "teensy",
"arch": "avr",
"name": "teensy41"
"vendor": "arduino",
"arch": "renesas_uno",
"name": "minima"
}],
"include": [{
"index": "https://downloads.arduino.cc/packages/package_index.json",
"board": {
"vendor": "arduino"
}
}, {
"index": "https://adafruit.github.io/arduino-board-index/package_adafruit_index.json",
"board": {
"vendor": "adafruit"
}
}, {
"index": "https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json",
"board": {
"vendor": "STMicroelectronics"
}
}, {
"index": "https://www.pjrc.com/teensy/package_teensy_index.json",
"board": {
"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",
Expand Down
26 changes: 7 additions & 19 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,22 @@ jobs:
fail-fast: true
matrix:
board:
- vendor: arduino
arch: avr
name: uno
- vendor: arduino
arch: samd
name: arduino_zero_native
- vendor: adafruit
arch: samd
name: adafruit_trinket_m0
- vendor: STMicroelectronics
arch: stm32
name: GenH5
- vendor: teensy
arch: avr
name: teensy41
- vendor: arduino
arch: renesas_uno
name: minima
include:
- index: https://downloads.arduino.cc/packages/package_index.json
board:
vendor: arduino
- index: https://adafruit.github.io/arduino-board-index/package_adafruit_index.json
board:
vendor: adafruit
- index: https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json
board:
vendor: STMicroelectronics
- index: https://www.pjrc.com/teensy/package_teensy_index.json
board:
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
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Kazuki Ota
Copyright (c) 2024 Kazuki Ota

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
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 library.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name=percent_encode
author=dojyorin
version=2.0.3
version=2.0.4
architectures=*
includes=arduino_percent.hpp
sentence=Convert between URL-unsafe string and percent encoded string.
Expand Down
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 ccfebd2

Please sign in to comment.