Explorer

definy.json-escape-byte

description
The JSON string escape of one UTF-8 byte of value at start (the byte itself when it needs no escape)
type
Fn(value: String, byte: Number, start: Number) -> String
expression
fn(value$0, byte$1, start$2) =>
  match @core.equal(left: $1, right: 34) {
    true =>
      "\\\"",
    false =>
      match @core.equal(left: $1, right: 92) {
        true =>
          "\\\\",
        false =>
          match @core.equal(left: $1, right: 10) {
            true =>
              "\\n",
            false =>
              match @core.equal(left: $1, right: 13) {
                true =>
                  "\\r",
                false =>
                  match @core.equal(left: $1, right: 9) {
                    true =>
                      "\\t",
                    false =>
                      match @core.less-than(left: $1, right: 32) {
                        true =>
                          @core.string-concat(
                            left: "\\u00",
                            right: @core.string-concat(
                              left: @core.string-slice(
                                value: "0123456789abcdef",
                                start: @core.divide(left: $1, right: 16),
                                end: @core.plus(left: @core.divide(left: $1, right: 16), right: 1)
                              ),
                              right: @core.string-slice(
                                value: "0123456789abcdef",
                                start: @core.remainder(left: $1, right: 16),
                                end: @core.plus(left: @core.remainder(left: $1, right: 16), right: 1)
                              )
                            )
                          ),
                        false =>
                          @core.string-slice(value: $0, start: $2, end: @core.plus(left: $2, right: 1))
                      }
                  }
              }
          }
      }
  }
visibility
public
definy.json-escape-byte (project definy, branch release-time-compare, snapshot JJrRgQW_LZN6tN8CbYr1dN7HosqNTuIWWYx7ACbt1n0)
id: dGrDCoKyfwuShaYpOSYGmZLG2F-xkH6c5SGJIx_GQE8
content hash: FW_uF441mZ8M9dhCPX6UWfSp2xOJjX5w1iOptSHIlQ0