length--
}
- i := strings.LastIndex(name[:length], "/")
+ i := strings.LastIndexByte(name[:length], '/')
nlen := len(name) - i - 1 // nlen is length of suffix
plen := i // plen is length of prefix
if i <= 0 || nlen > nameSize || nlen == 0 || plen > prefixSize {
}
// If it has a slash, it must be a package path but there is a symbol.
// It's the last package path we care about.
- slash := strings.LastIndex(arg, "/")
+ slash := strings.LastIndexByte(arg, '/')
// There may be periods in the package path before or after the slash
// and between a symbol and method.
// Split the string at various periods to see what we find.
case "<nil>":
// If the package name is not explicitly specified,
// make an educated guess. This is not guaranteed to be correct.
- lastSlash := strings.LastIndex(path, "/")
+ lastSlash := strings.LastIndexByte(path, '/')
if lastSlash == -1 {
name = path
} else {
// Backwards compatibility: skip optional first argument
// index after the colon.
- if colon := strings.LastIndex(name, ":"); colon > 0 {
+ if colon := strings.LastIndexByte(name, ':'); colon > 0 {
name = name[:colon]
}
if len(host) > 0 && host[0] == '[' && host[len(host)-1] == ']' {
host = host[1 : len(host)-1]
}
- if i := strings.LastIndex(host, "%"); i > 0 {
+ if i := strings.LastIndexByte(host, '%'); i > 0 {
host = host[:i]
}
if net.ParseIP(host) != nil {
return nil, err
}
- colonPos := strings.LastIndex(addr, ":")
+ colonPos := strings.LastIndexByte(addr, ':')
if colonPos == -1 {
colonPos = len(addr)
}
// PackageName returns the package part of the symbol name,
// or the empty string if there is none.
func (s *Sym) PackageName() string {
- pathend := strings.LastIndex(s.Name, "/")
+ pathend := strings.LastIndexByte(s.Name, '/')
if pathend < 0 {
pathend = 0
}
// ReceiverName returns the receiver type name of this symbol,
// or the empty string if there is none.
func (s *Sym) ReceiverName() string {
- pathend := strings.LastIndex(s.Name, "/")
+ pathend := strings.LastIndexByte(s.Name, '/')
if pathend < 0 {
pathend = 0
}
l := strings.IndexByte(s.Name[pathend:], '.')
- r := strings.LastIndex(s.Name[pathend:], ".")
+ r := strings.LastIndexByte(s.Name[pathend:], '.')
if l == -1 || r == -1 || l == r {
return ""
}
// BaseName returns the symbol name without the package or receiver name.
func (s *Sym) BaseName() string {
- if i := strings.LastIndex(s.Name, "."); i != -1 {
+ if i := strings.LastIndexByte(s.Name, '.'); i != -1 {
return s.Name[i+1:]
}
return s.Name
// Pick a name. We try to use the final element of the path
// but fall back to _.
prefix := strings.TrimRight(url, "/")
- if i := strings.LastIndex(prefix, "/"); i >= 0 {
+ if i := strings.LastIndexByte(prefix, '/'); i >= 0 {
prefix = prefix[i+1:]
}
if prefix == "" || !isName([]byte(prefix)) || strings.Contains(prefix, ":") {
}
func nameExt(name string) string {
- i := strings.LastIndex(name, ".")
+ i := strings.LastIndexByte(name, '.')
if i < 0 {
return ""
}
}
tried.vendor = append(tried.vendor, dir)
}
- i := strings.LastIndex(sub, "/")
+ i := strings.LastIndexByte(sub, '/')
if i < 0 {
break
}
return
}
- i := strings.LastIndex(name, ".")
+ i := strings.LastIndexByte(name, '.')
if i < 0 {
i = len(name)
}
_, file, line, ok := runtime.Caller(3) // decorate + log + public function.
if ok {
// Truncate file name at last file name separator.
- if index := strings.LastIndex(file, "/"); index >= 0 {
+ if index := strings.LastIndexByte(file, '/'); index >= 0 {
file = file[index+1:]
} else if index = strings.LastIndex(file, "\\"); index >= 0 {
file = file[index+1:]
if strings.HasPrefix(text, linePrefix) && (!pos.IsValid() || pos.Column == 1) {
// possibly a line directive
ldir := strings.TrimSpace(text[len(linePrefix):])
- if i := strings.LastIndex(ldir, ":"); i >= 0 {
+ if i := strings.LastIndexByte(ldir, ':'); i >= 0 {
if line, err := strconv.Atoi(ldir[i+1:]); err == nil && line > 0 {
// The line directive we are about to print changed
// the Filename and Line number used for subsequent
if i := len(name); i > 0 && name[i-1] == '/' {
name = name[:i-1]
}
- if i := strings.LastIndex(name, "/"); i >= 0 {
+ if i := strings.LastIndexByte(name, '/'); i >= 0 {
name = name[i+1:]
}
imp = NewPackage(path, name)
// pkgName returns the package name (last element) of an import path.
func pkgName(path string) string {
- if i := strings.LastIndex(path, "/"); i >= 0 {
+ if i := strings.LastIndexByte(path, '/'); i >= 0 {
path = path[i+1:]
}
return path
f := &Frame{PC: pc}
f.Fn = fn[:len(fn)-1]
f.File = file[:len(file)-1]
- if colon := strings.LastIndex(f.File, ":"); colon != -1 {
+ if colon := strings.LastIndexByte(f.File, ':'); colon != -1 {
ln, err := strconv.Atoi(f.File[colon+1:])
if err == nil {
f.File = f.File[:colon]
var i int
if psl == nil {
- i = strings.LastIndex(host, ".")
+ i = strings.LastIndexByte(host, '.')
if i <= 0 {
return host
}
// here on, so it is okay if psl.PublicSuffix("www.buggy.psl")
// returns "com" as the jar key is generated from host.
}
- prevDot := strings.LastIndex(host[:i-1], ".")
+ prevDot := strings.LastIndexByte(host[:i-1], '.')
return host[prevDot+1:]
}
return "/" // Path is empty or malformed.
}
- i := strings.LastIndex(path, "/") // Path starts with "/", so i != -1.
+ i := strings.LastIndexByte(path, '/') // Path starts with "/", so i != -1.
if i == 0 {
return "/" // Path has the form "/abc".
}
if d == "www2.buggy.psl" {
return "com"
}
- return d[strings.LastIndex(d, ".")+1:]
+ return d[strings.LastIndexByte(d, '.')+1:]
}
// newTestJar creates an empty Jar with testPSL as the public suffix list.
// Given a string of the form "host", "host:port", or "[ipv6::address]:port",
// return true if the string includes a port.
-func hasPort(s string) bool { return strings.LastIndex(s, ":") > strings.LastIndex(s, "]") }
+func hasPort(s string) bool { return strings.LastIndexByte(s, ':') > strings.LastIndexByte(s, ']') }
// removeEmptyPort strips the empty port in ":port" to ""
// as mandated by RFC 3986 Section 6.2.3.
if !strings.HasPrefix(host, "[") {
return host
}
- i := strings.LastIndex(host, "]")
+ i := strings.LastIndexByte(host, ']')
if i < 0 {
return host
}
- j := strings.LastIndex(host[:i], "%")
+ j := strings.LastIndexByte(host[:i], '%')
if j < 0 {
return host
}
addr = strings.ToLower(strings.TrimSpace(addr))
if hasPort(addr) {
- addr = addr[:strings.LastIndex(addr, ":")]
+ addr = addr[:strings.LastIndexByte(addr, ':')]
}
for _, p := range strings.Split(noProxy, ",") {
continue
}
if hasPort(p) {
- p = p[:strings.LastIndex(p, ":")]
+ p = p[:strings.LastIndexByte(p, ':')]
}
if addr == p {
return false
func (cm *connectMethod) tlsHost() string {
h := cm.targetAddr
if hasPort(h) {
- h = h[:strings.LastIndex(h, ":")]
+ h = h[:strings.LastIndexByte(h, ':')]
}
return h
}
// the name will be rendered according to RFC 2047.
func (a *Address) String() string {
// Format address local@domain
- at := strings.LastIndex(a.Address, "@")
+ at := strings.LastIndexByte(a.Address, '@')
var local, domain string
if at < 0 {
// This is a malformed address ("@" is required in addr-spec);
// we can still recover and move on to the next request.
keepReading = true
- dot := strings.LastIndex(req.ServiceMethod, ".")
+ dot := strings.LastIndexByte(req.ServiceMethod, '.')
if dot < 0 {
err = errors.New("rpc: service/method request ill-formed: " + req.ServiceMethod)
return
}
func parseAuthority(authority string) (user *Userinfo, host string, err error) {
- i := strings.LastIndex(authority, "@")
+ i := strings.LastIndexByte(authority, '@')
if i < 0 {
host, err = parseHost(authority)
} else {
if strings.HasPrefix(host, "[") {
// Parse an IP-Literal in RFC 3986 and RFC 6874.
// E.g., "[fe80::1]", "[fe80::1%25en0]", "[fe80::1]:80".
- i := strings.LastIndex(host, "]")
+ i := strings.LastIndexByte(host, ']')
if i < 0 {
return "", errors.New("missing ']' in host")
}
if ref == "" {
full = base
} else if ref[0] != '/' {
- i := strings.LastIndex(base, "/")
+ i := strings.LastIndexByte(base, '/')
full = base[:i+1] + ref
} else {
full = ref
}
func hasExt(file string) bool {
- i := strings.LastIndex(file, ".")
+ i := strings.LastIndexByte(file, '.')
if i < 0 {
return false
}
// file set to path.
// The returned values have the property that path = dir+file.
func Split(path string) (dir, file string) {
- i := strings.LastIndex(path, "/")
+ i := strings.LastIndexByte(path, '/')
return path[:i+1], path[i+1:]
}
path = path[0 : len(path)-1]
}
// Find the last element
- if i := strings.LastIndex(path, "/"); i >= 0 {
+ if i := strings.LastIndexByte(path, '/'); i >= 0 {
path = path[i+1:]
}
// If empty now, it had only slashes.
_, file, line, ok := runtime.Caller(skip)
if ok {
// Truncate file name at last file name separator.
- if index := strings.LastIndex(file, "/"); index >= 0 {
+ if index := strings.LastIndexByte(file, '/'); index >= 0 {
file = file[index+1:]
} else if index = strings.LastIndex(file, "\\"); index >= 0 {
file = file[index+1:]
t1 := Now()
SetMono(&t1, tt.mono)
s := t1.String()
- got := s[strings.LastIndex(s, " ")+1:]
+ got := s[strings.LastIndexByte(s, ' ')+1:]
if got != tt.want {
t.Errorf("with mono=%d: got %q; want %q", tt.mono, got, tt.want)
}