// Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Package stringslite implements a subset of strings, // only using packages that may be imported by "os". // // Tests for these functions are in the strings package.
package stringslite import ( ) func (, string) bool { return len() >= len() && [0:len()] == } func (, string) bool { return len() >= len() && [len()-len():] == } func ( string, byte) int { return bytealg.IndexByteString(, ) } func (, string) int { := len() switch { case == 0: return 0 case == 1: return IndexByte(, [0]) case == len(): if == { return 0 } return -1 case > len(): return -1 case <= bytealg.MaxLen: // Use brute force when s and substr both are small if len() <= bytealg.MaxBruteForce { return bytealg.IndexString(, ) } := [0] := [1] := 0 := len() - + 1 := 0 for < { if [] != { // IndexByte is faster than bytealg.IndexString, so use it as long as // we're not getting lots of false positives. := IndexByte([+1:], ) if < 0 { return -1 } += + 1 } if [+1] == && [:+] == { return } ++ ++ // Switch to bytealg.IndexString when IndexByte produces too many false positives. if > bytealg.Cutover() { := bytealg.IndexString([:], ) if >= 0 { return + } return -1 } } return -1 } := [0] := [1] := 0 := len() - + 1 := 0 for < { if [] != { := IndexByte([+1:], ) if < 0 { return -1 } += + 1 } if [+1] == && [:+] == { return } ++ ++ if >= 4+>>4 && < { // See comment in ../bytes/bytes.go. := bytealg.IndexRabinKarp([:], ) if < 0 { return -1 } return + } } return -1 } func (, string) (, string, bool) { if := Index(, ); >= 0 { return [:], [+len():], true } return , "", false } func (, string) ( string, bool) { if !HasPrefix(, ) { return , false } return [len():], true } func (, string) ( string, bool) { if !HasSuffix(, ) { return , false } return [:len()-len()], true } func (, string) string { if HasPrefix(, ) { return [len():] } return } func (, string) string { if HasSuffix(, ) { return [:len()-len()] } return } func ( string) string { if len() == 0 { return "" } := make([]byte, len()) copy(, ) return unsafe.String(&[0], len()) }