txt

package
v0.0.0-...-f1d475f Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: 0BSD Imports: 6 Imported by: 0

Documentation

Overview

Package txt provides text validation types, null terminated strings and a human readable textual struct tag.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Is

type Is[T any] string

Is denotes a string that should always contain values of the specified type. The type's pointer reciever should implement encoding.TextUnmarshaler or 'Parse(string) (*T, error)'

func (Is[T]) Get

func (val Is[T]) Get() (string, error)

Get returns the underlying string value if it matches T. Otherwise it returns an empty string and a non-nil error.

type Pointer

type Pointer struct {
	// contains filtered or unexported fields
}

Pointer to a null-terminated string. May point to memory not managed by the Go runtime. May or may not be mutable.

func Import

func Import(text unsafe.Pointer, size int, edit bool, free func()) Pointer

Import null-terminated text from the specified null-terminated memory address, if length is provided, no more than length bytes will be read from the address. The free function will be called when the [Ptr.Free] method is called. If [edit] is true, the string will be internally marked as mutable and will be copied when [Ptr.String] is called. If the size is not known, pass -1.

func New

func New(s string) Pointer

New returns a new pointer to a null-terminated string containing the first null-terminated string in s, if s is not already null-terminated, New will append the termination.

func (Pointer) Bytes

func (ptr Pointer) Bytes() []byte

Bytes returns the byte slice value of the pointer. If the pointer is not marked as mutable, a copy will be returned.

func (Pointer) Free

func (ptr Pointer) Free()

Free any foreign memory associated with the pointer setting it to nil. Future usage of the [Ptr] may result in a panic.

func (Pointer) Len

func (ptr Pointer) Len() (length int)

Len calculates and returns the length of the string.

func (Pointer) Mut

func (ptr Pointer) Mut() bool

Mut returns true if the pointer is mutable.

func (Pointer) SetUnsafePointer

func (ptr Pointer) SetUnsafePointer(addr unsafe.Pointer)

SetUnsafePointer modifies the pointer to the specified address, only valid when the pointer was previously created with Import.

func (Pointer) String

func (ptr Pointer) String() string

String returns the string value of the pointer. If the pointer is not marked as mutable, a copy will be returned.

func (Pointer) UnsafePointer

func (ptr Pointer) UnsafePointer() unsafe.Pointer

UnsafePointer takes ownership of the pointer and returns a pointer to the underlying memory.

Directories

Path Synopsis
std
human
Package human provides standard way to reference people by name.
Package human provides standard way to reference people by name.
markdown
Package markdown provide markdown types.
Package markdown provide markdown types.
src/js
Package js provides a way to represent JavaScript strings.
Package js provides a way to represent JavaScript strings.

Jump to

Keyboard shortcuts

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