string.go (820B)
1 package util 2 3 import ( 4 "strconv" 5 "strings" 6 "unicode" 7 ) 8 9 func FormatSignedFixedFloat1616(val int32) string { 10 if val&0xffff == 0 { 11 return strconv.Itoa(int(val >> 16)) 12 } else { 13 return strconv.FormatFloat(float64(val)/(1<<16), 'f', 5, 64) 14 } 15 } 16 17 func FormatUnsignedFixedFloat1616(val uint32) string { 18 if val&0xffff == 0 { 19 return strconv.Itoa(int(val >> 16)) 20 } else { 21 return strconv.FormatFloat(float64(val)/(1<<16), 'f', 5, 64) 22 } 23 } 24 25 func FormatSignedFixedFloat88(val int16) string { 26 if val&0xff == 0 { 27 return strconv.Itoa(int(val >> 8)) 28 } else { 29 return strconv.FormatFloat(float64(val)/(1<<8), 'f', 3, 32) 30 } 31 } 32 33 func EscapeUnprintable(r rune) rune { 34 if unicode.IsGraphic(r) { 35 return r 36 } 37 return rune('.') 38 } 39 40 func EscapeUnprintables(src string) string { 41 return strings.Map(EscapeUnprintable, src) 42 }