rfc3986.HasPrefixPctEncoded()

master
Charles Iliya Krempeaux 2024-08-24 08:42:07 -07:00
parent 5de48ef09b
commit b924b31e4c
2 changed files with 2444 additions and 0 deletions

View File

@ -4,10 +4,47 @@ import (
"io"
"github.com/reiver/go-erorr"
"github.com/reiver/go-rfc2234"
)
const pctencodedprefix = '%'
// IsPctEncodedPrefix returns true if what is at the beginning of the string is 'pct-encoded' as defined by IETF RFC-3986.
//
// pct-encoded = "%" HEXDIG HEXDIG
//
// Where 'HEXDIG' is defined in IETF RFC-2234 as:
//
// HEXDIG = DIGIT / "A" / "B" / "C" / "D" / "E" / "F"
//
// DIGIT = %x30-39
// ; 0-9
func HasPrefixPctEncoded(str string) bool {
var length int = len(str)
if length < 3 {
return false
}
var str0 rune = rune(str[0])
var str1 rune = rune(str[1])
var str2 rune = rune(str[2])
if !IsPctEncodedPrefix(str0) {
return false
}
if !rfc2234.IsHexDig(str1) {
return false
}
if !rfc2234.IsHexDig(str2) {
return false
}
return true
}
func IsPctEncodedPrefix(r rune) bool {
return pctencodedprefix == r
}

File diff suppressed because it is too large Load Diff