From: Robert Griesemer Date: Mon, 12 Jun 2023 21:58:32 +0000 (-0700) Subject: spec: de-emphasize string(int) conversions X-Git-Tag: go1.21rc1~19 X-Git-Url: http://www.git.cypherpunks.ru/?a=commitdiff_plain;h=17dcbd866241c69990c23ce543ebd2906d546961;p=gostls13.git spec: de-emphasize string(int) conversions Fixes #60731. Change-Id: I71fad1c8385b13d036bb0ce7ae6bd21e0f596e51 Reviewed-on: https://go-review.googlesource.com/c/go/+/502657 Reviewed-by: Ian Lance Taylor Reviewed-by: Robert Griesemer TryBot-Bypass: Robert Griesemer --- diff --git a/doc/go_spec.html b/doc/go_spec.html index bb5b2f3db9..6e735e4373 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -5587,21 +5587,6 @@ succeeds but the result value is implementation-dependent.

Conversions to and from a string type

    -
  1. -Converting a signed or unsigned integer value to a string type yields a -string containing the UTF-8 representation of the integer. Values outside -the range of valid Unicode code points are converted to "\uFFFD". - -
    -string('a')       // "a"
    -string(-1)        // "\ufffd" == "\xef\xbf\xbd"
    -string(0xf8)      // "\u00f8" == "ø" == "\xc3\xb8"
    -
    -type myString string
    -myString(0x65e5)  // "\u65e5" == "日" == "\xe6\x97\xa5"
    -
    -
  2. -
  3. Converting a slice of bytes to a string type yields a string whose successive bytes are the elements of the slice. @@ -5668,6 +5653,31 @@ runes("白鵬翔") // []rune{0x767d, 0x9d6c, 0x7fd4} []myRune(myString("🌐")) // []myRune{0x1f310}
  4. + +
  5. +Finally, for historical reasons, an integer value may be converted to a string type. +This form of conversion yields a string containing the (possibly multi-byte) UTF-8 +representation of the Unicode code point with the given integer value. +Values outside the range of valid Unicode code points are converted to "\uFFFD". + +
    +string('a')          // "a"
    +string(65)           // "A"
    +string('\xf8')       // "\u00f8" == "ø" == "\xc3\xb8"
    +string(-1)           // "\ufffd" == "\xef\xbf\xbd"
    +
    +type myString string
    +myString('\u65e5')   // "\u65e5" == "日" == "\xe6\x97\xa5"
    +
    + +Note: This form of conversion may eventually be removed from the language. +The go vet tool flags certain +integer-to-string conversions as potential errors. +Library functions such as +utf8.AppendRune or +utf8.EncodeRune +should be used instead. +

Conversions from slice to array or array pointer