Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotwutingfeng committed Jun 2, 2022
1 parent d0e0c75 commit 5214bb9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions fasttld.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ func (f *FastTLD) Extract(e URLParams) *ExtractResult {

// Check for IPv6 address
var netlocIsIPv6 bool
openingSquareBracketIdx := indexFirstByteBefore(netloc, '[', endOfHostWithPortDelimitersSet)
openingSquareBracketIdx := indexByteBefore(netloc, '[', endOfHostWithPortDelimitersSet)
if openingSquareBracketIdx > 0 {
// Erroneous opening square bracket
return &urlParts
}
closingSquareBracketIdx := indexFirstByteBefore(netloc, ']', endOfHostWithPortDelimitersSet)
closingSquareBracketIdx := indexByteBefore(netloc, ']', endOfHostWithPortDelimitersSet)
if openingSquareBracketIdx == 0 {
if !(closingSquareBracketIdx > 0 && isIPv6(netloc[1:closingSquareBracketIdx])) {
// Have opening square bracket but invalid IPv6 => Domain is invalid
Expand Down
4 changes: 2 additions & 2 deletions strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ func makeNewReplacerParams(toBeReplaced string, toReplaceWith string) []string {
return params
}

// indexFirstByteBefore returns the index of the first instance of byte b
// indexByteBefore returns the index of the first instance of byte b
// before any byte in notAfterCharsSet, otherwise -1
func indexFirstByteBefore(s string, b byte, notAfterCharsSet asciiSet) int {
func indexByteBefore(s string, b byte, notAfterCharsSet asciiSet) int {
if firstNotAfterCharIdx := indexAnyASCII(s, notAfterCharsSet); firstNotAfterCharIdx != -1 {
return strings.IndexByte(s[0:firstNotAfterCharIdx], b)
}
Expand Down

0 comments on commit 5214bb9

Please sign in to comment.