github.com/gidoBOSSftw5731/go/src@v0.0.0-20210226122457-d24b0edbf019/internal/poll/strconv.go (about)

     1  // Copyright 2009 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  //go:build plan9
     6  // +build plan9
     7  
     8  // Simple conversions to avoid depending on strconv.
     9  
    10  package poll
    11  
    12  // Convert integer to decimal string
    13  func itoa(val int) string {
    14  	if val < 0 {
    15  		return "-" + uitoa(uint(-val))
    16  	}
    17  	return uitoa(uint(val))
    18  }
    19  
    20  // Convert unsigned integer to decimal string
    21  func uitoa(val uint) string {
    22  	if val == 0 { // avoid string allocation
    23  		return "0"
    24  	}
    25  	var buf [20]byte // big enough for 64bit value base 10
    26  	i := len(buf) - 1
    27  	for val >= 10 {
    28  		q := val / 10
    29  		buf[i] = byte('0' + val - q*10)
    30  		i--
    31  		val = q
    32  	}
    33  	// val < 10
    34  	buf[i] = byte('0' + val)
    35  	return string(buf[i:])
    36  }
    37  
    38  // stringsHasSuffix is strings.HasSuffix. It reports whether s ends in
    39  // suffix.
    40  func stringsHasSuffix(s, suffix string) bool {
    41  	return len(s) >= len(suffix) && s[len(s)-len(suffix):] == suffix
    42  }