xid

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2023 License: MIT Imports: 2 Imported by: 2

README

xid

PkgGoDev Test

Package xid implements validation functions for unicode identifiers, as defined in UAX#31: https://unicode.org/reports/tr31/. The syntax for an identifier is:

<identifier> := <xid_start> <xid_continue>*

where <xid_start> and <xid_continue> derive from <id_start> and <id_continue>, respectively, and check their NFKC normalized forms.

Documentation

Overview

Package xid implements validation functions for unicode identifiers, as defined in UAX#31: https://unicode.org/reports/tr31/. The syntax for an identifier is:

<identifier> := <xid_start> <xid_continue>*

where <xid_start> and <xid_continue> derive from <id_start> and <id_continue>, respectively, and check their NFKC normalized forms.

Example
isIdent := func(input string) bool {
	// identifier should be non-empty
	if input == "" {
		return false
	}
	for i, r := range input {
		if i == 0 {
			// first rune should be in xid_start
			if !Start(r) {
				return false
			}
		} else {
			// other runes should be in xid_continue
			if !Continue(r) {
				return false
			}
		}
	}
	return true
}
fmt.Println(isIdent("index"))
fmt.Println(isIdent("snake_case"))
fmt.Println(isIdent("Δx"))
fmt.Println(isIdent("xₒ"))
fmt.Println(isIdent("ä"))
fmt.Println(isIdent("aᵢ"))
fmt.Println(isIdent("मूलधन"))
fmt.Println(isIdent("kebab-case"))
fmt.Println(isIdent("3x"))
fmt.Println(isIdent("_id"))
Output:

true
true
true
true
true
true
true
false
false
false

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Continue

func Continue(r rune) bool

Continue checks that the rune continues an identifier.

func Start

func Start(r rune) bool

Start checks that the rune begins an identifier.

Types

This section is empty.

Jump to

Keyboard shortcuts

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