Skip to content

Commit

Permalink
reorder toBase
Browse files Browse the repository at this point in the history
  • Loading branch information
adraffy committed Jan 5, 2024
1 parent 2f9bbbe commit 85ac317
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Impl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {Punycode} from "../src/Punycode.sol";
// 20231227: 4355678
// 20231231: 4310752
// 20240101: 3494778
// 20240104: 3255423
// 20240104: 3208941

// [decode]
// 20240104: 6096960
Expand Down
16 changes: 7 additions & 9 deletions src/Punycode.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,15 @@ library Punycode {
// returns [0, BASE) as success, BASE as error
function toBase(uint256 ch) internal pure returns (uint256) {
unchecked {
if (ch <= 90) {
if (ch >= 65) {
return ch - 65; // [A-Z] => 0-25
} else if (ch >= 48 && ch <= 57) {
return ch - 22; // [0-9] => 26-35, 48-26=22
}
} else if (ch >= 97 && ch <= 122) {
if (ch >= 97 && ch <= 122) {
return ch - 97; // [a-z] => 0-25
} else if (ch >= 48 && ch <= 57) {
return ch - 22; // [0-9] => 26-35, 48-26=22
} else if (ch >= 65 && ch <= 90) {
return ch - 65; // [A-Z] => 0-25
} else {
return BASE;
}
return BASE;
}
}
// "An encoder SHOULD output only uppercase forms or only lowercase forms"
Expand All @@ -62,7 +61,6 @@ library Punycode {
return i < 26 ? 97 + i : 22 + i;
}


// https://datatracker.ietf.org/doc/html/rfc3492#section-6.1
function adaptBias(uint256 delta, uint256 len, bool first) internal pure returns (uint256) {
unchecked {
Expand Down

0 comments on commit 85ac317

Please sign in to comment.