...
Run Format

Source file src/internal/poll/strconv.go

Documentation: internal/poll

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

View as plain text