package module
Version: v1.0.3 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Mar 30, 2021 License: Apache-2.0 Imports: 3 Imported by: 51


This was renamed to xdg-go/stringprep in October 2018. This didn't break dependencies at the time because Github redirected requests. In March 2021, I made xdg-go/stringprep a module, which can't be used as xdg/stringprep with Github redirects. This repository has been recreated to support legacy dependencies.



Package stringprep provides data tables and algorithms for RFC-3454, including errata (as of 2018-02). It also provides a profile for SASLprep as defined in RFC-4013.

Example (CustomProfile)
package main

import (


func main() {
	customProfile := stringprep.Profile{
		Mappings: []stringprep.Mapping{
		Normalize: true,
		Prohibits: []stringprep.Set{
		CheckBiDi: true,

	prepped, err := customProfile.Prepare("TrustNô1")
	if err != nil {
		panic("stringprep failed")


Example (SASLprep)
package main

import (


func main() {
	prepped, err := stringprep.SASLprep.Prepare("TrustNô1")
	if err != nil {
		panic("SASLprep failed")





This section is empty.


This section is empty.


This section is empty.


type Error

type Error struct {
	Msg  string
	Rune rune

Error describes problems encountered during stringprep, including what rune was problematic.

func (Error) Error

func (e Error) Error() string

type Mapping

type Mapping map[rune][]rune

Mapping represents a stringprep mapping, from a single rune to zero or more runes.

var TableB1 Mapping = tableB1

TableB1 represents RFC-3454 Table B.1.

var TableB2 Mapping = tableB2

TableB2 represents RFC-3454 Table B.2.

var TableB3 Mapping = tableB3

TableB3 represents RFC-3454 Table B.3.

func (Mapping) Map

func (m Mapping) Map(r rune) (replacement []rune, ok bool)

Map maps a rune to a (possibly empty) rune slice via a stringprep Mapping. The ok return value is false if the rune was not found.

type Profile

type Profile struct {
	Mappings  []Mapping
	Normalize bool
	Prohibits []Set
	CheckBiDi bool

Profile represents a stringprep profile.

var SASLprep Profile = saslprep

SASLprep is a pre-defined stringprep profile for user names and passwords as described in RFC-4013.

Because the stringprep distinction between query and stored strings was intended for compatibility across profile versions, but SASLprep was never updated and is now deprecated, this profile only operates in stored strings mode, prohibiting unassigned code points.

func (Profile) Prepare

func (p Profile) Prepare(s string) (string, error)

Prepare transforms an input string to an output string following the rules defined in the profile as defined by RFC-3454.

type RuneRange

type RuneRange [2]rune

RuneRange represents a close-ended range of runes: [N,M]. For a range consisting of a single rune, N and M will be equal.

func (RuneRange) Contains

func (rr RuneRange) Contains(r rune) bool

Contains returns true if a rune is within the bounds of the RuneRange.

type Set

type Set []RuneRange

Set represents a stringprep data table used to identify runes of a particular type.

var TableA1 Set = tableA1

TableA1 represents RFC-3454 Table A.1.

var TableC1_1 Set = tableC1_1

TableC1_1 represents RFC-3454 Table C.1.1.

var TableC1_2 Set = tableC1_2

TableC1_2 represents RFC-3454 Table C.1.2.

var TableC2_1 Set = tableC2_1

TableC2_1 represents RFC-3454 Table C.2.1.

var TableC2_2 Set = tableC2_2

TableC2_2 represents RFC-3454 Table C.2.2.

var TableC3 Set = tableC3

TableC3 represents RFC-3454 Table C.3.

var TableC4 Set = tableC4

TableC4 represents RFC-3454 Table C.4.

var TableC5 Set = tableC5

TableC5 represents RFC-3454 Table C.5.

var TableC6 Set = tableC6

TableC6 represents RFC-3454 Table C.6.

var TableC7 Set = tableC7

TableC7 represents RFC-3454 Table C.7.

var TableC8 Set = tableC8

TableC8 represents RFC-3454 Table C.8.

var TableC9 Set = tableC9

TableC9 represents RFC-3454 Table C.9.

var TableD1 Set = tableD1

TableD1 represents RFC-3454 Table D.1.

var TableD2 Set = tableD2

TableD2 represents RFC-3454 Table D.2.

func (Set) Contains

func (s Set) Contains(r rune) bool

Contains returns true if a rune is within any of the RuneRanges in the Set.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL