contentline

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package contentline reads and patches the content lines of vCard (RFC 6350) and iCalendar (RFC 5545) objects. Parse keeps each property's place in the source, so a change replaces the lines it touches and leaves every other byte as the server sent it (ADR-0018).

Index

Constants

This section is empty.

Variables

View Source
var ErrSyntax = errors.New("contentline: syntax error")

ErrSyntax wraps every parse error.

Functions

func Apply

func Apply(src []byte, edits ...Edit) ([]byte, error)

Apply returns src with the edits made. Edits may come in any order but must not overlap; two insertions at the same place keep their order, and an insertion goes before an edit that replaces text starting there.

func EscapeText

func EscapeText(s string) string

EscapeText escapes a TEXT value: backslash, semicolon, comma and newline (RFC 5545 §3.3.11). Carriage returns are dropped.

func Fold

func Fold(s, eol string) string

Fold splits a logical line into lines of at most 75 octets, never inside a UTF-8 sequence; each continuation starts with a space, and every line ends in eol.

func JoinFields

func JoinFields(fields ...string) string

JoinFields escapes each field and joins them with semicolons, for N, ADR and ORG.

func LineEnding

func LineEnding(src []byte) string

LineEnding returns the line ending src uses: "\n" when its first line ends in a bare LF, else "\r\n".

Types

type Component

type Component struct {
	Name     string // uppercased
	Props    []Prop // the component's own properties, without BEGIN and END
	Children []*Component
	// Start and End are the block's bytes in the source, from its BEGIN
	// line to its END line's line ending.
	Start, End int
}

Component is a BEGIN/END block: a VCARD, VCALENDAR, VEVENT, VALARM, ….

func Parse

func Parse(src []byte) ([]*Component, error)

Parse reads the top-level components in src. Lines end in CRLF or LF; a line that starts with a space or tab continues the one before it. Empty lines are skipped.

func (*Component) ChildrenNamed

func (c *Component) ChildrenNamed(name string) []*Component

ChildrenNamed returns the component's children with the name, in order.

func (*Component) Prop

func (c *Component) Prop(name string) *Prop

Prop returns the component's first property with the name, or nil.

func (*Component) PropsNamed

func (c *Component) PropsNamed(name string) []Prop

PropsNamed returns the component's properties with the name, in order.

type Edit

type Edit struct {
	Start, End int
	Text       string
}

Edit replaces src[Start:End] with Text. Start == End inserts.

type Param

type Param struct {
	Name   string   // uppercased
	Values []string // unquoted, RFC 6868 caret escapes decoded
}

Param is one property parameter. A parameter may repeat; each occurrence is its own Param.

type Prop

type Prop struct {
	Group  string  // the vCard group, such as item1; empty when there is none
	Name   string  // uppercased
	Params []Param // in source order
	Value  string  // as written: escapes intact
	// Start and End are the folded line's bytes in the source, its line
	// ending included.
	Start, End int
}

Prop is one property: a content line, unfolded.

func (Prop) Encode

func (p Prop) Encode(eol string) string

Encode formats the property as content lines folded at 75 octets, each ending in eol ("\r\n", or "\n" to match a source that uses it). Start and End are ignored.

func (Prop) Fields

func (p Prop) Fields() []string

Fields splits a structured value (N, ADR, ORG, GENDER) at unescaped semicolons and unescapes each field.

func (Prop) HasParam

func (p Prop) HasParam(name, value string) bool

HasParam reports whether the named parameter has value, ignoring case.

func (Prop) Param

func (p Prop) Param(name string) string

Param returns the first value of the named parameter, or "".

func (Prop) ParamValues

func (p Prop) ParamValues(name string) []string

ParamValues returns every value of the named parameter across its occurrences, with comma-separated values split (TYPE=work,voice).

func (Prop) Text

func (p Prop) Text() string

Text is the value as TEXT (RFC 5545 §3.3.11, RFC 6350 §3.4): \n and \N are newlines, and a backslash before any other character stands for that character.

Jump to

Keyboard shortcuts

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