(ns ^{:go-imports ["strconv"]
      :doc "Implements conversions to and from string representations of basic data types."}
  strconv)

(defn ^Int atoi
  "Equivalent to (parse-int s 10 0)."
  {:added "1.0"
   :go "!_res, err := strconv.Atoi(s); PanicOnErr(err)"}
  [^String s])

(defn ^Boolean can-backquote?
  "Reports whether the string s can be represented unchanged as a single-line backquoted string without control characters other than tab."
  {:added "1.0"
   :go "strconv.CanBackquote(s)"}
  [^String s])

(defn ^String format-bool
  "Returns \"true\" or \"false\" according to the value of b."
  {:added "1.0"
   :go "strconv.FormatBool(b)"}
  [^Boolean b])

(defn ^String format-double
  "Converts the floating-point number f to a string, according to the format fmt and precision prec. It rounds the result assuming that the original was obtained from a floating-point value of bitSize bits (32 for float32, 64 for float64).
  The format fmt is one of 'b' (-ddddp±ddd, a binary exponent), 'e' (-d.dddde±dd, a decimal exponent), 'E' (-d.ddddE±dd, a decimal exponent), 'f' (-ddd.dddd, no exponent), 'g' ('e' for large exponents, 'f' otherwise), or 'G' ('E' for large exponents, 'f' otherwise).
  The precision prec controls the number of digits (excluding the exponent) printed by the 'e', 'E', 'f', 'g', and 'G' formats. For 'e', 'E', and 'f' it is the number of digits after the decimal point. For 'g' and 'G' it is the maximum number of significant digits (trailing zeros are removed). The special precision -1 uses the smallest number of digits necessary such that ParseFloat will return f exactly."
  {:added "1.0"
   :go "strconv.FormatFloat(f, byte(fmt), prec, bitSize)"}
  [^Double f ^Char fmt ^Int prec ^Int bitSize])

(defn ^String format-int
  "Returns the string representation of i in the given base, for 2 <= base <= 36. The result uses the lower-case letters 'a' to 'z' for digit values >= 10."
  {:added "1.0"
   :go "strconv.FormatInt(int64(i), base)"}
  [^Int i ^Int base])

(defn ^Boolean graphic?
  "Reports whether the char 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."
  {:added "1.0"
   :go "strconv.IsGraphic(c)"}
  [^Char c])

(defn ^Boolean printable?
  "Reports whether the char is defined as printable by Joker: letters, numbers, punctuation, symbols and ASCII space."
  {:added "1.0"
   :go "strconv.IsPrint(c)"}
  [^Char c])

(defn ^String itoa
  "Equivalent to (format-int i 10)."
  {:added "1.0"
   :go "strconv.Itoa(i)"}
  [^Int i])

(defn ^Boolean parse-bool
  "Returns the boolean value represented by the string. It accepts 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False. Any other value returns an error."
  {:added "1.0"
   :go "!_res, err := strconv.ParseBool(s); PanicOnErr(err)"}
  [^String s])

(defn ^Double parse-double
  "Converts the string s to a floating-point number."
  {:added "1.0"
   :go "!_res, err := strconv.ParseFloat(s, 64); PanicOnErr(err)"}
  [^String s])

(defn ^Int parse-int
  "Interprets a string s in the given base (0, 2 to 36) and bit size (0 to 64) and returns the corresponding value i.
  If base == 0, the base is implied by the string's prefix: base 16 for \"0x\", base 8 for \"0\", and base 10 otherwise. For bases 1, below 0 or above 36 an error is returned.
  The bitSize argument specifies the integer type that the result must fit into. Bit sizes 0, 8, 16, 32, and 64 correspond to int, int8, int16, int32, and int64. For a bitSize below 0 or above 64 an error is returned."
  {:added "1.0"
   ;; TODO: 32-bit issue
   :go "!t, err := strconv.ParseInt(s, base, bitSize); PanicOnErr(err); _res := int(t)"}
  [^String s ^Int base ^Int bitSize])

(defn ^String quote
  "Returns a double-quoted string literal representing s. The returned string uses escape sequences (\\t, \\n, \\xFF, \\u0100)
  for control characters and non-printable characters as defined by printable?."
  {:added "1.0"
   :go "strconv.Quote(s)"}
  [^String s])

(defn ^String quote-char
  "Returns a single-quoted char literal representing the character. The returned string uses escape sequences (\\t, \\n, \\xFF, \\u0100)
  for control characters and non-printable characters as defined by printable?."
  {:added "1.0"
   :go "strconv.QuoteRune(c)"}
  [^Char c])

(defn ^String quote-char-to-ascii
  "Returns a single-quoted char literal representing the character. The returned string uses escape sequences (\\t, \\n, \\xFF, \\u0100)
  for non-ASCII characters and non-printable characters as defined by printable?."
  {:added "1.0"
   :go "strconv.QuoteRuneToASCII(c)"}
  [^Char c])

(defn ^String quote-char-to-graphic
  "Returns a single-quoted char literal representing the character. The returned string uses escape sequences (\\t, \\n, \\xFF, \\u0100)
  for non-ASCII characters and non-printable characters as defined by graphic?."
  {:added "1.0"
   :go "strconv.QuoteRuneToGraphic(c)"}
  [^Char c])

(defn ^String quote-to-ascii
  "Returns a double-quoted string literal representing s. The returned string uses escape sequences (\\t, \\n, \\xFF, \\u0100)
  for non-ASCII characters and non-printable characters as defined by printable?."
  {:added "1.0"
   :go "strconv.QuoteToASCII(s)"}
  [^String s])

(defn ^String quote-to-graphic
  "Returns a double-quoted string literal representing s. The returned string uses escape sequences (\\t, \\n, \\xFF, \\u0100)
  for non-ASCII characters and non-printable characters as defined by graphic?."
  {:added "1.0"
   :go "strconv.QuoteToGraphic(s)"}
  [^String s])

(defn ^String unquote
  "Interprets s as a single-quoted, double-quoted, or backquoted string literal, returning the string value that s quotes.
  (If s is single-quoted, it would be a Go character literal; Unquote returns the corresponding one-character string.)"
  {:added "1.0"
   :go "!_res, err := strconv.Unquote(s); PanicOnErr(err)"}
  [^String s])
