remove dependency on less function

This commit is contained in:
Russ Ross 2011-05-30 14:42:38 -06:00
parent cd7b952148
commit 4a17a5b58f
2 changed files with 1 additions and 29 deletions

View File

@ -634,7 +634,7 @@ func isSafeLink(link []byte) bool {
for _, prefix := range validUris {
// TODO: handle unicode here
// case-insensitive prefix test
if len(link) > len(prefix) && !less(link[:len(prefix)], prefix) && !less(prefix, link[:len(prefix)]) && isalnum(link[len(prefix)]) {
if len(link) > len(prefix) && bytes.Equal(bytes.ToLower(link[:len(prefix)]), prefix) && isalnum(link[len(prefix)]) {
return true
}
}

View File

@ -14,7 +14,6 @@ package blackfriday
import (
"bytes"
"unicode"
)
// These are the supported markdown parsing extensions.
@ -275,33 +274,6 @@ type reference struct {
title []byte
}
// Compare two []byte values (case-insensitive), returning
// true if a is less than b.
func less(a []byte, b []byte) bool {
// adapted from bytes.Compare in stdlib
m := len(a)
if m > len(b) {
m = len(b)
}
for i, ac := range a[0:m] {
// do a case-insensitive comparison
ai, bi := unicode.ToLower(int(ac)), unicode.ToLower(int(b[i]))
switch {
case ai > bi:
return false
case ai < bi:
return true
}
}
switch {
case len(a) < len(b):
return true
case len(a) > len(b):
return false
}
return false
}
// Check whether or not data starts with a reference link.
// If so, it is parsed and stored in the list of references
// (in the render struct).