casemap

package
v0.0.0-...-1a94ce6 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package casemap folds nicks and channel names to a canonical form per the negotiated CASEMAPPING token so that case-insensitive comparison works.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mapper

type Mapper func(string) string

Mapper folds a string to its canonical lowercase form.

var ASCII Mapper = func(s string) string {
	var b strings.Builder
	b.Grow(len(s))
	for i := 0; i < len(s); i++ {
		c := s[i]
		if c >= 'A' && c <= 'Z' {
			c += 'a' - 'A'
		}
		b.WriteByte(c)
	}
	return b.String()
}

ASCII folds the bytes A-Z to lowercase and leaves all other bytes unchanged.

var RFC1459 Mapper = func(s string) string {
	var b strings.Builder
	b.Grow(len(s))
	for i := 0; i < len(s); i++ {
		c := s[i]
		switch c {
		case '{':
			c = '['
		case '}':
			c = ']'
		case '|':
			c = '\\'
		case '^':
			c = '~'
		default:
			if c >= 'A' && c <= 'Z' {
				c += 'a' - 'A'
			}
		}
		b.WriteByte(c)
	}
	return b.String()
}

RFC1459 folds ASCII letters and the classic { } | ^ equivalences to [ ] \ ~.

var RFC1459Strict Mapper = func(s string) string {
	var b strings.Builder
	b.Grow(len(s))
	for i := 0; i < len(s); i++ {
		c := s[i]
		switch c {
		case '{':
			c = '['
		case '}':
			c = ']'
		case '|':
			c = '\\'
		default:
			if c >= 'A' && c <= 'Z' {
				c += 'a' - 'A'
			}
		}
		b.WriteByte(c)
	}
	return b.String()
}

RFC1459Strict folds the same characters as RFC1459 but omits the ^ to ~ fold.

var RFC7613 Mapper = strings.ToLower

RFC7613 folds using strings.ToLower as a dependency-free approximation of PRECIS UsernameCaseMapped that is consistent for comparison but skips NFC normalisation.

func ByName

func ByName(s string) Mapper

ByName returns the Mapper named by the CASEMAPPING token s, defaulting to RFC1459.

Jump to

Keyboard shortcuts

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