Source file src/internal/bytealg/lastindexbyte_generic.go

     1  // Copyright 2023 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package bytealg
     6  
     7  func LastIndexByte(s []byte, c byte) int {
     8  	for i := len(s) - 1; i >= 0; i-- {
     9  		if s[i] == c {
    10  			return i
    11  		}
    12  	}
    13  	return -1
    14  }
    15  
    16  func LastIndexByteString(s string, c byte) int {
    17  	for i := len(s) - 1; i >= 0; i-- {
    18  		if s[i] == c {
    19  			return i
    20  		}
    21  	}
    22  	return -1
    23  }
    24  

View as plain text