From d820c36c4f33c986229f6d516f39f022f708035f Mon Sep 17 00:00:00 2001 From: Ron Evans Date: Fri, 25 Jan 2019 13:44:26 +0100 Subject: [PATCH] runtime/strings: add implementation of strings.IndexByte() (#155) Signed-off-by: Ron Evans --- src/runtime/string.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/runtime/string.go b/src/runtime/string.go index 73d56a86e..e11420340 100644 --- a/src/runtime/string.go +++ b/src/runtime/string.go @@ -166,3 +166,14 @@ func decodeUTF8(s string, index uintptr) (rune, uintptr) { return 0xfffd, 1 } } + +// indexByte returns the index of the first instance of c in s, or -1 if c is not present in s. +//go:linkname indexByte strings.IndexByte +func indexByte(s string, c byte) int { + for i := 0; i < len(s); i++ { + if s[i] == c { + return i + } + } + return -1 +}