Search results

There are no results.

std.uri.Fragment

type pub inline Fragment

The fragment string of a URI.

A Fragment wraps a String that's valid for a URI fragment. Characters not allowed in the fragment string component (e.g. non-ASCII characters) are percent-encoded.

Static methods

empty

Show source code
Hide source code
fn pub static empty -> Self {
  Self('')
}
fn pub static empty -> Fragment

Returns an empty Fragment

Examples

import std.uri (Fragment)

Fragment.empty.empty? # => true

new

Show source code
Hide source code
fn pub static new[B: Bytes](value: ref B) -> Option[Self] {
  match parse(value, start: 0, standalone: true) {
    case Ok((Some(v), _)) -> Option.Some(v)
    case Ok(_) -> Option.Some(Self(''))
    case _ -> Option.None
  }
}
fn pub static new[B: Bytes](value: ref B) -> Option[Fragment]

Parses a Fragment from the given String.

The input should not start with a # as it will be treated as being part of the value, instead of merely signalling the start of the value.

While this method validates percent-encoded sequences it doesn't decode them. For that you can use Fragment.to_byte_array and Fragment.to_string.

If the input is invalid (e.g. it contains invalid percent-encoded sequences), an Option.None is returned. If the input is empty, an empty Fragment is returned.

Examples

import std.uri (Fragment)

Fragment.new('foo') # => Option.Some(Fragment('foo'))
Fragment.new('# foo') # => Option.None

Instance methods

!=

Show source code
Hide source code
fn pub !=(other: ref Self) -> Bool {
  !(self == other)
}
fn pub !=(other: ref Self) -> Bool

Returns true if self and the given object are not equal to each other.

==

Show source code
Hide source code
fn pub ==(other: ref Fragment) -> Bool {
  @value == other.value
}
fn pub ==(other: ref Fragment) -> Bool

Returns true if self and other are equal.

This method doesn't perform any percent decoding or normalization.

clone

Show source code
Hide source code
fn pub clone -> Self {
  Self(@value)
}
fn pub clone -> Fragment

Creates a clone of self.

The returned value is an owned value that is the same type as the receiver of this method. For example, cloning a ref Array[Int] results in a Array[Int], not another ref Array[Int].

empty?

Show source code
Hide source code
fn pub inline empty? -> Bool {
  size == 0
}
fn pub inline empty? -> Bool

Returns true if self is empty.

Examples

import std.uri (Fragment)

Fragment.new('').empty? # => true
Fragment.new('foo').empty? # => false

fmt

Show source code
Hide source code
fn pub fmt(formatter: mut Formatter) {
  formatter.object('Fragment').field('value', @value).finish
}
fn pub fmt(formatter: mut Formatter)

Formats self in a human-readable format for debugging purposes.

size

Show source code
Hide source code
fn pub inline size -> Int {
  @value.size
}
fn pub inline size -> Int

Returns the size of self, before applying percent decoding.

Examples

import std.uri (Fragment)

Fragment.new('').get.size # => 0
Fragment.new('a%20b').get.size # => 5

to_byte_array

Show source code
Hide source code
fn pub to_byte_array -> ByteArray {
  let buf = ByteArray.new

  decode(@value, buf)
  buf
}
fn pub to_byte_array -> ByteArray

Returns a ByteArray containing the percent-decoded value of self.

The return type is a ByteArray instead of String because after percent decoding the data may contain bytes that aren't valid UTF-8, such as when encoding an image into a fragment string.

to_string

Show source code
Hide source code
fn pub to_string -> String {
  to_byte_array.into_string
}
fn pub to_string -> String

Returns a String containing the percent-decoded value of self.

If after decoding the data contains bytes that aren't valid UTF-8, these bytes are replaced with U+FFFD REPLACEMENT CHARACTER.

Implemented traits

std.bytes.

ToByteArray

impl ToByteArray for Fragment
std.clone.

Clone

impl Clone for Fragment
std.cmp.

Equal

impl Equal for Fragment
std.fmt.

Format

impl Format for Fragment
std.string.

ToString

impl ToString for Fragment