go-vcard icon indicating copy to clipboard operation
go-vcard copied to clipboard

FieldValue type

Open oliverpool opened this issue 1 year ago • 1 comments

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 avatar Oct 23 '24 15:10 oliverpool

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

oliverpool avatar Oct 23 '24 17:10 oliverpool

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:

  • use slices instead of maps (preserves original ordering and casing)
  • version is an unexported property

oliverpool avatar Nov 09 '24 13:11 oliverpool

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.

emersion avatar Nov 11 '24 14:11 emersion