github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/modules/wasm/abi/proxy/util.go (about)

     1  package proxy
     2  
     3  // subStringWithLength
     4  // If the length is negative, an empty string is returned.
     5  // If the length is greater than the length of the input string, the entire string is returned.
     6  // Otherwise, a substring of the input string with the specified length is returned.
     7  func subStringWithLength(str string, length int) string {
     8  	if length < 0 {
     9  		return ""
    10  	}
    11  	rs := []rune(str)
    12  	strLen := len(rs)
    13  
    14  	if length > strLen {
    15  		return str
    16  	}
    17  	return string(rs[0:length])
    18  }