From 5214bb9e57f5778e127c529a2ef83b838c37ce28 Mon Sep 17 00:00:00 2001 From: Tingfeng Date: Fri, 3 Jun 2022 05:06:29 +0800 Subject: [PATCH] refactoring --- fasttld.go | 4 ++-- strings.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fasttld.go b/fasttld.go index 08201d7..9848d76 100644 --- a/fasttld.go +++ b/fasttld.go @@ -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 diff --git a/strings.go b/strings.go index 4908dd3..4240d90 100644 --- a/strings.go +++ b/strings.go @@ -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) }