Extensions for kotlin.String

decodeURLPart

fun String.decodeURLPart(
    start: Int = 0,
    end: Int = length,
    charset: Charset = Charsets.UTF_8
): String

Decode percent encoded URL part within the specified range [start, end). This function is not intended to decode urlencoded forms so it doesn’t decode plus character to space.

decodeURLQueryComponent

fun String.decodeURLQueryComponent(
    start: Int = 0,
    end: Int = length,
    plusIsSpace: Boolean = false,
    charset: Charset = Charsets.UTF_8
): String

Decode URL query component

encodeOAuth

fun String.encodeOAuth(): String

Encode this in percent encoding specified here: https://tools.ietf.org/html/rfc5849#section-3.6

encodeURLParameter

fun String.encodeURLParameter(
    spaceToPlus: Boolean = false
): String

Encode this as query parameter

encodeURLPath

fun String.encodeURLPath(): String

Encode URL path or component. It escapes all illegal or ambiguous characters

encodeURLQueryComponent

fun String.encodeURLQueryComponent(
    encodeFull: Boolean = false,
    spaceToPlus: Boolean = false,
    charset: Charset = Charsets.UTF_8
): String

Encode url part as specified in https://tools.ietf.org/html/rfc3986#section-2

escapeIfNeeded

fun String.escapeIfNeeded(): String

Escape using double quotes if needed or keep as is if no dangerous strings found

fromHttpDateString

fun String.fromHttpDateString(): ZonedDateTime

Parse HTTP date to ZonedDateTime

fromHttpToGmtDate

fun String.fromHttpToGmtDate(): GMTDate

Convert valid http date String to GMTDate according to: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Date format: <day-name>{3}, {2} {3} {4} {2}:{2}:{2} GMT String size should be equals 29

parseUrlEncodedParameters

fun String.parseUrlEncodedParameters(
    defaultEncoding: Charset = Charsets.UTF_8,
    limit: Int = 1000
): Parameters

Parse URL query parameters. Shouldn’t be used for urlencoded forms because of + character.

quote

fun String.quote(): String

Escape string using double quotes