Module ggstd::strconv

source ·
Expand description

Package strconv implements conversions to and from string representations of basic data types.

String Conversions

Quote and QuoteToASCII convert strings to quoted Go string literals. The latter guarantees that the result is an ASCII string, by escaping any non-ASCII Unicode with \u:

use ggstd::strconv;

let q = strconv::quote("Hello, 世界");
let q = strconv::quote_to_ascii("Hello, 世界");

Functions

  • append_quote appends a double-quoted Go string literal representing s, as generated by Quote, to dst and returns the extended buffer.
  • append_quote_to_ascii appends a double-quoted Go string literal representing s, as generated by quote_to_ascii, to dst and returns the extended buffer.
  • append_quote_to_graphic appends a double-quoted Go string literal representing s, as generated by quote_to_graphic, to dst and returns the extended buffer.
  • is_graphic reports whether the rune is defined as a Graphic by Unicode. Such characters include letters, marks, numbers, punctuation, symbols, and spaces, from categories L, M, N, P, S, and Zs.
  • is_print reports whether the rune is defined as printable by Go, with the same definition as unicode.is_print: letters, numbers, punctuation, symbols and ASCII space.
  • quote returns a double-quoted Go string literal representing s. The returned string uses Go escape sequences (\t, \n, \xFF, \u0100) for control characters and non-printable characters as defined by is_print.
  • quote_bytes_string is similar to Quote, but takes slice of bytes instead of a string. This is useful in cases when replacing Go Quote function when the Go string contains arbitrary data (in Go strings can contain arbitrary data, in Rust they cannot).
  • quote_to_ascii returns a double-quoted Go string literal representing s. The returned string uses Go escape sequences (\t, \n, \xFF, \u0100) for non-ASCII characters and non-printable characters as defined by is_print.
  • quote_to_graphic returns a double-quoted Go string literal representing s. The returned string leaves Unicode graphic characters, as defined by is_graphic, unchanged and uses Go escape sequences (\t, \n, \xFF, \u0100) for non-graphic characters.