Search results

There are no results.

std.uri.decode

Show source code
Hide source code
fn pub decode[B: Bytes](input: ref B, output: mut ByteArray) -> Bool {
  let mut idx = 0
  let mut start = 0
  let len = input.size

  while idx < len {
    match input.get(idx).or_panic {
      case PERC -> {
        if idx > start { output.append(Slice.new(input, start, idx)) }

        match decode_triplet(input, idx + 1) {
          case Some(v) -> output.push(v)
          case _ -> return false
        }

        idx += 3
        start = idx
        next
      }
      case _ -> {}
    }

    idx += 1
  }

  if idx > start { output.append(Slice.new(input, start, idx)) }

  true
}
fn pub static decode[B: Bytes](input: ref B, output: mut ByteArray) -> Bool

Percent decodes a Bytes value into a ByteArray

If the input is valid and decoded, the return value is true. If the input contains invalid percent sequences, false is returned instead.

For more information, refer to the documentation of std.uri.encode.

Examples

import std.uri (decode, encode)

let encoded = ByteArray.new
let decoded = ByteArray.new

encode('😃', encoded)
decode(encoded, decoded)
decoded.to_string # => '😃'