drop idna from names as we already are in the idn package and also avoid "else

if" when it's not necessary
This commit is contained in:
Rafael Dantas Justo 2015-07-16 08:05:25 -03:00
parent 0096e2aae0
commit 4071a397d6
2 changed files with 2344 additions and 2342 deletions

File diff suppressed because it is too large Load Diff

View File

@ -274,30 +274,32 @@ func decode(b []byte) []byte {
}
// isValidRune checks if the character is valid. We will look for the
// character property in the IDNA table. For now we aren't checking special
// character property in the code points list. For now we aren't checking special
// rules in case of contextual property
func isValidRune(r rune) bool {
return findProperty(r) == idnaPropertyPVALID
return findProperty(r) == propertyPVALID
}
// findIDNProperty will try to check the code point property of the give
// findProperty will try to check the code point property of the given
// character. It will use a binary search algorithm as we have a slice of
// ordered ranges (average case performance O(log n))
func findProperty(r rune) idnaProperty {
imin, imax := 0, len(idnaTable)
func findProperty(r rune) property {
imin, imax := 0, len(codePoints)
for imax >= imin {
imid := (imin + imax) / 2
codePoint := idnaTable[imid]
codePoint := codePoints[imid]
if (codePoint.start == r && codePoint.end == 0) || (codePoint.start <= r && codePoint.end >= r) {
return codePoint.state
} else if (codePoint.end > 0 && codePoint.end < r) || (codePoint.end == 0 && codePoint.start < r) {
}
if (codePoint.end > 0 && codePoint.end < r) || (codePoint.end == 0 && codePoint.start < r) {
imin = imid + 1
} else {
imax = imid - 1
}
}
return idnaPropertyUnknown
}
return propertyUnknown
}