emersion / go-vcard

A Go library to parse and format vCard
MIT License
107 stars 34 forks source link

FieldValue type #35

Open oliverpool opened 1 month ago

oliverpool commented 1 month ago

Supersedes #11 and #34. Resolves #5 and #26

This is a breaking change

This changes the string type from the Field.Value to a dedicated FieldValue type (backed by a string):

// FieldValue contains the raw field value.
// Use [NewFieldValue] to construct a properly escaped field value.
type FieldValue string

// NewFieldValue creates a new FieldValue after
// escaping each part (backslash, newline, comma)
func NewFieldValue(parts ...string) FieldValue 

Users who want the raw value, can call FieldValue.String(). To get escaped values, call FieldValue.Values().

oliverpool commented 1 month ago

I can confirm that this helps a bit with https://github.com/emersion/go-webdav/issues/173 (conformance test for carddav server)

oliverpool commented 2 weeks ago

FYI I am giving a try to a larger refactoring in a dedicated package (loose fork): https://code.pfad.fr/gopim/vcard/

Main differences for users:

emersion commented 2 weeks ago

I'm not a fan of this approach in general. If there is no way around it, would prefer some dedicated getter/setter, just like we have for other data types.