ics - properties.go
1 package ics
2
3 // File automatically generated with ./genProperties.sh
4
5 import (
6 "errors"
7 "fmt"
8 "strings"
9
10 "vimagination.zapto.org/parser"
11 )
12
13 // PropAction defines the action to be invoked when an alarm is triggered
14 type PropAction uint8
15
16 // PropAction constant values
17 const (
18 ActionAudio PropAction = iota
19 ActionDisplay
20 ActionEmail
21 )
22
23 // New returns a pointer to the type (used with constants for ease of use with
24 // optional values)
25 func (p PropAction) New() *PropAction {
26 return &p
27 }
28
29 func (p *PropAction) decode(params []parser.Token, value string) error {
30 switch strings.ToUpper(value) {
31 case "AUDIO":
32 *p = ActionAudio
33 case "DISPLAY":
34 *p = ActionDisplay
35 case "EMAIL":
36 *p = ActionEmail
37 default:
38 return fmt.Errorf(errDecodingType, cAction, ErrInvalidValue)
39 }
40 return nil
41 }
42
43 func (p *PropAction) encode(w writer) {
44 w.WriteString("ACTION:")
45 switch *p {
46 case ActionAudio:
47 w.WriteString("AUDIO")
48 case ActionDisplay:
49 w.WriteString("DISPLAY")
50 case ActionEmail:
51 w.WriteString("EMAIL")
52 }
53 w.WriteString("\r\n")
54 }
55
56 func (p *PropAction) valid() error {
57 switch *p {
58 case ActionAudio, ActionDisplay, ActionEmail:
59 default:
60 return fmt.Errorf(errValidatingType, cAction, ErrInvalidValue)
61 }
62 return nil
63 }
64
65 // PropAttachment provides the capability to associate a document object with a
66 // calendar component
67 type PropAttachment struct {
68 FormatType *ParamFormatType
69 URI *URI
70 Binary *Binary
71 }
72
73 func (p *PropAttachment) decode(params []parser.Token, value string) error {
74 vType := -1
75 oParams := make(map[string]string)
76 var ts []string
77 for len(params) > 0 {
78 pName := strings.ToUpper(params[0].Data)
79 i := 1
80 for i < len(params) && params[i].Type != tokenParamName {
81 i++
82 }
83 pValues := params[1:i]
84 params = params[i:]
85 switch pName {
86 case "FMTTYPE":
87 if p.FormatType != nil {
88 return fmt.Errorf(errDecodingProp, cAttachment, cFormatType, ErrDuplicateParam)
89 }
90 p.FormatType = new(ParamFormatType)
91 if err := p.FormatType.decode(pValues); err != nil {
92 return fmt.Errorf(errDecodingProp, cAttachment, cFormatType, err)
93 }
94 case "VALUE":
95 if len(pValues) != 1 {
96 return fmt.Errorf(errDecodingProp, cAttachment, cValue, ErrInvalidValue)
97 }
98 if vType != -1 {
99 return fmt.Errorf(errDecodingProp, cAttachment, cValue, ErrDuplicateParam)
100 }
101 switch strings.ToUpper(pValues[0].Data) {
102 case "URI":
103 vType = 0
104 case "BINARY":
105 vType = 1
106 default:
107 return fmt.Errorf(errDecodingType, cAttachment, ErrInvalidValue)
108 }
109 default:
110 for _, v := range pValues {
111 ts = append(ts, v.Data)
112 }
113 oParams[pName] = strings.Join(ts, ",")
114 ts = ts[:0]
115 }
116 }
117 if vType == -1 {
118 vType = 0
119 }
120 switch vType {
121 case 0:
122 p.URI = new(URI)
123 if err := p.URI.decode(oParams, value); err != nil {
124 return fmt.Errorf(errDecodingProp, cAttachment, cURI, err)
125 }
126 case 1:
127 p.Binary = new(Binary)
128 if err := p.Binary.decode(oParams, value); err != nil {
129 return fmt.Errorf(errDecodingProp, cAttachment, cBinary, err)
130 }
131 }
132 return nil
133 }
134
135 func (p *PropAttachment) encode(w writer) {
136 w.WriteString("ATTACH")
137 if p.FormatType != nil {
138 p.FormatType.encode(w)
139 }
140 if p.URI != nil {
141 p.URI.aencode(w)
142 }
143 if p.Binary != nil {
144 w.WriteString(";VALUE=BINARY")
145 p.Binary.aencode(w)
146 }
147 w.WriteString("\r\n")
148 }
149
150 func (p *PropAttachment) valid() error {
151 if p.FormatType != nil {
152 if err := p.FormatType.valid(); err != nil {
153 return fmt.Errorf(errValidatingProp, cAttachment, cFormatType, err)
154 }
155 }
156 c := 0
157 if p.URI != nil {
158 if err := p.URI.valid(); err != nil {
159 return fmt.Errorf(errValidatingProp, cAttachment, cURI, err)
160 }
161 c++
162 }
163 if p.Binary != nil {
164 if err := p.Binary.valid(); err != nil {
165 return fmt.Errorf(errValidatingProp, cAttachment, cBinary, err)
166 }
167 c++
168 }
169 if c != 1 {
170 return fmt.Errorf(errValidatingType, cAttachment, ErrInvalidValue)
171 }
172 return nil
173 }
174
175 // PropAttendee defines an "Attendee" within a calendar component
176 type PropAttendee struct {
177 CalendarUserType *ParamCalendarUserType
178 Member ParamMember
179 ParticipationRole *ParamParticipationRole
180 ParticipationStatus *ParamParticipationStatus
181 RSVP *ParamRSVP
182 Delagatee ParamDelagatee
183 Delegator ParamDelegator
184 SentBy *ParamSentBy
185 CommonName *ParamCommonName
186 DirectoryEntry *ParamDirectoryEntry
187 Language *ParamLanguage
188 CalendarAddress
189 }
190
191 func (p *PropAttendee) decode(params []parser.Token, value string) error {
192 oParams := make(map[string]string)
193 var ts []string
194 for len(params) > 0 {
195 pName := strings.ToUpper(params[0].Data)
196 i := 1
197 for i < len(params) && params[i].Type != tokenParamName {
198 i++
199 }
200 pValues := params[1:i]
201 params = params[i:]
202 switch pName {
203 case "CUTYPE":
204 if p.CalendarUserType != nil {
205 return fmt.Errorf(errDecodingProp, cAttendee, cCalendarUserType, ErrDuplicateParam)
206 }
207 p.CalendarUserType = new(ParamCalendarUserType)
208 if err := p.CalendarUserType.decode(pValues); err != nil {
209 return fmt.Errorf(errDecodingProp, cAttendee, cCalendarUserType, err)
210 }
211 case "MEMBER":
212 if p.Member != nil {
213 return fmt.Errorf(errDecodingProp, cAttendee, cMember, ErrDuplicateParam)
214 }
215 if err := p.Member.decode(pValues); err != nil {
216 return fmt.Errorf(errDecodingProp, cAttendee, cMember, err)
217 }
218 case "ROLE":
219 if p.ParticipationRole != nil {
220 return fmt.Errorf(errDecodingProp, cAttendee, cParticipationRole, ErrDuplicateParam)
221 }
222 p.ParticipationRole = new(ParamParticipationRole)
223 if err := p.ParticipationRole.decode(pValues); err != nil {
224 return fmt.Errorf(errDecodingProp, cAttendee, cParticipationRole, err)
225 }
226 case "PARTSTAT":
227 if p.ParticipationStatus != nil {
228 return fmt.Errorf(errDecodingProp, cAttendee, cParticipationStatus, ErrDuplicateParam)
229 }
230 p.ParticipationStatus = new(ParamParticipationStatus)
231 if err := p.ParticipationStatus.decode(pValues); err != nil {
232 return fmt.Errorf(errDecodingProp, cAttendee, cParticipationStatus, err)
233 }
234 case "RSVP":
235 if p.RSVP != nil {
236 return fmt.Errorf(errDecodingProp, cAttendee, cRSVP, ErrDuplicateParam)
237 }
238 p.RSVP = new(ParamRSVP)
239 if err := p.RSVP.decode(pValues); err != nil {
240 return fmt.Errorf(errDecodingProp, cAttendee, cRSVP, err)
241 }
242 case "DELEGATED-TO":
243 if p.Delagatee != nil {
244 return fmt.Errorf(errDecodingProp, cAttendee, cDelagatee, ErrDuplicateParam)
245 }
246 if err := p.Delagatee.decode(pValues); err != nil {
247 return fmt.Errorf(errDecodingProp, cAttendee, cDelagatee, err)
248 }
249 case "DELEGATED-FROM":
250 if p.Delegator != nil {
251 return fmt.Errorf(errDecodingProp, cAttendee, cDelegator, ErrDuplicateParam)
252 }
253 if err := p.Delegator.decode(pValues); err != nil {
254 return fmt.Errorf(errDecodingProp, cAttendee, cDelegator, err)
255 }
256 case "SENT-BY":
257 if p.SentBy != nil {
258 return fmt.Errorf(errDecodingProp, cAttendee, cSentBy, ErrDuplicateParam)
259 }
260 p.SentBy = new(ParamSentBy)
261 if err := p.SentBy.decode(pValues); err != nil {
262 return fmt.Errorf(errDecodingProp, cAttendee, cSentBy, err)
263 }
264 case "CN":
265 if p.CommonName != nil {
266 return fmt.Errorf(errDecodingProp, cAttendee, cCommonName, ErrDuplicateParam)
267 }
268 p.CommonName = new(ParamCommonName)
269 if err := p.CommonName.decode(pValues); err != nil {
270 return fmt.Errorf(errDecodingProp, cAttendee, cCommonName, err)
271 }
272 case "DIR":
273 if p.DirectoryEntry != nil {
274 return fmt.Errorf(errDecodingProp, cAttendee, cDirectoryEntry, ErrDuplicateParam)
275 }
276 p.DirectoryEntry = new(ParamDirectoryEntry)
277 if err := p.DirectoryEntry.decode(pValues); err != nil {
278 return fmt.Errorf(errDecodingProp, cAttendee, cDirectoryEntry, err)
279 }
280 case "LANGUAGE":
281 if p.Language != nil {
282 return fmt.Errorf(errDecodingProp, cAttendee, cLanguage, ErrDuplicateParam)
283 }
284 p.Language = new(ParamLanguage)
285 if err := p.Language.decode(pValues); err != nil {
286 return fmt.Errorf(errDecodingProp, cAttendee, cLanguage, err)
287 }
288 default:
289 for _, v := range pValues {
290 ts = append(ts, v.Data)
291 }
292 oParams[pName] = strings.Join(ts, ",")
293 ts = ts[:0]
294 }
295 }
296 if err := p.CalendarAddress.decode(oParams, value); err != nil {
297 return fmt.Errorf(errDecodingProp, cAttendee, cCalendarAddress, err)
298 }
299 return nil
300 }
301
302 func (p *PropAttendee) encode(w writer) {
303 w.WriteString("ATTENDEE")
304 if p.CalendarUserType != nil {
305 p.CalendarUserType.encode(w)
306 }
307 if p.Member != nil {
308 p.Member.encode(w)
309 }
310 if p.ParticipationRole != nil {
311 p.ParticipationRole.encode(w)
312 }
313 if p.ParticipationStatus != nil {
314 p.ParticipationStatus.encode(w)
315 }
316 if p.RSVP != nil {
317 p.RSVP.encode(w)
318 }
319 if p.Delagatee != nil {
320 p.Delagatee.encode(w)
321 }
322 if p.Delegator != nil {
323 p.Delegator.encode(w)
324 }
325 if p.SentBy != nil {
326 p.SentBy.encode(w)
327 }
328 if p.CommonName != nil {
329 p.CommonName.encode(w)
330 }
331 if p.DirectoryEntry != nil {
332 p.DirectoryEntry.encode(w)
333 }
334 if p.Language != nil {
335 p.Language.encode(w)
336 }
337 p.CalendarAddress.aencode(w)
338 w.WriteString("\r\n")
339 }
340
341 func (p *PropAttendee) valid() error {
342 if p.CalendarUserType != nil {
343 if err := p.CalendarUserType.valid(); err != nil {
344 return fmt.Errorf(errValidatingProp, cAttendee, cCalendarUserType, err)
345 }
346 }
347 if p.Member != nil {
348 if err := p.Member.valid(); err != nil {
349 return fmt.Errorf(errValidatingProp, cAttendee, cMember, err)
350 }
351 }
352 if p.ParticipationRole != nil {
353 if err := p.ParticipationRole.valid(); err != nil {
354 return fmt.Errorf(errValidatingProp, cAttendee, cParticipationRole, err)
355 }
356 }
357 if p.ParticipationStatus != nil {
358 if err := p.ParticipationStatus.valid(); err != nil {
359 return fmt.Errorf(errValidatingProp, cAttendee, cParticipationStatus, err)
360 }
361 }
362 if p.RSVP != nil {
363 if err := p.RSVP.valid(); err != nil {
364 return fmt.Errorf(errValidatingProp, cAttendee, cRSVP, err)
365 }
366 }
367 if p.Delagatee != nil {
368 if err := p.Delagatee.valid(); err != nil {
369 return fmt.Errorf(errValidatingProp, cAttendee, cDelagatee, err)
370 }
371 }
372 if p.Delegator != nil {
373 if err := p.Delegator.valid(); err != nil {
374 return fmt.Errorf(errValidatingProp, cAttendee, cDelegator, err)
375 }
376 }
377 if p.SentBy != nil {
378 if err := p.SentBy.valid(); err != nil {
379 return fmt.Errorf(errValidatingProp, cAttendee, cSentBy, err)
380 }
381 }
382 if p.CommonName != nil {
383 if err := p.CommonName.valid(); err != nil {
384 return fmt.Errorf(errValidatingProp, cAttendee, cCommonName, err)
385 }
386 }
387 if p.DirectoryEntry != nil {
388 if err := p.DirectoryEntry.valid(); err != nil {
389 return fmt.Errorf(errValidatingProp, cAttendee, cDirectoryEntry, err)
390 }
391 }
392 if p.Language != nil {
393 if err := p.Language.valid(); err != nil {
394 return fmt.Errorf(errValidatingProp, cAttendee, cLanguage, err)
395 }
396 }
397 if err := p.CalendarAddress.valid(); err != nil {
398 return fmt.Errorf(errValidatingProp, cAttendee, cCalendarAddress, err)
399 }
400 return nil
401 }
402
403 // PropCalendarScale defines the calendar scale
404 type PropCalendarScale uint8
405
406 // PropCalendarScale constant values
407 const (
408 CalendarScaleGregorian PropCalendarScale = iota
409 )
410
411 // New returns a pointer to the type (used with constants for ease of use with
412 // optional values)
413 func (p PropCalendarScale) New() *PropCalendarScale {
414 return &p
415 }
416
417 func (p *PropCalendarScale) decode(params []parser.Token, value string) error {
418 switch strings.ToUpper(value) {
419 case "GREGORIAN":
420 *p = CalendarScaleGregorian
421 default:
422 return fmt.Errorf(errDecodingType, cCalendarScale, ErrInvalidValue)
423 }
424 return nil
425 }
426
427 func (p *PropCalendarScale) encode(w writer) {
428 w.WriteString("CALSCALE:")
429 switch *p {
430 case CalendarScaleGregorian:
431 w.WriteString("GREGORIAN")
432 }
433 w.WriteString("\r\n")
434 }
435
436 func (p *PropCalendarScale) valid() error {
437 switch *p {
438 case CalendarScaleGregorian:
439 default:
440 return fmt.Errorf(errValidatingType, cCalendarScale, ErrInvalidValue)
441 }
442 return nil
443 }
444
445 // PropCategories defines the categories for a calendar component
446 type PropCategories struct {
447 Language *ParamLanguage
448 MText
449 }
450
451 func (p *PropCategories) decode(params []parser.Token, value string) error {
452 oParams := make(map[string]string)
453 var ts []string
454 for len(params) > 0 {
455 pName := strings.ToUpper(params[0].Data)
456 i := 1
457 for i < len(params) && params[i].Type != tokenParamName {
458 i++
459 }
460 pValues := params[1:i]
461 params = params[i:]
462 switch pName {
463 case "LANGUAGE":
464 if p.Language != nil {
465 return fmt.Errorf(errDecodingProp, cCategories, cLanguage, ErrDuplicateParam)
466 }
467 p.Language = new(ParamLanguage)
468 if err := p.Language.decode(pValues); err != nil {
469 return fmt.Errorf(errDecodingProp, cCategories, cLanguage, err)
470 }
471 default:
472 for _, v := range pValues {
473 ts = append(ts, v.Data)
474 }
475 oParams[pName] = strings.Join(ts, ",")
476 ts = ts[:0]
477 }
478 }
479 if err := p.MText.decode(oParams, value); err != nil {
480 return fmt.Errorf(errDecodingProp, cCategories, cMText, err)
481 }
482 return nil
483 }
484
485 func (p *PropCategories) encode(w writer) {
486 w.WriteString("CATEGORIES")
487 if p.Language != nil {
488 p.Language.encode(w)
489 }
490 p.MText.aencode(w)
491 w.WriteString("\r\n")
492 }
493
494 func (p *PropCategories) valid() error {
495 if p.Language != nil {
496 if err := p.Language.valid(); err != nil {
497 return fmt.Errorf(errValidatingProp, cCategories, cLanguage, err)
498 }
499 }
500 if err := p.MText.valid(); err != nil {
501 return fmt.Errorf(errValidatingProp, cCategories, cMText, err)
502 }
503 return nil
504 }
505
506 // PropClass defines the access classification for a calendar component
507 type PropClass uint8
508
509 // PropClass constant values
510 const (
511 ClassPublic PropClass = iota
512 ClassPrivate
513 ClassConfidential
514 )
515
516 // New returns a pointer to the type (used with constants for ease of use with
517 // optional values)
518 func (p PropClass) New() *PropClass {
519 return &p
520 }
521
522 func (p *PropClass) decode(params []parser.Token, value string) error {
523 switch strings.ToUpper(value) {
524 case "PUBLIC":
525 *p = ClassPublic
526 case "PRIVATE":
527 *p = ClassPrivate
528 case "CONFIDENTIAL":
529 *p = ClassConfidential
530 default:
531 return fmt.Errorf(errDecodingType, cClass, ErrInvalidValue)
532 }
533 return nil
534 }
535
536 func (p *PropClass) encode(w writer) {
537 w.WriteString("CLASS:")
538 switch *p {
539 case ClassPublic:
540 w.WriteString("PUBLIC")
541 case ClassPrivate:
542 w.WriteString("PRIVATE")
543 case ClassConfidential:
544 w.WriteString("CONFIDENTIAL")
545 }
546 w.WriteString("\r\n")
547 }
548
549 func (p *PropClass) valid() error {
550 switch *p {
551 case ClassPublic, ClassPrivate, ClassConfidential:
552 default:
553 return fmt.Errorf(errValidatingType, cClass, ErrInvalidValue)
554 }
555 return nil
556 }
557
558 // PropComment specifies non-processing information intended to provide a
559 // comment to the calendar user
560 type PropComment struct {
561 AlternativeRepresentation *ParamAlternativeRepresentation
562 Language *ParamLanguage
563 Text
564 }
565
566 func (p *PropComment) decode(params []parser.Token, value string) error {
567 oParams := make(map[string]string)
568 var ts []string
569 for len(params) > 0 {
570 pName := strings.ToUpper(params[0].Data)
571 i := 1
572 for i < len(params) && params[i].Type != tokenParamName {
573 i++
574 }
575 pValues := params[1:i]
576 params = params[i:]
577 switch pName {
578 case "ALTREP":
579 if p.AlternativeRepresentation != nil {
580 return fmt.Errorf(errDecodingProp, cComment, cAlternativeRepresentation, ErrDuplicateParam)
581 }
582 p.AlternativeRepresentation = new(ParamAlternativeRepresentation)
583 if err := p.AlternativeRepresentation.decode(pValues); err != nil {
584 return fmt.Errorf(errDecodingProp, cComment, cAlternativeRepresentation, err)
585 }
586 case "LANGUAGE":
587 if p.Language != nil {
588 return fmt.Errorf(errDecodingProp, cComment, cLanguage, ErrDuplicateParam)
589 }
590 p.Language = new(ParamLanguage)
591 if err := p.Language.decode(pValues); err != nil {
592 return fmt.Errorf(errDecodingProp, cComment, cLanguage, err)
593 }
594 default:
595 for _, v := range pValues {
596 ts = append(ts, v.Data)
597 }
598 oParams[pName] = strings.Join(ts, ",")
599 ts = ts[:0]
600 }
601 }
602 if err := p.Text.decode(oParams, value); err != nil {
603 return fmt.Errorf(errDecodingProp, cComment, cText, err)
604 }
605 return nil
606 }
607
608 func (p *PropComment) encode(w writer) {
609 w.WriteString("COMMENT")
610 if p.AlternativeRepresentation != nil {
611 p.AlternativeRepresentation.encode(w)
612 }
613 if p.Language != nil {
614 p.Language.encode(w)
615 }
616 p.Text.aencode(w)
617 w.WriteString("\r\n")
618 }
619
620 func (p *PropComment) valid() error {
621 if p.AlternativeRepresentation != nil {
622 if err := p.AlternativeRepresentation.valid(); err != nil {
623 return fmt.Errorf(errValidatingProp, cComment, cAlternativeRepresentation, err)
624 }
625 }
626 if p.Language != nil {
627 if err := p.Language.valid(); err != nil {
628 return fmt.Errorf(errValidatingProp, cComment, cLanguage, err)
629 }
630 }
631 if err := p.Text.valid(); err != nil {
632 return fmt.Errorf(errValidatingProp, cComment, cText, err)
633 }
634 return nil
635 }
636
637 // PropCompleted defines the date and time that a to-do was actually completed
638 type PropCompleted DateTime
639
640 func (p *PropCompleted) decode(params []parser.Token, value string) error {
641 oParams := make(map[string]string)
642 var ts []string
643 for len(params) > 0 {
644 i := 1
645 for i < len(params) && params[i].Type != tokenParamName {
646 i++
647 }
648 pValues := params[1:i]
649 for _, v := range pValues {
650 ts = append(ts, v.Data)
651 }
652 oParams[strings.ToUpper(params[0].Data)] = strings.Join(ts, ",")
653 params = params[i:]
654 ts = ts[:0]
655 }
656 var t DateTime
657 if err := t.decode(oParams, value); err != nil {
658 return fmt.Errorf(errDecodingType, cCompleted, err)
659 }
660 *p = PropCompleted(t)
661 return nil
662 }
663
664 func (p *PropCompleted) encode(w writer) {
665 w.WriteString("COMPLETED")
666 t := DateTime(*p)
667 t.aencode(w)
668 w.WriteString("\r\n")
669 }
670
671 func (p *PropCompleted) valid() error {
672 t := DateTime(*p)
673 if err := t.valid(); err != nil {
674 return fmt.Errorf(errValidatingType, cCompleted, err)
675 }
676 return nil
677 }
678
679 // PropContact is used to represent contact information or alternately a
680 // reference to contact information associated with the calendar component
681 type PropContact struct {
682 AlternativeRepresentation *ParamAlternativeRepresentation
683 Language *ParamLanguage
684 Text
685 }
686
687 func (p *PropContact) decode(params []parser.Token, value string) error {
688 oParams := make(map[string]string)
689 var ts []string
690 for len(params) > 0 {
691 pName := strings.ToUpper(params[0].Data)
692 i := 1
693 for i < len(params) && params[i].Type != tokenParamName {
694 i++
695 }
696 pValues := params[1:i]
697 params = params[i:]
698 switch pName {
699 case "ALTREP":
700 if p.AlternativeRepresentation != nil {
701 return fmt.Errorf(errDecodingProp, cContact, cAlternativeRepresentation, ErrDuplicateParam)
702 }
703 p.AlternativeRepresentation = new(ParamAlternativeRepresentation)
704 if err := p.AlternativeRepresentation.decode(pValues); err != nil {
705 return fmt.Errorf(errDecodingProp, cContact, cAlternativeRepresentation, err)
706 }
707 case "LANGUAGE":
708 if p.Language != nil {
709 return fmt.Errorf(errDecodingProp, cContact, cLanguage, ErrDuplicateParam)
710 }
711 p.Language = new(ParamLanguage)
712 if err := p.Language.decode(pValues); err != nil {
713 return fmt.Errorf(errDecodingProp, cContact, cLanguage, err)
714 }
715 default:
716 for _, v := range pValues {
717 ts = append(ts, v.Data)
718 }
719 oParams[pName] = strings.Join(ts, ",")
720 ts = ts[:0]
721 }
722 }
723 if err := p.Text.decode(oParams, value); err != nil {
724 return fmt.Errorf(errDecodingProp, cContact, cText, err)
725 }
726 return nil
727 }
728
729 func (p *PropContact) encode(w writer) {
730 w.WriteString("CONTACT")
731 if p.AlternativeRepresentation != nil {
732 p.AlternativeRepresentation.encode(w)
733 }
734 if p.Language != nil {
735 p.Language.encode(w)
736 }
737 p.Text.aencode(w)
738 w.WriteString("\r\n")
739 }
740
741 func (p *PropContact) valid() error {
742 if p.AlternativeRepresentation != nil {
743 if err := p.AlternativeRepresentation.valid(); err != nil {
744 return fmt.Errorf(errValidatingProp, cContact, cAlternativeRepresentation, err)
745 }
746 }
747 if p.Language != nil {
748 if err := p.Language.valid(); err != nil {
749 return fmt.Errorf(errValidatingProp, cContact, cLanguage, err)
750 }
751 }
752 if err := p.Text.valid(); err != nil {
753 return fmt.Errorf(errValidatingProp, cContact, cText, err)
754 }
755 return nil
756 }
757
758 // PropCreated specifies the date and time that the calendar information was
759 // created by the calendar user agent in the calendar store
760 type PropCreated DateTime
761
762 func (p *PropCreated) decode(params []parser.Token, value string) error {
763 oParams := make(map[string]string)
764 var ts []string
765 for len(params) > 0 {
766 i := 1
767 for i < len(params) && params[i].Type != tokenParamName {
768 i++
769 }
770 pValues := params[1:i]
771 for _, v := range pValues {
772 ts = append(ts, v.Data)
773 }
774 oParams[strings.ToUpper(params[0].Data)] = strings.Join(ts, ",")
775 params = params[i:]
776 ts = ts[:0]
777 }
778 var t DateTime
779 if err := t.decode(oParams, value); err != nil {
780 return fmt.Errorf(errDecodingType, cCreated, err)
781 }
782 *p = PropCreated(t)
783 return nil
784 }
785
786 func (p *PropCreated) encode(w writer) {
787 w.WriteString("CREATED")
788 t := DateTime(*p)
789 t.aencode(w)
790 w.WriteString("\r\n")
791 }
792
793 func (p *PropCreated) valid() error {
794 t := DateTime(*p)
795 if err := t.valid(); err != nil {
796 return fmt.Errorf(errValidatingType, cCreated, err)
797 }
798 return nil
799 }
800
801 // PropDescription provides a more complete description of the calendar
802 // component than that provided by the "SUMMARY" property
803 type PropDescription struct {
804 AlternativeRepresentation *ParamAlternativeRepresentation
805 Language *ParamLanguage
806 Text
807 }
808
809 func (p *PropDescription) decode(params []parser.Token, value string) error {
810 oParams := make(map[string]string)
811 var ts []string
812 for len(params) > 0 {
813 pName := strings.ToUpper(params[0].Data)
814 i := 1
815 for i < len(params) && params[i].Type != tokenParamName {
816 i++
817 }
818 pValues := params[1:i]
819 params = params[i:]
820 switch pName {
821 case "ALTREP":
822 if p.AlternativeRepresentation != nil {
823 return fmt.Errorf(errDecodingProp, cDescription, cAlternativeRepresentation, ErrDuplicateParam)
824 }
825 p.AlternativeRepresentation = new(ParamAlternativeRepresentation)
826 if err := p.AlternativeRepresentation.decode(pValues); err != nil {
827 return fmt.Errorf(errDecodingProp, cDescription, cAlternativeRepresentation, err)
828 }
829 case "LANGUAGE":
830 if p.Language != nil {
831 return fmt.Errorf(errDecodingProp, cDescription, cLanguage, ErrDuplicateParam)
832 }
833 p.Language = new(ParamLanguage)
834 if err := p.Language.decode(pValues); err != nil {
835 return fmt.Errorf(errDecodingProp, cDescription, cLanguage, err)
836 }
837 default:
838 for _, v := range pValues {
839 ts = append(ts, v.Data)
840 }
841 oParams[pName] = strings.Join(ts, ",")
842 ts = ts[:0]
843 }
844 }
845 if err := p.Text.decode(oParams, value); err != nil {
846 return fmt.Errorf(errDecodingProp, cDescription, cText, err)
847 }
848 return nil
849 }
850
851 func (p *PropDescription) encode(w writer) {
852 w.WriteString("DESCRIPTION")
853 if p.AlternativeRepresentation != nil {
854 p.AlternativeRepresentation.encode(w)
855 }
856 if p.Language != nil {
857 p.Language.encode(w)
858 }
859 p.Text.aencode(w)
860 w.WriteString("\r\n")
861 }
862
863 func (p *PropDescription) valid() error {
864 if p.AlternativeRepresentation != nil {
865 if err := p.AlternativeRepresentation.valid(); err != nil {
866 return fmt.Errorf(errValidatingProp, cDescription, cAlternativeRepresentation, err)
867 }
868 }
869 if p.Language != nil {
870 if err := p.Language.valid(); err != nil {
871 return fmt.Errorf(errValidatingProp, cDescription, cLanguage, err)
872 }
873 }
874 if err := p.Text.valid(); err != nil {
875 return fmt.Errorf(errValidatingProp, cDescription, cText, err)
876 }
877 return nil
878 }
879
880 // PropDateTimeEnd specifies the date and time that a calendar component ends
881 type PropDateTimeEnd struct {
882 DateTime *DateTime
883 Date *Date
884 }
885
886 func (p *PropDateTimeEnd) decode(params []parser.Token, value string) error {
887 vType := -1
888 oParams := make(map[string]string)
889 var ts []string
890 for len(params) > 0 {
891 pName := strings.ToUpper(params[0].Data)
892 i := 1
893 for i < len(params) && params[i].Type != tokenParamName {
894 i++
895 }
896 pValues := params[1:i]
897 params = params[i:]
898 switch pName {
899 case "VALUE":
900 if len(pValues) != 1 {
901 return fmt.Errorf(errDecodingProp, cDateTimeEnd, cValue, ErrInvalidValue)
902 }
903 if vType != -1 {
904 return fmt.Errorf(errDecodingProp, cDateTimeEnd, cValue, ErrDuplicateParam)
905 }
906 switch strings.ToUpper(pValues[0].Data) {
907 case "DATE-TIME":
908 vType = 0
909 case "DATE":
910 vType = 1
911 default:
912 return fmt.Errorf(errDecodingType, cDateTimeEnd, ErrInvalidValue)
913 }
914 default:
915 for _, v := range pValues {
916 ts = append(ts, v.Data)
917 }
918 oParams[pName] = strings.Join(ts, ",")
919 ts = ts[:0]
920 }
921 }
922 if vType == -1 {
923 vType = 0
924 }
925 switch vType {
926 case 0:
927 p.DateTime = new(DateTime)
928 if err := p.DateTime.decode(oParams, value); err != nil {
929 return fmt.Errorf(errDecodingProp, cDateTimeEnd, cDateTime, err)
930 }
931 case 1:
932 p.Date = new(Date)
933 if err := p.Date.decode(oParams, value); err != nil {
934 return fmt.Errorf(errDecodingProp, cDateTimeEnd, cDate, err)
935 }
936 }
937 return nil
938 }
939
940 func (p *PropDateTimeEnd) encode(w writer) {
941 w.WriteString("DTEND")
942 if p.DateTime != nil {
943 p.DateTime.aencode(w)
944 }
945 if p.Date != nil {
946 w.WriteString(";VALUE=DATE")
947 p.Date.aencode(w)
948 }
949 w.WriteString("\r\n")
950 }
951
952 func (p *PropDateTimeEnd) valid() error {
953 c := 0
954 if p.DateTime != nil {
955 if err := p.DateTime.valid(); err != nil {
956 return fmt.Errorf(errValidatingProp, cDateTimeEnd, cDateTime, err)
957 }
958 c++
959 }
960 if p.Date != nil {
961 if err := p.Date.valid(); err != nil {
962 return fmt.Errorf(errValidatingProp, cDateTimeEnd, cDate, err)
963 }
964 c++
965 }
966 if c != 1 {
967 return fmt.Errorf(errValidatingType, cDateTimeEnd, ErrInvalidValue)
968 }
969 return nil
970 }
971
972 // PropDateTimeStamp specifies the date and time that the calendar object was
973 // created unless the calendar object has no METHOD property, in which case it
974 // specifies the date and time that the information with the calendar was last
975 // revised
976 type PropDateTimeStamp DateTime
977
978 func (p *PropDateTimeStamp) decode(params []parser.Token, value string) error {
979 oParams := make(map[string]string)
980 var ts []string
981 for len(params) > 0 {
982 i := 1
983 for i < len(params) && params[i].Type != tokenParamName {
984 i++
985 }
986 pValues := params[1:i]
987 for _, v := range pValues {
988 ts = append(ts, v.Data)
989 }
990 oParams[strings.ToUpper(params[0].Data)] = strings.Join(ts, ",")
991 params = params[i:]
992 ts = ts[:0]
993 }
994 var t DateTime
995 if err := t.decode(oParams, value); err != nil {
996 return fmt.Errorf(errDecodingType, cDateTimeStamp, err)
997 }
998 *p = PropDateTimeStamp(t)
999 return nil
1000 }
1001
1002 func (p *PropDateTimeStamp) encode(w writer) {
1003 w.WriteString("DTSTAMP")
1004 t := DateTime(*p)
1005 t.aencode(w)
1006 w.WriteString("\r\n")
1007 }
1008
1009 func (p *PropDateTimeStamp) valid() error {
1010 t := DateTime(*p)
1011 if err := t.valid(); err != nil {
1012 return fmt.Errorf(errValidatingType, cDateTimeStamp, err)
1013 }
1014 return nil
1015 }
1016
1017 // PropDateTimeStart specifies when the calendar component begins
1018 type PropDateTimeStart struct {
1019 DateTime *DateTime
1020 Date *Date
1021 }
1022
1023 func (p *PropDateTimeStart) decode(params []parser.Token, value string) error {
1024 vType := -1
1025 oParams := make(map[string]string)
1026 var ts []string
1027 for len(params) > 0 {
1028 pName := strings.ToUpper(params[0].Data)
1029 i := 1
1030 for i < len(params) && params[i].Type != tokenParamName {
1031 i++
1032 }
1033 pValues := params[1:i]
1034 params = params[i:]
1035 switch pName {
1036 case "VALUE":
1037 if len(pValues) != 1 {
1038 return fmt.Errorf(errDecodingProp, cDateTimeStart, cValue, ErrInvalidValue)
1039 }
1040 if vType != -1 {
1041 return fmt.Errorf(errDecodingProp, cDateTimeStart, cValue, ErrDuplicateParam)
1042 }
1043 switch strings.ToUpper(pValues[0].Data) {
1044 case "DATE-TIME":
1045 vType = 0
1046 case "DATE":
1047 vType = 1
1048 default:
1049 return fmt.Errorf(errDecodingType, cDateTimeStart, ErrInvalidValue)
1050 }
1051 default:
1052 for _, v := range pValues {
1053 ts = append(ts, v.Data)
1054 }
1055 oParams[pName] = strings.Join(ts, ",")
1056 ts = ts[:0]
1057 }
1058 }
1059 if vType == -1 {
1060 vType = 0
1061 }
1062 switch vType {
1063 case 0:
1064 p.DateTime = new(DateTime)
1065 if err := p.DateTime.decode(oParams, value); err != nil {
1066 return fmt.Errorf(errDecodingProp, cDateTimeStart, cDateTime, err)
1067 }
1068 case 1:
1069 p.Date = new(Date)
1070 if err := p.Date.decode(oParams, value); err != nil {
1071 return fmt.Errorf(errDecodingProp, cDateTimeStart, cDate, err)
1072 }
1073 }
1074 return nil
1075 }
1076
1077 func (p *PropDateTimeStart) encode(w writer) {
1078 w.WriteString("DTSTART")
1079 if p.DateTime != nil {
1080 p.DateTime.aencode(w)
1081 }
1082 if p.Date != nil {
1083 w.WriteString(";VALUE=DATE")
1084 p.Date.aencode(w)
1085 }
1086 w.WriteString("\r\n")
1087 }
1088
1089 func (p *PropDateTimeStart) valid() error {
1090 c := 0
1091 if p.DateTime != nil {
1092 if err := p.DateTime.valid(); err != nil {
1093 return fmt.Errorf(errValidatingProp, cDateTimeStart, cDateTime, err)
1094 }
1095 c++
1096 }
1097 if p.Date != nil {
1098 if err := p.Date.valid(); err != nil {
1099 return fmt.Errorf(errValidatingProp, cDateTimeStart, cDate, err)
1100 }
1101 c++
1102 }
1103 if c != 1 {
1104 return fmt.Errorf(errValidatingType, cDateTimeStart, ErrInvalidValue)
1105 }
1106 return nil
1107 }
1108
1109 // PropDue defines the date and time that a to-do is expected to be completed
1110 type PropDue struct {
1111 DateTime *DateTime
1112 Date *Date
1113 }
1114
1115 func (p *PropDue) decode(params []parser.Token, value string) error {
1116 vType := -1
1117 oParams := make(map[string]string)
1118 var ts []string
1119 for len(params) > 0 {
1120 pName := strings.ToUpper(params[0].Data)
1121 i := 1
1122 for i < len(params) && params[i].Type != tokenParamName {
1123 i++
1124 }
1125 pValues := params[1:i]
1126 params = params[i:]
1127 switch pName {
1128 case "VALUE":
1129 if len(pValues) != 1 {
1130 return fmt.Errorf(errDecodingProp, cDue, cValue, ErrInvalidValue)
1131 }
1132 if vType != -1 {
1133 return fmt.Errorf(errDecodingProp, cDue, cValue, ErrDuplicateParam)
1134 }
1135 switch strings.ToUpper(pValues[0].Data) {
1136 case "DATE-TIME":
1137 vType = 0
1138 case "DATE":
1139 vType = 1
1140 default:
1141 return fmt.Errorf(errDecodingType, cDue, ErrInvalidValue)
1142 }
1143 default:
1144 for _, v := range pValues {
1145 ts = append(ts, v.Data)
1146 }
1147 oParams[pName] = strings.Join(ts, ",")
1148 ts = ts[:0]
1149 }
1150 }
1151 if vType == -1 {
1152 vType = 0
1153 }
1154 switch vType {
1155 case 0:
1156 p.DateTime = new(DateTime)
1157 if err := p.DateTime.decode(oParams, value); err != nil {
1158 return fmt.Errorf(errDecodingProp, cDue, cDateTime, err)
1159 }
1160 case 1:
1161 p.Date = new(Date)
1162 if err := p.Date.decode(oParams, value); err != nil {
1163 return fmt.Errorf(errDecodingProp, cDue, cDate, err)
1164 }
1165 }
1166 return nil
1167 }
1168
1169 func (p *PropDue) encode(w writer) {
1170 w.WriteString("DUE")
1171 if p.DateTime != nil {
1172 p.DateTime.aencode(w)
1173 }
1174 if p.Date != nil {
1175 w.WriteString(";VALUE=DATE")
1176 p.Date.aencode(w)
1177 }
1178 w.WriteString("\r\n")
1179 }
1180
1181 func (p *PropDue) valid() error {
1182 c := 0
1183 if p.DateTime != nil {
1184 if err := p.DateTime.valid(); err != nil {
1185 return fmt.Errorf(errValidatingProp, cDue, cDateTime, err)
1186 }
1187 c++
1188 }
1189 if p.Date != nil {
1190 if err := p.Date.valid(); err != nil {
1191 return fmt.Errorf(errValidatingProp, cDue, cDate, err)
1192 }
1193 c++
1194 }
1195 if c != 1 {
1196 return fmt.Errorf(errValidatingType, cDue, ErrInvalidValue)
1197 }
1198 return nil
1199 }
1200
1201 // PropDuration specifies a positive duration of time
1202 type PropDuration Duration
1203
1204 func (p *PropDuration) decode(params []parser.Token, value string) error {
1205 oParams := make(map[string]string)
1206 var ts []string
1207 for len(params) > 0 {
1208 i := 1
1209 for i < len(params) && params[i].Type != tokenParamName {
1210 i++
1211 }
1212 pValues := params[1:i]
1213 for _, v := range pValues {
1214 ts = append(ts, v.Data)
1215 }
1216 oParams[strings.ToUpper(params[0].Data)] = strings.Join(ts, ",")
1217 params = params[i:]
1218 ts = ts[:0]
1219 }
1220 var t Duration
1221 if err := t.decode(oParams, value); err != nil {
1222 return fmt.Errorf(errDecodingType, cDuration, err)
1223 }
1224 *p = PropDuration(t)
1225 return nil
1226 }
1227
1228 func (p *PropDuration) encode(w writer) {
1229 w.WriteString("DURATION")
1230 t := Duration(*p)
1231 t.aencode(w)
1232 w.WriteString("\r\n")
1233 }
1234
1235 func (p *PropDuration) valid() error {
1236 t := Duration(*p)
1237 if err := t.valid(); err != nil {
1238 return fmt.Errorf(errValidatingType, cDuration, err)
1239 }
1240 return nil
1241 }
1242
1243 // PropExceptionDateTime defines the list of DATE-TIME exceptions for recurring
1244 // events, to-dos, journal entries, or time zone definitions
1245 type PropExceptionDateTime struct {
1246 DateTime *DateTime
1247 Date *Date
1248 }
1249
1250 func (p *PropExceptionDateTime) decode(params []parser.Token, value string) error {
1251 vType := -1
1252 oParams := make(map[string]string)
1253 var ts []string
1254 for len(params) > 0 {
1255 pName := strings.ToUpper(params[0].Data)
1256 i := 1
1257 for i < len(params) && params[i].Type != tokenParamName {
1258 i++
1259 }
1260 pValues := params[1:i]
1261 params = params[i:]
1262 switch pName {
1263 case "VALUE":
1264 if len(pValues) != 1 {
1265 return fmt.Errorf(errDecodingProp, cExceptionDateTime, cValue, ErrInvalidValue)
1266 }
1267 if vType != -1 {
1268 return fmt.Errorf(errDecodingProp, cExceptionDateTime, cValue, ErrDuplicateParam)
1269 }
1270 switch strings.ToUpper(pValues[0].Data) {
1271 case "DATE-TIME":
1272 vType = 0
1273 case "DATE":
1274 vType = 1
1275 default:
1276 return fmt.Errorf(errDecodingType, cExceptionDateTime, ErrInvalidValue)
1277 }
1278 default:
1279 for _, v := range pValues {
1280 ts = append(ts, v.Data)
1281 }
1282 oParams[pName] = strings.Join(ts, ",")
1283 ts = ts[:0]
1284 }
1285 }
1286 if vType == -1 {
1287 vType = 0
1288 }
1289 switch vType {
1290 case 0:
1291 p.DateTime = new(DateTime)
1292 if err := p.DateTime.decode(oParams, value); err != nil {
1293 return fmt.Errorf(errDecodingProp, cExceptionDateTime, cDateTime, err)
1294 }
1295 case 1:
1296 p.Date = new(Date)
1297 if err := p.Date.decode(oParams, value); err != nil {
1298 return fmt.Errorf(errDecodingProp, cExceptionDateTime, cDate, err)
1299 }
1300 }
1301 return nil
1302 }
1303
1304 func (p *PropExceptionDateTime) encode(w writer) {
1305 w.WriteString("EXDATE")
1306 if p.DateTime != nil {
1307 p.DateTime.aencode(w)
1308 }
1309 if p.Date != nil {
1310 w.WriteString(";VALUE=DATE")
1311 p.Date.aencode(w)
1312 }
1313 w.WriteString("\r\n")
1314 }
1315
1316 func (p *PropExceptionDateTime) valid() error {
1317 c := 0
1318 if p.DateTime != nil {
1319 if err := p.DateTime.valid(); err != nil {
1320 return fmt.Errorf(errValidatingProp, cExceptionDateTime, cDateTime, err)
1321 }
1322 c++
1323 }
1324 if p.Date != nil {
1325 if err := p.Date.valid(); err != nil {
1326 return fmt.Errorf(errValidatingProp, cExceptionDateTime, cDate, err)
1327 }
1328 c++
1329 }
1330 if c != 1 {
1331 return fmt.Errorf(errValidatingType, cExceptionDateTime, ErrInvalidValue)
1332 }
1333 return nil
1334 }
1335
1336 // PropFreeBusy defines one or more free or busy time intervals
1337 type PropFreeBusy struct {
1338 FreeBusyType *ParamFreeBusyType
1339 Period
1340 }
1341
1342 func (p *PropFreeBusy) decode(params []parser.Token, value string) error {
1343 oParams := make(map[string]string)
1344 var ts []string
1345 for len(params) > 0 {
1346 pName := strings.ToUpper(params[0].Data)
1347 i := 1
1348 for i < len(params) && params[i].Type != tokenParamName {
1349 i++
1350 }
1351 pValues := params[1:i]
1352 params = params[i:]
1353 switch pName {
1354 case "FBTYPE":
1355 if p.FreeBusyType != nil {
1356 return fmt.Errorf(errDecodingProp, cFreeBusy, cFreeBusyType, ErrDuplicateParam)
1357 }
1358 p.FreeBusyType = new(ParamFreeBusyType)
1359 if err := p.FreeBusyType.decode(pValues); err != nil {
1360 return fmt.Errorf(errDecodingProp, cFreeBusy, cFreeBusyType, err)
1361 }
1362 default:
1363 for _, v := range pValues {
1364 ts = append(ts, v.Data)
1365 }
1366 oParams[pName] = strings.Join(ts, ",")
1367 ts = ts[:0]
1368 }
1369 }
1370 if err := p.Period.decode(oParams, value); err != nil {
1371 return fmt.Errorf(errDecodingProp, cFreeBusy, cPeriod, err)
1372 }
1373 return nil
1374 }
1375
1376 func (p *PropFreeBusy) encode(w writer) {
1377 w.WriteString("FREEBUSY")
1378 if p.FreeBusyType != nil {
1379 p.FreeBusyType.encode(w)
1380 }
1381 p.Period.aencode(w)
1382 w.WriteString("\r\n")
1383 }
1384
1385 func (p *PropFreeBusy) valid() error {
1386 if p.FreeBusyType != nil {
1387 if err := p.FreeBusyType.valid(); err != nil {
1388 return fmt.Errorf(errValidatingProp, cFreeBusy, cFreeBusyType, err)
1389 }
1390 }
1391 if err := p.Period.valid(); err != nil {
1392 return fmt.Errorf(errValidatingProp, cFreeBusy, cPeriod, err)
1393 }
1394 return nil
1395 }
1396
1397 // PropGeo specifies information related to the global position for the activity
1398 // specified by a calendar component
1399 type PropGeo TFloat
1400
1401 func (p *PropGeo) decode(params []parser.Token, value string) error {
1402 oParams := make(map[string]string)
1403 var ts []string
1404 for len(params) > 0 {
1405 i := 1
1406 for i < len(params) && params[i].Type != tokenParamName {
1407 i++
1408 }
1409 pValues := params[1:i]
1410 for _, v := range pValues {
1411 ts = append(ts, v.Data)
1412 }
1413 oParams[strings.ToUpper(params[0].Data)] = strings.Join(ts, ",")
1414 params = params[i:]
1415 ts = ts[:0]
1416 }
1417 var t TFloat
1418 if err := t.decode(oParams, value); err != nil {
1419 return fmt.Errorf(errDecodingType, cGeo, err)
1420 }
1421 *p = PropGeo(t)
1422 return nil
1423 }
1424
1425 func (p *PropGeo) encode(w writer) {
1426 w.WriteString("GEO")
1427 t := TFloat(*p)
1428 t.aencode(w)
1429 w.WriteString("\r\n")
1430 }
1431
1432 func (p *PropGeo) valid() error {
1433 t := TFloat(*p)
1434 if err := t.valid(); err != nil {
1435 return fmt.Errorf(errValidatingType, cGeo, err)
1436 }
1437 return nil
1438 }
1439
1440 // PropLastModified specifies the date and time that the information associated
1441 // with the calendar component was last revised in the calendar store
1442 type PropLastModified DateTime
1443
1444 func (p *PropLastModified) decode(params []parser.Token, value string) error {
1445 oParams := make(map[string]string)
1446 var ts []string
1447 for len(params) > 0 {
1448 i := 1
1449 for i < len(params) && params[i].Type != tokenParamName {
1450 i++
1451 }
1452 pValues := params[1:i]
1453 for _, v := range pValues {
1454 ts = append(ts, v.Data)
1455 }
1456 oParams[strings.ToUpper(params[0].Data)] = strings.Join(ts, ",")
1457 params = params[i:]
1458 ts = ts[:0]
1459 }
1460 var t DateTime
1461 if err := t.decode(oParams, value); err != nil {
1462 return fmt.Errorf(errDecodingType, cLastModified, err)
1463 }
1464 *p = PropLastModified(t)
1465 return nil
1466 }
1467
1468 func (p *PropLastModified) encode(w writer) {
1469 w.WriteString("LAST-MODIFIED")
1470 t := DateTime(*p)
1471 t.aencode(w)
1472 w.WriteString("\r\n")
1473 }
1474
1475 func (p *PropLastModified) valid() error {
1476 t := DateTime(*p)
1477 if err := t.valid(); err != nil {
1478 return fmt.Errorf(errValidatingType, cLastModified, err)
1479 }
1480 return nil
1481 }
1482
1483 // PropLocation defines the intended venue for the activity defined by a
1484 // calendar component
1485 type PropLocation struct {
1486 AlternativeRepresentation *ParamAlternativeRepresentation
1487 Language *ParamLanguage
1488 Text
1489 }
1490
1491 func (p *PropLocation) decode(params []parser.Token, value string) error {
1492 oParams := make(map[string]string)
1493 var ts []string
1494 for len(params) > 0 {
1495 pName := strings.ToUpper(params[0].Data)
1496 i := 1
1497 for i < len(params) && params[i].Type != tokenParamName {
1498 i++
1499 }
1500 pValues := params[1:i]
1501 params = params[i:]
1502 switch pName {
1503 case "ALTREP":
1504 if p.AlternativeRepresentation != nil {
1505 return fmt.Errorf(errDecodingProp, cLocation, cAlternativeRepresentation, ErrDuplicateParam)
1506 }
1507 p.AlternativeRepresentation = new(ParamAlternativeRepresentation)
1508 if err := p.AlternativeRepresentation.decode(pValues); err != nil {
1509 return fmt.Errorf(errDecodingProp, cLocation, cAlternativeRepresentation, err)
1510 }
1511 case "LANGUAGE":
1512 if p.Language != nil {
1513 return fmt.Errorf(errDecodingProp, cLocation, cLanguage, ErrDuplicateParam)
1514 }
1515 p.Language = new(ParamLanguage)
1516 if err := p.Language.decode(pValues); err != nil {
1517 return fmt.Errorf(errDecodingProp, cLocation, cLanguage, err)
1518 }
1519 default:
1520 for _, v := range pValues {
1521 ts = append(ts, v.Data)
1522 }
1523 oParams[pName] = strings.Join(ts, ",")
1524 ts = ts[:0]
1525 }
1526 }
1527 if err := p.Text.decode(oParams, value); err != nil {
1528 return fmt.Errorf(errDecodingProp, cLocation, cText, err)
1529 }
1530 return nil
1531 }
1532
1533 func (p *PropLocation) encode(w writer) {
1534 w.WriteString("LOCATION")
1535 if p.AlternativeRepresentation != nil {
1536 p.AlternativeRepresentation.encode(w)
1537 }
1538 if p.Language != nil {
1539 p.Language.encode(w)
1540 }
1541 p.Text.aencode(w)
1542 w.WriteString("\r\n")
1543 }
1544
1545 func (p *PropLocation) valid() error {
1546 if p.AlternativeRepresentation != nil {
1547 if err := p.AlternativeRepresentation.valid(); err != nil {
1548 return fmt.Errorf(errValidatingProp, cLocation, cAlternativeRepresentation, err)
1549 }
1550 }
1551 if p.Language != nil {
1552 if err := p.Language.valid(); err != nil {
1553 return fmt.Errorf(errValidatingProp, cLocation, cLanguage, err)
1554 }
1555 }
1556 if err := p.Text.valid(); err != nil {
1557 return fmt.Errorf(errValidatingProp, cLocation, cText, err)
1558 }
1559 return nil
1560 }
1561
1562 // PropMethod defines the iCalendar object method associated with the calendar
1563 // object
1564 type PropMethod Text
1565
1566 func (p *PropMethod) decode(params []parser.Token, value string) error {
1567 oParams := make(map[string]string)
1568 var ts []string
1569 for len(params) > 0 {
1570 i := 1
1571 for i < len(params) && params[i].Type != tokenParamName {
1572 i++
1573 }
1574 pValues := params[1:i]
1575 for _, v := range pValues {
1576 ts = append(ts, v.Data)
1577 }
1578 oParams[strings.ToUpper(params[0].Data)] = strings.Join(ts, ",")
1579 params = params[i:]
1580 ts = ts[:0]
1581 }
1582 var t Text
1583 if err := t.decode(oParams, value); err != nil {
1584 return fmt.Errorf(errDecodingType, cMethod, err)
1585 }
1586 *p = PropMethod(t)
1587 return nil
1588 }
1589
1590 func (p *PropMethod) encode(w writer) {
1591 w.WriteString("METHOD")
1592 t := Text(*p)
1593 t.aencode(w)
1594 w.WriteString("\r\n")
1595 }
1596
1597 func (p *PropMethod) valid() error {
1598 t := Text(*p)
1599 if err := t.valid(); err != nil {
1600 return fmt.Errorf(errValidatingType, cMethod, err)
1601 }
1602 return nil
1603 }
1604
1605 // PropOrganizer defines the organizer for a calendar component
1606 type PropOrganizer struct {
1607 CommonName *ParamCommonName
1608 DirectoryEntry *ParamDirectoryEntry
1609 SentBy *ParamSentBy
1610 Language *ParamLanguage
1611 CalendarAddress
1612 }
1613
1614 func (p *PropOrganizer) decode(params []parser.Token, value string) error {
1615 oParams := make(map[string]string)
1616 var ts []string
1617 for len(params) > 0 {
1618 pName := strings.ToUpper(params[0].Data)
1619 i := 1
1620 for i < len(params) && params[i].Type != tokenParamName {
1621 i++
1622 }
1623 pValues := params[1:i]
1624 params = params[i:]
1625 switch pName {
1626 case "CN":
1627 if p.CommonName != nil {
1628 return fmt.Errorf(errDecodingProp, cOrganizer, cCommonName, ErrDuplicateParam)
1629 }
1630 p.CommonName = new(ParamCommonName)
1631 if err := p.CommonName.decode(pValues); err != nil {
1632 return fmt.Errorf(errDecodingProp, cOrganizer, cCommonName, err)
1633 }
1634 case "DIR":
1635 if p.DirectoryEntry != nil {
1636 return fmt.Errorf(errDecodingProp, cOrganizer, cDirectoryEntry, ErrDuplicateParam)
1637 }
1638 p.DirectoryEntry = new(ParamDirectoryEntry)
1639 if err := p.DirectoryEntry.decode(pValues); err != nil {
1640 return fmt.Errorf(errDecodingProp, cOrganizer, cDirectoryEntry, err)
1641 }
1642 case "SENT-BY":
1643 if p.SentBy != nil {
1644 return fmt.Errorf(errDecodingProp, cOrganizer, cSentBy, ErrDuplicateParam)
1645 }
1646 p.SentBy = new(ParamSentBy)
1647 if err := p.SentBy.decode(pValues); err != nil {
1648 return fmt.Errorf(errDecodingProp, cOrganizer, cSentBy, err)
1649 }
1650 case "LANGUAGE":
1651 if p.Language != nil {
1652 return fmt.Errorf(errDecodingProp, cOrganizer, cLanguage, ErrDuplicateParam)
1653 }
1654 p.Language = new(ParamLanguage)
1655 if err := p.Language.decode(pValues); err != nil {
1656 return fmt.Errorf(errDecodingProp, cOrganizer, cLanguage, err)
1657 }
1658 default:
1659 for _, v := range pValues {
1660 ts = append(ts, v.Data)
1661 }
1662 oParams[pName] = strings.Join(ts, ",")
1663 ts = ts[:0]
1664 }
1665 }
1666 if err := p.CalendarAddress.decode(oParams, value); err != nil {
1667 return fmt.Errorf(errDecodingProp, cOrganizer, cCalendarAddress, err)
1668 }
1669 return nil
1670 }
1671
1672 func (p *PropOrganizer) encode(w writer) {
1673 w.WriteString("ORGANIZER")
1674 if p.CommonName != nil {
1675 p.CommonName.encode(w)
1676 }
1677 if p.DirectoryEntry != nil {
1678 p.DirectoryEntry.encode(w)
1679 }
1680 if p.SentBy != nil {
1681 p.SentBy.encode(w)
1682 }
1683 if p.Language != nil {
1684 p.Language.encode(w)
1685 }
1686 p.CalendarAddress.aencode(w)
1687 w.WriteString("\r\n")
1688 }
1689
1690 func (p *PropOrganizer) valid() error {
1691 if p.CommonName != nil {
1692 if err := p.CommonName.valid(); err != nil {
1693 return fmt.Errorf(errValidatingProp, cOrganizer, cCommonName, err)
1694 }
1695 }
1696 if p.DirectoryEntry != nil {
1697 if err := p.DirectoryEntry.valid(); err != nil {
1698 return fmt.Errorf(errValidatingProp, cOrganizer, cDirectoryEntry, err)
1699 }
1700 }
1701 if p.SentBy != nil {
1702 if err := p.SentBy.valid(); err != nil {
1703 return fmt.Errorf(errValidatingProp, cOrganizer, cSentBy, err)
1704 }
1705 }
1706 if p.Language != nil {
1707 if err := p.Language.valid(); err != nil {
1708 return fmt.Errorf(errValidatingProp, cOrganizer, cLanguage, err)
1709 }
1710 }
1711 if err := p.CalendarAddress.valid(); err != nil {
1712 return fmt.Errorf(errValidatingProp, cOrganizer, cCalendarAddress, err)
1713 }
1714 return nil
1715 }
1716
1717 // PropPercentComplete is used by an assignee or delegatee of a to-do to convey
1718 // the percent completion of a to-do to the "Organizer"
1719 type PropPercentComplete Integer
1720
1721 // NewPercentComplete generates a pointer to a constant value.
1722 // Used when manually creating Calendar values
1723 func NewPercentComplete(v PropPercentComplete) *PropPercentComplete {
1724 return &v
1725 }
1726
1727 func (p *PropPercentComplete) decode(params []parser.Token, value string) error {
1728 oParams := make(map[string]string)
1729 var ts []string
1730 for len(params) > 0 {
1731 i := 1
1732 for i < len(params) && params[i].Type != tokenParamName {
1733 i++
1734 }
1735 pValues := params[1:i]
1736 for _, v := range pValues {
1737 ts = append(ts, v.Data)
1738 }
1739 oParams[strings.ToUpper(params[0].Data)] = strings.Join(ts, ",")
1740 params = params[i:]
1741 ts = ts[:0]
1742 }
1743 var t Integer
1744 if err := t.decode(oParams, value); err != nil {
1745 return fmt.Errorf(errDecodingType, cPercentComplete, err)
1746 }
1747 *p = PropPercentComplete(t)
1748 return nil
1749 }
1750
1751 func (p *PropPercentComplete) encode(w writer) {
1752 w.WriteString("PERCENT-COMPLETE")
1753 t := Integer(*p)
1754 t.aencode(w)
1755 w.WriteString("\r\n")
1756 }
1757
1758 func (p *PropPercentComplete) valid() error {
1759 t := Integer(*p)
1760 if err := t.valid(); err != nil {
1761 return fmt.Errorf(errValidatingType, cPercentComplete, err)
1762 }
1763 return nil
1764 }
1765
1766 // PropPriority defines the relative priority for a calendar component
1767 type PropPriority Integer
1768
1769 // NewPriority generates a pointer to a constant value.
1770 // Used when manually creating Calendar values
1771 func NewPriority(v PropPriority) *PropPriority {
1772 return &v
1773 }
1774
1775 func (p *PropPriority) decode(params []parser.Token, value string) error {
1776 oParams := make(map[string]string)
1777 var ts []string
1778 for len(params) > 0 {
1779 i := 1
1780 for i < len(params) && params[i].Type != tokenParamName {
1781 i++
1782 }
1783 pValues := params[1:i]
1784 for _, v := range pValues {
1785 ts = append(ts, v.Data)
1786 }
1787 oParams[strings.ToUpper(params[0].Data)] = strings.Join(ts, ",")
1788 params = params[i:]
1789 ts = ts[:0]
1790 }
1791 var t Integer
1792 if err := t.decode(oParams, value); err != nil {
1793 return fmt.Errorf(errDecodingType, cPriority, err)
1794 }
1795 *p = PropPriority(t)
1796 return nil
1797 }
1798
1799 func (p *PropPriority) encode(w writer) {
1800 w.WriteString("PRIORITY")
1801 t := Integer(*p)
1802 t.aencode(w)
1803 w.WriteString("\r\n")
1804 }
1805
1806 func (p *PropPriority) valid() error {
1807 t := Integer(*p)
1808 if err := t.valid(); err != nil {
1809 return fmt.Errorf(errValidatingType, cPriority, err)
1810 }
1811 return nil
1812 }
1813
1814 // PropProductID specifies the identifier for the product that created the
1815 // iCalendar object
1816 type PropProductID Text
1817
1818 func (p *PropProductID) decode(params []parser.Token, value string) error {
1819 oParams := make(map[string]string)
1820 var ts []string
1821 for len(params) > 0 {
1822 i := 1
1823 for i < len(params) && params[i].Type != tokenParamName {
1824 i++
1825 }
1826 pValues := params[1:i]
1827 for _, v := range pValues {
1828 ts = append(ts, v.Data)
1829 }
1830 oParams[strings.ToUpper(params[0].Data)] = strings.Join(ts, ",")
1831 params = params[i:]
1832 ts = ts[:0]
1833 }
1834 var t Text
1835 if err := t.decode(oParams, value); err != nil {
1836 return fmt.Errorf(errDecodingType, cProductID, err)
1837 }
1838 *p = PropProductID(t)
1839 return nil
1840 }
1841
1842 func (p *PropProductID) encode(w writer) {
1843 w.WriteString("PRODID")
1844 t := Text(*p)
1845 t.aencode(w)
1846 w.WriteString("\r\n")
1847 }
1848
1849 func (p *PropProductID) valid() error {
1850 t := Text(*p)
1851 if err := t.valid(); err != nil {
1852 return fmt.Errorf(errValidatingType, cProductID, err)
1853 }
1854 return nil
1855 }
1856
1857 // PropRecurrenceDateTimes defines the list of DATE-TIME values for recurring
1858 // events, to-dos, journal entries, or time zone definitions
1859 type PropRecurrenceDateTimes struct {
1860 DateTime *DateTime
1861 Date *Date
1862 Period *Period
1863 }
1864
1865 func (p *PropRecurrenceDateTimes) decode(params []parser.Token, value string) error {
1866 vType := -1
1867 oParams := make(map[string]string)
1868 var ts []string
1869 for len(params) > 0 {
1870 pName := strings.ToUpper(params[0].Data)
1871 i := 1
1872 for i < len(params) && params[i].Type != tokenParamName {
1873 i++
1874 }
1875 pValues := params[1:i]
1876 params = params[i:]
1877 switch pName {
1878 case "VALUE":
1879 if len(pValues) != 1 {
1880 return fmt.Errorf(errDecodingProp, cRecurrenceDateTimes, cValue, ErrInvalidValue)
1881 }
1882 if vType != -1 {
1883 return fmt.Errorf(errDecodingProp, cRecurrenceDateTimes, cValue, ErrDuplicateParam)
1884 }
1885 switch strings.ToUpper(pValues[0].Data) {
1886 case "DATE-TIME":
1887 vType = 0
1888 case "DATE":
1889 vType = 1
1890 case "PERIOD":
1891 vType = 2
1892 default:
1893 return fmt.Errorf(errDecodingType, cRecurrenceDateTimes, ErrInvalidValue)
1894 }
1895 default:
1896 for _, v := range pValues {
1897 ts = append(ts, v.Data)
1898 }
1899 oParams[pName] = strings.Join(ts, ",")
1900 ts = ts[:0]
1901 }
1902 }
1903 if vType == -1 {
1904 vType = 0
1905 }
1906 switch vType {
1907 case 0:
1908 p.DateTime = new(DateTime)
1909 if err := p.DateTime.decode(oParams, value); err != nil {
1910 return fmt.Errorf(errDecodingProp, cRecurrenceDateTimes, cDateTime, err)
1911 }
1912 case 1:
1913 p.Date = new(Date)
1914 if err := p.Date.decode(oParams, value); err != nil {
1915 return fmt.Errorf(errDecodingProp, cRecurrenceDateTimes, cDate, err)
1916 }
1917 case 2:
1918 p.Period = new(Period)
1919 if err := p.Period.decode(oParams, value); err != nil {
1920 return fmt.Errorf(errDecodingProp, cRecurrenceDateTimes, cPeriod, err)
1921 }
1922 }
1923 return nil
1924 }
1925
1926 func (p *PropRecurrenceDateTimes) encode(w writer) {
1927 w.WriteString("RDATE")
1928 if p.DateTime != nil {
1929 p.DateTime.aencode(w)
1930 }
1931 if p.Date != nil {
1932 w.WriteString(";VALUE=DATE")
1933 p.Date.aencode(w)
1934 }
1935 if p.Period != nil {
1936 w.WriteString(";VALUE=PERIOD")
1937 p.Period.aencode(w)
1938 }
1939 w.WriteString("\r\n")
1940 }
1941
1942 func (p *PropRecurrenceDateTimes) valid() error {
1943 c := 0
1944 if p.DateTime != nil {
1945 if err := p.DateTime.valid(); err != nil {
1946 return fmt.Errorf(errValidatingProp, cRecurrenceDateTimes, cDateTime, err)
1947 }
1948 c++
1949 }
1950 if p.Date != nil {
1951 if err := p.Date.valid(); err != nil {
1952 return fmt.Errorf(errValidatingProp, cRecurrenceDateTimes, cDate, err)
1953 }
1954 c++
1955 }
1956 if p.Period != nil {
1957 if err := p.Period.valid(); err != nil {
1958 return fmt.Errorf(errValidatingProp, cRecurrenceDateTimes, cPeriod, err)
1959 }
1960 c++
1961 }
1962 if c != 1 {
1963 return fmt.Errorf(errValidatingType, cRecurrenceDateTimes, ErrInvalidValue)
1964 }
1965 return nil
1966 }
1967
1968 // PropRecurrenceID is used to identify a specific instance of a recurring
1969 // Event, Todo or Journal
1970 type PropRecurrenceID struct {
1971 Range *ParamRange
1972 DateTime *DateTime
1973 Date *Date
1974 }
1975
1976 func (p *PropRecurrenceID) decode(params []parser.Token, value string) error {
1977 vType := -1
1978 oParams := make(map[string]string)
1979 var ts []string
1980 for len(params) > 0 {
1981 pName := strings.ToUpper(params[0].Data)
1982 i := 1
1983 for i < len(params) && params[i].Type != tokenParamName {
1984 i++
1985 }
1986 pValues := params[1:i]
1987 params = params[i:]
1988 switch pName {
1989 case "RANGE":
1990 if p.Range != nil {
1991 return fmt.Errorf(errDecodingProp, cRecurrenceID, cRange, ErrDuplicateParam)
1992 }
1993 p.Range = new(ParamRange)
1994 if err := p.Range.decode(pValues); err != nil {
1995 return fmt.Errorf(errDecodingProp, cRecurrenceID, cRange, err)
1996 }
1997 case "VALUE":
1998 if len(pValues) != 1 {
1999 return fmt.Errorf(errDecodingProp, cRecurrenceID, cValue, ErrInvalidValue)
2000 }
2001 if vType != -1 {
2002 return fmt.Errorf(errDecodingProp, cRecurrenceID, cValue, ErrDuplicateParam)
2003 }
2004 switch strings.ToUpper(pValues[0].Data) {
2005 case "DATE-TIME":
2006 vType = 0
2007 case "DATE":
2008 vType = 1
2009 default:
2010 return fmt.Errorf(errDecodingType, cRecurrenceID, ErrInvalidValue)
2011 }
2012 default:
2013 for _, v := range pValues {
2014 ts = append(ts, v.Data)
2015 }
2016 oParams[pName] = strings.Join(ts, ",")
2017 ts = ts[:0]
2018 }
2019 }
2020 if vType == -1 {
2021 vType = 0
2022 }
2023 switch vType {
2024 case 0:
2025 p.DateTime = new(DateTime)
2026 if err := p.DateTime.decode(oParams, value); err != nil {
2027 return fmt.Errorf(errDecodingProp, cRecurrenceID, cDateTime, err)
2028 }
2029 case 1:
2030 p.Date = new(Date)
2031 if err := p.Date.decode(oParams, value); err != nil {
2032 return fmt.Errorf(errDecodingProp, cRecurrenceID, cDate, err)
2033 }
2034 }
2035 return nil
2036 }
2037
2038 func (p *PropRecurrenceID) encode(w writer) {
2039 w.WriteString("RECURRENCE-ID")
2040 if p.Range != nil {
2041 p.Range.encode(w)
2042 }
2043 if p.DateTime != nil {
2044 p.DateTime.aencode(w)
2045 }
2046 if p.Date != nil {
2047 w.WriteString(";VALUE=DATE")
2048 p.Date.aencode(w)
2049 }
2050 w.WriteString("\r\n")
2051 }
2052
2053 func (p *PropRecurrenceID) valid() error {
2054 if p.Range != nil {
2055 if err := p.Range.valid(); err != nil {
2056 return fmt.Errorf(errValidatingProp, cRecurrenceID, cRange, err)
2057 }
2058 }
2059 c := 0
2060 if p.DateTime != nil {
2061 if err := p.DateTime.valid(); err != nil {
2062 return fmt.Errorf(errValidatingProp, cRecurrenceID, cDateTime, err)
2063 }
2064 c++
2065 }
2066 if p.Date != nil {
2067 if err := p.Date.valid(); err != nil {
2068 return fmt.Errorf(errValidatingProp, cRecurrenceID, cDate, err)
2069 }
2070 c++
2071 }
2072 if c != 1 {
2073 return fmt.Errorf(errValidatingType, cRecurrenceID, ErrInvalidValue)
2074 }
2075 return nil
2076 }
2077
2078 // PropRelatedTo is used to represent a relationship or reference between one
2079 // calendar component and another
2080 type PropRelatedTo struct {
2081 RelationshipType *ParamRelationshipType
2082 Text
2083 }
2084
2085 func (p *PropRelatedTo) decode(params []parser.Token, value string) error {
2086 oParams := make(map[string]string)
2087 var ts []string
2088 for len(params) > 0 {
2089 pName := strings.ToUpper(params[0].Data)
2090 i := 1
2091 for i < len(params) && params[i].Type != tokenParamName {
2092 i++
2093 }
2094 pValues := params[1:i]
2095 params = params[i:]
2096 switch pName {
2097 case "RELTYPE":
2098 if p.RelationshipType != nil {
2099 return fmt.Errorf(errDecodingProp, cRelatedTo, cRelationshipType, ErrDuplicateParam)
2100 }
2101 p.RelationshipType = new(ParamRelationshipType)
2102 if err := p.RelationshipType.decode(pValues); err != nil {
2103 return fmt.Errorf(errDecodingProp, cRelatedTo, cRelationshipType, err)
2104 }
2105 default:
2106 for _, v := range pValues {
2107 ts = append(ts, v.Data)
2108 }
2109 oParams[pName] = strings.Join(ts, ",")
2110 ts = ts[:0]
2111 }
2112 }
2113 if err := p.Text.decode(oParams, value); err != nil {
2114 return fmt.Errorf(errDecodingProp, cRelatedTo, cText, err)
2115 }
2116 return nil
2117 }
2118
2119 func (p *PropRelatedTo) encode(w writer) {
2120 w.WriteString("RELATED-TO")
2121 if p.RelationshipType != nil {
2122 p.RelationshipType.encode(w)
2123 }
2124 p.Text.aencode(w)
2125 w.WriteString("\r\n")
2126 }
2127
2128 func (p *PropRelatedTo) valid() error {
2129 if p.RelationshipType != nil {
2130 if err := p.RelationshipType.valid(); err != nil {
2131 return fmt.Errorf(errValidatingProp, cRelatedTo, cRelationshipType, err)
2132 }
2133 }
2134 if err := p.Text.valid(); err != nil {
2135 return fmt.Errorf(errValidatingProp, cRelatedTo, cText, err)
2136 }
2137 return nil
2138 }
2139
2140 // PropRepeat defines the number of times the alarm should be repeated, after
2141 // the initial trigger
2142 type PropRepeat Integer
2143
2144 // NewRepeat generates a pointer to a constant value.
2145 // Used when manually creating Calendar values
2146 func NewRepeat(v PropRepeat) *PropRepeat {
2147 return &v
2148 }
2149
2150 func (p *PropRepeat) decode(params []parser.Token, value string) error {
2151 oParams := make(map[string]string)
2152 var ts []string
2153 for len(params) > 0 {
2154 i := 1
2155 for i < len(params) && params[i].Type != tokenParamName {
2156 i++
2157 }
2158 pValues := params[1:i]
2159 for _, v := range pValues {
2160 ts = append(ts, v.Data)
2161 }
2162 oParams[strings.ToUpper(params[0].Data)] = strings.Join(ts, ",")
2163 params = params[i:]
2164 ts = ts[:0]
2165 }
2166 var t Integer
2167 if err := t.decode(oParams, value); err != nil {
2168 return fmt.Errorf(errDecodingType, cRepeat, err)
2169 }
2170 *p = PropRepeat(t)
2171 return nil
2172 }
2173
2174 func (p *PropRepeat) encode(w writer) {
2175 w.WriteString("REPEAT")
2176 t := Integer(*p)
2177 t.aencode(w)
2178 w.WriteString("\r\n")
2179 }
2180
2181 func (p *PropRepeat) valid() error {
2182 t := Integer(*p)
2183 if err := t.valid(); err != nil {
2184 return fmt.Errorf(errValidatingType, cRepeat, err)
2185 }
2186 return nil
2187 }
2188
2189 // PropRequestStatus defines the status code returned for a scheduling request
2190 type PropRequestStatus Text
2191
2192 func (p *PropRequestStatus) decode(params []parser.Token, value string) error {
2193 oParams := make(map[string]string)
2194 var ts []string
2195 for len(params) > 0 {
2196 i := 1
2197 for i < len(params) && params[i].Type != tokenParamName {
2198 i++
2199 }
2200 pValues := params[1:i]
2201 for _, v := range pValues {
2202 ts = append(ts, v.Data)
2203 }
2204 oParams[strings.ToUpper(params[0].Data)] = strings.Join(ts, ",")
2205 params = params[i:]
2206 ts = ts[:0]
2207 }
2208 var t Text
2209 if err := t.decode(oParams, value); err != nil {
2210 return fmt.Errorf(errDecodingType, cRequestStatus, err)
2211 }
2212 *p = PropRequestStatus(t)
2213 return nil
2214 }
2215
2216 func (p *PropRequestStatus) encode(w writer) {
2217 w.WriteString("REQUEST-STATUS")
2218 t := Text(*p)
2219 t.aencode(w)
2220 w.WriteString("\r\n")
2221 }
2222
2223 func (p *PropRequestStatus) valid() error {
2224 t := Text(*p)
2225 if err := t.valid(); err != nil {
2226 return fmt.Errorf(errValidatingType, cRequestStatus, err)
2227 }
2228 return nil
2229 }
2230
2231 // PropResources defines the equipment or resources anticipated for an activity
2232 // specified by a calendar component
2233 type PropResources struct {
2234 AlternativeRepresentation *ParamAlternativeRepresentation
2235 Language *ParamLanguage
2236 MText
2237 }
2238
2239 func (p *PropResources) decode(params []parser.Token, value string) error {
2240 oParams := make(map[string]string)
2241 var ts []string
2242 for len(params) > 0 {
2243 pName := strings.ToUpper(params[0].Data)
2244 i := 1
2245 for i < len(params) && params[i].Type != tokenParamName {
2246 i++
2247 }
2248 pValues := params[1:i]
2249 params = params[i:]
2250 switch pName {
2251 case "ALTREP":
2252 if p.AlternativeRepresentation != nil {
2253 return fmt.Errorf(errDecodingProp, cResources, cAlternativeRepresentation, ErrDuplicateParam)
2254 }
2255 p.AlternativeRepresentation = new(ParamAlternativeRepresentation)
2256 if err := p.AlternativeRepresentation.decode(pValues); err != nil {
2257 return fmt.Errorf(errDecodingProp, cResources, cAlternativeRepresentation, err)
2258 }
2259 case "LANGUAGE":
2260 if p.Language != nil {
2261 return fmt.Errorf(errDecodingProp, cResources, cLanguage, ErrDuplicateParam)
2262 }
2263 p.Language = new(ParamLanguage)
2264 if err := p.Language.decode(pValues); err != nil {
2265 return fmt.Errorf(errDecodingProp, cResources, cLanguage, err)
2266 }
2267 default:
2268 for _, v := range pValues {
2269 ts = append(ts, v.Data)
2270 }
2271 oParams[pName] = strings.Join(ts, ",")
2272 ts = ts[:0]
2273 }
2274 }
2275 if err := p.MText.decode(oParams, value); err != nil {
2276 return fmt.Errorf(errDecodingProp, cResources, cMText, err)
2277 }
2278 return nil
2279 }
2280
2281 func (p *PropResources) encode(w writer) {
2282 w.WriteString("RESOURCES")
2283 if p.AlternativeRepresentation != nil {
2284 p.AlternativeRepresentation.encode(w)
2285 }
2286 if p.Language != nil {
2287 p.Language.encode(w)
2288 }
2289 p.MText.aencode(w)
2290 w.WriteString("\r\n")
2291 }
2292
2293 func (p *PropResources) valid() error {
2294 if p.AlternativeRepresentation != nil {
2295 if err := p.AlternativeRepresentation.valid(); err != nil {
2296 return fmt.Errorf(errValidatingProp, cResources, cAlternativeRepresentation, err)
2297 }
2298 }
2299 if p.Language != nil {
2300 if err := p.Language.valid(); err != nil {
2301 return fmt.Errorf(errValidatingProp, cResources, cLanguage, err)
2302 }
2303 }
2304 if err := p.MText.valid(); err != nil {
2305 return fmt.Errorf(errValidatingProp, cResources, cMText, err)
2306 }
2307 return nil
2308 }
2309
2310 // PropRecurrenceRule defines a rule or repeating pattern for recurring events,
2311 // to-dos, journal entries, or time zone definitions
2312 type PropRecurrenceRule Recur
2313
2314 func (p *PropRecurrenceRule) decode(params []parser.Token, value string) error {
2315 oParams := make(map[string]string)
2316 var ts []string
2317 for len(params) > 0 {
2318 i := 1
2319 for i < len(params) && params[i].Type != tokenParamName {
2320 i++
2321 }
2322 pValues := params[1:i]
2323 for _, v := range pValues {
2324 ts = append(ts, v.Data)
2325 }
2326 oParams[strings.ToUpper(params[0].Data)] = strings.Join(ts, ",")
2327 params = params[i:]
2328 ts = ts[:0]
2329 }
2330 var t Recur
2331 if err := t.decode(oParams, value); err != nil {
2332 return fmt.Errorf(errDecodingType, cRecurrenceRule, err)
2333 }
2334 *p = PropRecurrenceRule(t)
2335 return nil
2336 }
2337
2338 func (p *PropRecurrenceRule) encode(w writer) {
2339 w.WriteString("RRULE")
2340 t := Recur(*p)
2341 t.aencode(w)
2342 w.WriteString("\r\n")
2343 }
2344
2345 func (p *PropRecurrenceRule) valid() error {
2346 t := Recur(*p)
2347 if err := t.valid(); err != nil {
2348 return fmt.Errorf(errValidatingType, cRecurrenceRule, err)
2349 }
2350 return nil
2351 }
2352
2353 // PropSequence defines the revision sequence number of the calendar component
2354 // within a sequence of revisions
2355 type PropSequence Integer
2356
2357 // NewSequence generates a pointer to a constant value.
2358 // Used when manually creating Calendar values
2359 func NewSequence(v PropSequence) *PropSequence {
2360 return &v
2361 }
2362
2363 func (p *PropSequence) decode(params []parser.Token, value string) error {
2364 oParams := make(map[string]string)
2365 var ts []string
2366 for len(params) > 0 {
2367 i := 1
2368 for i < len(params) && params[i].Type != tokenParamName {
2369 i++
2370 }
2371 pValues := params[1:i]
2372 for _, v := range pValues {
2373 ts = append(ts, v.Data)
2374 }
2375 oParams[strings.ToUpper(params[0].Data)] = strings.Join(ts, ",")
2376 params = params[i:]
2377 ts = ts[:0]
2378 }
2379 var t Integer
2380 if err := t.decode(oParams, value); err != nil {
2381 return fmt.Errorf(errDecodingType, cSequence, err)
2382 }
2383 *p = PropSequence(t)
2384 return nil
2385 }
2386
2387 func (p *PropSequence) encode(w writer) {
2388 w.WriteString("SEQUENCE")
2389 t := Integer(*p)
2390 t.aencode(w)
2391 w.WriteString("\r\n")
2392 }
2393
2394 func (p *PropSequence) valid() error {
2395 t := Integer(*p)
2396 if err := t.valid(); err != nil {
2397 return fmt.Errorf(errValidatingType, cSequence, err)
2398 }
2399 return nil
2400 }
2401
2402 // PropStatus defines the overall status or confirmation for the calendar
2403 // component
2404 type PropStatus uint8
2405
2406 // PropStatus constant values
2407 const (
2408 StatusTentative PropStatus = iota
2409 StatusConfirmed
2410 StatusCancelled
2411 StatusNeedsAction
2412 StatusCompleted
2413 StatusInProcess
2414 StatusDraft
2415 StatusFinal
2416 )
2417
2418 // New returns a pointer to the type (used with constants for ease of use with
2419 // optional values)
2420 func (p PropStatus) New() *PropStatus {
2421 return &p
2422 }
2423
2424 func (p *PropStatus) decode(params []parser.Token, value string) error {
2425 switch strings.ToUpper(value) {
2426 case "TENTATIVE":
2427 *p = StatusTentative
2428 case "CONFIRMED":
2429 *p = StatusConfirmed
2430 case "CANCELLED":
2431 *p = StatusCancelled
2432 case "NEEDS-ACTION":
2433 *p = StatusNeedsAction
2434 case "COMPLETED":
2435 *p = StatusCompleted
2436 case "IN-PROCESS":
2437 *p = StatusInProcess
2438 case "DRAFT":
2439 *p = StatusDraft
2440 case "FINAL":
2441 *p = StatusFinal
2442 default:
2443 return fmt.Errorf(errDecodingType, cStatus, ErrInvalidValue)
2444 }
2445 return nil
2446 }
2447
2448 func (p *PropStatus) encode(w writer) {
2449 w.WriteString("STATUS:")
2450 switch *p {
2451 case StatusTentative:
2452 w.WriteString("TENTATIVE")
2453 case StatusConfirmed:
2454 w.WriteString("CONFIRMED")
2455 case StatusCancelled:
2456 w.WriteString("CANCELLED")
2457 case StatusNeedsAction:
2458 w.WriteString("NEEDS-ACTION")
2459 case StatusCompleted:
2460 w.WriteString("COMPLETED")
2461 case StatusInProcess:
2462 w.WriteString("IN-PROCESS")
2463 case StatusDraft:
2464 w.WriteString("DRAFT")
2465 case StatusFinal:
2466 w.WriteString("FINAL")
2467 }
2468 w.WriteString("\r\n")
2469 }
2470
2471 func (p *PropStatus) valid() error {
2472 switch *p {
2473 case StatusTentative, StatusConfirmed, StatusCancelled, StatusNeedsAction, StatusCompleted, StatusInProcess, StatusDraft, StatusFinal:
2474 default:
2475 return fmt.Errorf(errValidatingType, cStatus, ErrInvalidValue)
2476 }
2477 return nil
2478 }
2479
2480 // PropSummary defines a short summary or subject for the calendar component
2481 type PropSummary struct {
2482 AlternativeRepresentation *ParamAlternativeRepresentation
2483 Language *ParamLanguage
2484 Text
2485 }
2486
2487 func (p *PropSummary) decode(params []parser.Token, value string) error {
2488 oParams := make(map[string]string)
2489 var ts []string
2490 for len(params) > 0 {
2491 pName := strings.ToUpper(params[0].Data)
2492 i := 1
2493 for i < len(params) && params[i].Type != tokenParamName {
2494 i++
2495 }
2496 pValues := params[1:i]
2497 params = params[i:]
2498 switch pName {
2499 case "ALTREP":
2500 if p.AlternativeRepresentation != nil {
2501 return fmt.Errorf(errDecodingProp, cSummary, cAlternativeRepresentation, ErrDuplicateParam)
2502 }
2503 p.AlternativeRepresentation = new(ParamAlternativeRepresentation)
2504 if err := p.AlternativeRepresentation.decode(pValues); err != nil {
2505 return fmt.Errorf(errDecodingProp, cSummary, cAlternativeRepresentation, err)
2506 }
2507 case "LANGUAGE":
2508 if p.Language != nil {
2509 return fmt.Errorf(errDecodingProp, cSummary, cLanguage, ErrDuplicateParam)
2510 }
2511 p.Language = new(ParamLanguage)
2512 if err := p.Language.decode(pValues); err != nil {
2513 return fmt.Errorf(errDecodingProp, cSummary, cLanguage, err)
2514 }
2515 default:
2516 for _, v := range pValues {
2517 ts = append(ts, v.Data)
2518 }
2519 oParams[pName] = strings.Join(ts, ",")
2520 ts = ts[:0]
2521 }
2522 }
2523 if err := p.Text.decode(oParams, value); err != nil {
2524 return fmt.Errorf(errDecodingProp, cSummary, cText, err)
2525 }
2526 return nil
2527 }
2528
2529 func (p *PropSummary) encode(w writer) {
2530 w.WriteString("SUMMARY")
2531 if p.AlternativeRepresentation != nil {
2532 p.AlternativeRepresentation.encode(w)
2533 }
2534 if p.Language != nil {
2535 p.Language.encode(w)
2536 }
2537 p.Text.aencode(w)
2538 w.WriteString("\r\n")
2539 }
2540
2541 func (p *PropSummary) valid() error {
2542 if p.AlternativeRepresentation != nil {
2543 if err := p.AlternativeRepresentation.valid(); err != nil {
2544 return fmt.Errorf(errValidatingProp, cSummary, cAlternativeRepresentation, err)
2545 }
2546 }
2547 if p.Language != nil {
2548 if err := p.Language.valid(); err != nil {
2549 return fmt.Errorf(errValidatingProp, cSummary, cLanguage, err)
2550 }
2551 }
2552 if err := p.Text.valid(); err != nil {
2553 return fmt.Errorf(errValidatingProp, cSummary, cText, err)
2554 }
2555 return nil
2556 }
2557
2558 // PropTimeTransparency defines whether or not an event is transparent to busy
2559 // time searches
2560 type PropTimeTransparency uint8
2561
2562 // PropTimeTransparency constant values
2563 const (
2564 TimeTransparencyOpaque PropTimeTransparency = iota
2565 TimeTransparencyTransparent
2566 )
2567
2568 // New returns a pointer to the type (used with constants for ease of use with
2569 // optional values)
2570 func (p PropTimeTransparency) New() *PropTimeTransparency {
2571 return &p
2572 }
2573
2574 func (p *PropTimeTransparency) decode(params []parser.Token, value string) error {
2575 switch strings.ToUpper(value) {
2576 case "OPAQUE":
2577 *p = TimeTransparencyOpaque
2578 case "TRANSPARENT":
2579 *p = TimeTransparencyTransparent
2580 default:
2581 return fmt.Errorf(errDecodingType, cTimeTransparency, ErrInvalidValue)
2582 }
2583 return nil
2584 }
2585
2586 func (p *PropTimeTransparency) encode(w writer) {
2587 w.WriteString("TRANSP:")
2588 switch *p {
2589 case TimeTransparencyOpaque:
2590 w.WriteString("OPAQUE")
2591 case TimeTransparencyTransparent:
2592 w.WriteString("TRANSPARENT")
2593 }
2594 w.WriteString("\r\n")
2595 }
2596
2597 func (p *PropTimeTransparency) valid() error {
2598 switch *p {
2599 case TimeTransparencyOpaque, TimeTransparencyTransparent:
2600 default:
2601 return fmt.Errorf(errValidatingType, cTimeTransparency, ErrInvalidValue)
2602 }
2603 return nil
2604 }
2605
2606 // PropTrigger specifies when an alarm will trigger
2607 type PropTrigger struct {
2608 Duration *Duration
2609 DateTime *DateTime
2610 }
2611
2612 func (p *PropTrigger) decode(params []parser.Token, value string) error {
2613 vType := -1
2614 oParams := make(map[string]string)
2615 var ts []string
2616 for len(params) > 0 {
2617 pName := strings.ToUpper(params[0].Data)
2618 i := 1
2619 for i < len(params) && params[i].Type != tokenParamName {
2620 i++
2621 }
2622 pValues := params[1:i]
2623 params = params[i:]
2624 switch pName {
2625 case "VALUE":
2626 if len(pValues) != 1 {
2627 return fmt.Errorf(errDecodingProp, cTrigger, cValue, ErrInvalidValue)
2628 }
2629 if vType != -1 {
2630 return fmt.Errorf(errDecodingProp, cTrigger, cValue, ErrDuplicateParam)
2631 }
2632 switch strings.ToUpper(pValues[0].Data) {
2633 case "DURATION":
2634 vType = 0
2635 case "DATE-TIME":
2636 vType = 1
2637 default:
2638 return fmt.Errorf(errDecodingType, cTrigger, ErrInvalidValue)
2639 }
2640 default:
2641 for _, v := range pValues {
2642 ts = append(ts, v.Data)
2643 }
2644 oParams[pName] = strings.Join(ts, ",")
2645 ts = ts[:0]
2646 }
2647 }
2648 if vType == -1 {
2649 vType = 0
2650 }
2651 switch vType {
2652 case 0:
2653 p.Duration = new(Duration)
2654 if err := p.Duration.decode(oParams, value); err != nil {
2655 return fmt.Errorf(errDecodingProp, cTrigger, cDuration, err)
2656 }
2657 case 1:
2658 p.DateTime = new(DateTime)
2659 if err := p.DateTime.decode(oParams, value); err != nil {
2660 return fmt.Errorf(errDecodingProp, cTrigger, cDateTime, err)
2661 }
2662 }
2663 return nil
2664 }
2665
2666 func (p *PropTrigger) encode(w writer) {
2667 w.WriteString("TRIGGER")
2668 if p.Duration != nil {
2669 p.Duration.aencode(w)
2670 }
2671 if p.DateTime != nil {
2672 w.WriteString(";VALUE=DATE-TIME")
2673 p.DateTime.aencode(w)
2674 }
2675 w.WriteString("\r\n")
2676 }
2677
2678 func (p *PropTrigger) valid() error {
2679 c := 0
2680 if p.Duration != nil {
2681 if err := p.Duration.valid(); err != nil {
2682 return fmt.Errorf(errValidatingProp, cTrigger, cDuration, err)
2683 }
2684 c++
2685 }
2686 if p.DateTime != nil {
2687 if err := p.DateTime.valid(); err != nil {
2688 return fmt.Errorf(errValidatingProp, cTrigger, cDateTime, err)
2689 }
2690 c++
2691 }
2692 if c != 1 {
2693 return fmt.Errorf(errValidatingType, cTrigger, ErrInvalidValue)
2694 }
2695 return nil
2696 }
2697
2698 // PropTimezoneID specifies the text value that uniquely identifies the
2699 // "VTIMEZONE" calendar component in the scope of an iCalendar object
2700 type PropTimezoneID Text
2701
2702 func (p *PropTimezoneID) decode(params []parser.Token, value string) error {
2703 oParams := make(map[string]string)
2704 var ts []string
2705 for len(params) > 0 {
2706 i := 1
2707 for i < len(params) && params[i].Type != tokenParamName {
2708 i++
2709 }
2710 pValues := params[1:i]
2711 for _, v := range pValues {
2712 ts = append(ts, v.Data)
2713 }
2714 oParams[strings.ToUpper(params[0].Data)] = strings.Join(ts, ",")
2715 params = params[i:]
2716 ts = ts[:0]
2717 }
2718 var t Text
2719 if err := t.decode(oParams, value); err != nil {
2720 return fmt.Errorf(errDecodingType, cTimezoneID, err)
2721 }
2722 *p = PropTimezoneID(t)
2723 return nil
2724 }
2725
2726 func (p *PropTimezoneID) encode(w writer) {
2727 w.WriteString("TZID")
2728 t := Text(*p)
2729 t.aencode(w)
2730 w.WriteString("\r\n")
2731 }
2732
2733 func (p *PropTimezoneID) valid() error {
2734 t := Text(*p)
2735 if err := t.valid(); err != nil {
2736 return fmt.Errorf(errValidatingType, cTimezoneID, err)
2737 }
2738 return nil
2739 }
2740
2741 // PropTimezoneName specifies the customary designation for a time zone
2742 // description
2743 type PropTimezoneName struct {
2744 Language *ParamLanguage
2745 Text
2746 }
2747
2748 func (p *PropTimezoneName) decode(params []parser.Token, value string) error {
2749 oParams := make(map[string]string)
2750 var ts []string
2751 for len(params) > 0 {
2752 pName := strings.ToUpper(params[0].Data)
2753 i := 1
2754 for i < len(params) && params[i].Type != tokenParamName {
2755 i++
2756 }
2757 pValues := params[1:i]
2758 params = params[i:]
2759 switch pName {
2760 case "LANGUAGE":
2761 if p.Language != nil {
2762 return fmt.Errorf(errDecodingProp, cTimezoneName, cLanguage, ErrDuplicateParam)
2763 }
2764 p.Language = new(ParamLanguage)
2765 if err := p.Language.decode(pValues); err != nil {
2766 return fmt.Errorf(errDecodingProp, cTimezoneName, cLanguage, err)
2767 }
2768 default:
2769 for _, v := range pValues {
2770 ts = append(ts, v.Data)
2771 }
2772 oParams[pName] = strings.Join(ts, ",")
2773 ts = ts[:0]
2774 }
2775 }
2776 if err := p.Text.decode(oParams, value); err != nil {
2777 return fmt.Errorf(errDecodingProp, cTimezoneName, cText, err)
2778 }
2779 return nil
2780 }
2781
2782 func (p *PropTimezoneName) encode(w writer) {
2783 w.WriteString("TZNAME")
2784 if p.Language != nil {
2785 p.Language.encode(w)
2786 }
2787 p.Text.aencode(w)
2788 w.WriteString("\r\n")
2789 }
2790
2791 func (p *PropTimezoneName) valid() error {
2792 if p.Language != nil {
2793 if err := p.Language.valid(); err != nil {
2794 return fmt.Errorf(errValidatingProp, cTimezoneName, cLanguage, err)
2795 }
2796 }
2797 if err := p.Text.valid(); err != nil {
2798 return fmt.Errorf(errValidatingProp, cTimezoneName, cText, err)
2799 }
2800 return nil
2801 }
2802
2803 // PropTimezoneOffsetFrom specifies the offset that is in use prior to this time
2804 // zone observance
2805 type PropTimezoneOffsetFrom UTCOffset
2806
2807 func (p *PropTimezoneOffsetFrom) decode(params []parser.Token, value string) error {
2808 oParams := make(map[string]string)
2809 var ts []string
2810 for len(params) > 0 {
2811 i := 1
2812 for i < len(params) && params[i].Type != tokenParamName {
2813 i++
2814 }
2815 pValues := params[1:i]
2816 for _, v := range pValues {
2817 ts = append(ts, v.Data)
2818 }
2819 oParams[strings.ToUpper(params[0].Data)] = strings.Join(ts, ",")
2820 params = params[i:]
2821 ts = ts[:0]
2822 }
2823 var t UTCOffset
2824 if err := t.decode(oParams, value); err != nil {
2825 return fmt.Errorf(errDecodingType, cTimezoneOffsetFrom, err)
2826 }
2827 *p = PropTimezoneOffsetFrom(t)
2828 return nil
2829 }
2830
2831 func (p *PropTimezoneOffsetFrom) encode(w writer) {
2832 w.WriteString("TZOFFSETFROM")
2833 t := UTCOffset(*p)
2834 t.aencode(w)
2835 w.WriteString("\r\n")
2836 }
2837
2838 func (p *PropTimezoneOffsetFrom) valid() error {
2839 t := UTCOffset(*p)
2840 if err := t.valid(); err != nil {
2841 return fmt.Errorf(errValidatingType, cTimezoneOffsetFrom, err)
2842 }
2843 return nil
2844 }
2845
2846 // PropTimezoneOffsetTo specifies the offset that is in use in this time zone
2847 // observance
2848 type PropTimezoneOffsetTo UTCOffset
2849
2850 func (p *PropTimezoneOffsetTo) decode(params []parser.Token, value string) error {
2851 oParams := make(map[string]string)
2852 var ts []string
2853 for len(params) > 0 {
2854 i := 1
2855 for i < len(params) && params[i].Type != tokenParamName {
2856 i++
2857 }
2858 pValues := params[1:i]
2859 for _, v := range pValues {
2860 ts = append(ts, v.Data)
2861 }
2862 oParams[strings.ToUpper(params[0].Data)] = strings.Join(ts, ",")
2863 params = params[i:]
2864 ts = ts[:0]
2865 }
2866 var t UTCOffset
2867 if err := t.decode(oParams, value); err != nil {
2868 return fmt.Errorf(errDecodingType, cTimezoneOffsetTo, err)
2869 }
2870 *p = PropTimezoneOffsetTo(t)
2871 return nil
2872 }
2873
2874 func (p *PropTimezoneOffsetTo) encode(w writer) {
2875 w.WriteString("TZOFFSETTO")
2876 t := UTCOffset(*p)
2877 t.aencode(w)
2878 w.WriteString("\r\n")
2879 }
2880
2881 func (p *PropTimezoneOffsetTo) valid() error {
2882 t := UTCOffset(*p)
2883 if err := t.valid(); err != nil {
2884 return fmt.Errorf(errValidatingType, cTimezoneOffsetTo, err)
2885 }
2886 return nil
2887 }
2888
2889 // PropTimezoneURL provides a means for a "VTIMEZONE" component to point to a
2890 // network location that can be used to retrieve an up- to-date version of
2891 // itself
2892 type PropTimezoneURL URI
2893
2894 func (p *PropTimezoneURL) decode(params []parser.Token, value string) error {
2895 oParams := make(map[string]string)
2896 var ts []string
2897 for len(params) > 0 {
2898 i := 1
2899 for i < len(params) && params[i].Type != tokenParamName {
2900 i++
2901 }
2902 pValues := params[1:i]
2903 for _, v := range pValues {
2904 ts = append(ts, v.Data)
2905 }
2906 oParams[strings.ToUpper(params[0].Data)] = strings.Join(ts, ",")
2907 params = params[i:]
2908 ts = ts[:0]
2909 }
2910 var t URI
2911 if err := t.decode(oParams, value); err != nil {
2912 return fmt.Errorf(errDecodingType, cTimezoneURL, err)
2913 }
2914 *p = PropTimezoneURL(t)
2915 return nil
2916 }
2917
2918 func (p *PropTimezoneURL) encode(w writer) {
2919 w.WriteString("TZURL")
2920 t := URI(*p)
2921 t.aencode(w)
2922 w.WriteString("\r\n")
2923 }
2924
2925 func (p *PropTimezoneURL) valid() error {
2926 t := URI(*p)
2927 if err := t.valid(); err != nil {
2928 return fmt.Errorf(errValidatingType, cTimezoneURL, err)
2929 }
2930 return nil
2931 }
2932
2933 // PropUID defines the persistent, globally unique identifier for the calendar
2934 // component
2935 type PropUID Text
2936
2937 func (p *PropUID) decode(params []parser.Token, value string) error {
2938 oParams := make(map[string]string)
2939 var ts []string
2940 for len(params) > 0 {
2941 i := 1
2942 for i < len(params) && params[i].Type != tokenParamName {
2943 i++
2944 }
2945 pValues := params[1:i]
2946 for _, v := range pValues {
2947 ts = append(ts, v.Data)
2948 }
2949 oParams[strings.ToUpper(params[0].Data)] = strings.Join(ts, ",")
2950 params = params[i:]
2951 ts = ts[:0]
2952 }
2953 var t Text
2954 if err := t.decode(oParams, value); err != nil {
2955 return fmt.Errorf(errDecodingType, cUID, err)
2956 }
2957 *p = PropUID(t)
2958 return nil
2959 }
2960
2961 func (p *PropUID) encode(w writer) {
2962 w.WriteString("UID")
2963 t := Text(*p)
2964 t.aencode(w)
2965 w.WriteString("\r\n")
2966 }
2967
2968 func (p *PropUID) valid() error {
2969 t := Text(*p)
2970 if err := t.valid(); err != nil {
2971 return fmt.Errorf(errValidatingType, cUID, err)
2972 }
2973 return nil
2974 }
2975
2976 // PropURL defines a Uniform Resource Locator associated with the iCalendar
2977 // object
2978 type PropURL URI
2979
2980 func (p *PropURL) decode(params []parser.Token, value string) error {
2981 oParams := make(map[string]string)
2982 var ts []string
2983 for len(params) > 0 {
2984 i := 1
2985 for i < len(params) && params[i].Type != tokenParamName {
2986 i++
2987 }
2988 pValues := params[1:i]
2989 for _, v := range pValues {
2990 ts = append(ts, v.Data)
2991 }
2992 oParams[strings.ToUpper(params[0].Data)] = strings.Join(ts, ",")
2993 params = params[i:]
2994 ts = ts[:0]
2995 }
2996 var t URI
2997 if err := t.decode(oParams, value); err != nil {
2998 return fmt.Errorf(errDecodingType, cURL, err)
2999 }
3000 *p = PropURL(t)
3001 return nil
3002 }
3003
3004 func (p *PropURL) encode(w writer) {
3005 w.WriteString("URL")
3006 t := URI(*p)
3007 t.aencode(w)
3008 w.WriteString("\r\n")
3009 }
3010
3011 func (p *PropURL) valid() error {
3012 t := URI(*p)
3013 if err := t.valid(); err != nil {
3014 return fmt.Errorf(errValidatingType, cURL, err)
3015 }
3016 return nil
3017 }
3018
3019 // PropURI
3020 type PropURI URI
3021
3022 func (p *PropURI) decode(params []parser.Token, value string) error {
3023 oParams := make(map[string]string)
3024 var ts []string
3025 for len(params) > 0 {
3026 i := 1
3027 for i < len(params) && params[i].Type != tokenParamName {
3028 i++
3029 }
3030 pValues := params[1:i]
3031 for _, v := range pValues {
3032 ts = append(ts, v.Data)
3033 }
3034 oParams[strings.ToUpper(params[0].Data)] = strings.Join(ts, ",")
3035 params = params[i:]
3036 ts = ts[:0]
3037 }
3038 var t URI
3039 if err := t.decode(oParams, value); err != nil {
3040 return fmt.Errorf(errDecodingType, cURI, err)
3041 }
3042 *p = PropURI(t)
3043 return nil
3044 }
3045
3046 func (p *PropURI) encode(w writer) {
3047 w.WriteString("URI")
3048 t := URI(*p)
3049 t.aencode(w)
3050 w.WriteString("\r\n")
3051 }
3052
3053 func (p *PropURI) valid() error {
3054 t := URI(*p)
3055 if err := t.valid(); err != nil {
3056 return fmt.Errorf(errValidatingType, cURI, err)
3057 }
3058 return nil
3059 }
3060
3061 // PropVersion specifies the identifier corresponding to the highest version
3062 // number or the minimum and maximum range of the iCalendar specification that
3063 // is required in order to interpret the iCalendar object
3064 type PropVersion Text
3065
3066 func (p *PropVersion) decode(params []parser.Token, value string) error {
3067 oParams := make(map[string]string)
3068 var ts []string
3069 for len(params) > 0 {
3070 i := 1
3071 for i < len(params) && params[i].Type != tokenParamName {
3072 i++
3073 }
3074 pValues := params[1:i]
3075 for _, v := range pValues {
3076 ts = append(ts, v.Data)
3077 }
3078 oParams[strings.ToUpper(params[0].Data)] = strings.Join(ts, ",")
3079 params = params[i:]
3080 ts = ts[:0]
3081 }
3082 var t Text
3083 if err := t.decode(oParams, value); err != nil {
3084 return fmt.Errorf(errDecodingType, cVersion, err)
3085 }
3086 *p = PropVersion(t)
3087 return nil
3088 }
3089
3090 func (p *PropVersion) encode(w writer) {
3091 w.WriteString("VERSION")
3092 t := Text(*p)
3093 t.aencode(w)
3094 w.WriteString("\r\n")
3095 }
3096
3097 func (p *PropVersion) valid() error {
3098 t := Text(*p)
3099 if err := t.valid(); err != nil {
3100 return fmt.Errorf(errValidatingType, cVersion, err)
3101 }
3102 return nil
3103 }
3104
3105 // PropAlarmAgent
3106 type PropAlarmAgent struct {
3107 URI *ParamURI
3108 ID *ParamID
3109 AgentID *ParamAgentID
3110 Text
3111 }
3112
3113 func (p *PropAlarmAgent) decode(params []parser.Token, value string) error {
3114 oParams := make(map[string]string)
3115 var ts []string
3116 for len(params) > 0 {
3117 pName := strings.ToUpper(params[0].Data)
3118 i := 1
3119 for i < len(params) && params[i].Type != tokenParamName {
3120 i++
3121 }
3122 pValues := params[1:i]
3123 params = params[i:]
3124 switch pName {
3125 case "URI":
3126 if p.URI != nil {
3127 return fmt.Errorf(errDecodingProp, cAlarmAgent, cURI, ErrDuplicateParam)
3128 }
3129 p.URI = new(ParamURI)
3130 if err := p.URI.decode(pValues); err != nil {
3131 return fmt.Errorf(errDecodingProp, cAlarmAgent, cURI, err)
3132 }
3133 case "ID":
3134 if p.ID != nil {
3135 return fmt.Errorf(errDecodingProp, cAlarmAgent, cID, ErrDuplicateParam)
3136 }
3137 p.ID = new(ParamID)
3138 if err := p.ID.decode(pValues); err != nil {
3139 return fmt.Errorf(errDecodingProp, cAlarmAgent, cID, err)
3140 }
3141 case "AGENT-ID":
3142 if p.AgentID != nil {
3143 return fmt.Errorf(errDecodingProp, cAlarmAgent, cAgentID, ErrDuplicateParam)
3144 }
3145 p.AgentID = new(ParamAgentID)
3146 if err := p.AgentID.decode(pValues); err != nil {
3147 return fmt.Errorf(errDecodingProp, cAlarmAgent, cAgentID, err)
3148 }
3149 default:
3150 for _, v := range pValues {
3151 ts = append(ts, v.Data)
3152 }
3153 oParams[pName] = strings.Join(ts, ",")
3154 ts = ts[:0]
3155 }
3156 }
3157 if err := p.Text.decode(oParams, value); err != nil {
3158 return fmt.Errorf(errDecodingProp, cAlarmAgent, cText, err)
3159 }
3160 return nil
3161 }
3162
3163 func (p *PropAlarmAgent) encode(w writer) {
3164 w.WriteString("ALARM-AGENT")
3165 if p.URI != nil {
3166 p.URI.encode(w)
3167 }
3168 if p.ID != nil {
3169 p.ID.encode(w)
3170 }
3171 if p.AgentID != nil {
3172 p.AgentID.encode(w)
3173 }
3174 p.Text.aencode(w)
3175 w.WriteString("\r\n")
3176 }
3177
3178 func (p *PropAlarmAgent) valid() error {
3179 if p.URI != nil {
3180 if err := p.URI.valid(); err != nil {
3181 return fmt.Errorf(errValidatingProp, cAlarmAgent, cURI, err)
3182 }
3183 }
3184 if p.ID != nil {
3185 if err := p.ID.valid(); err != nil {
3186 return fmt.Errorf(errValidatingProp, cAlarmAgent, cID, err)
3187 }
3188 }
3189 if p.AgentID != nil {
3190 if err := p.AgentID.valid(); err != nil {
3191 return fmt.Errorf(errValidatingProp, cAlarmAgent, cAgentID, err)
3192 }
3193 }
3194 if err := p.Text.valid(); err != nil {
3195 return fmt.Errorf(errValidatingProp, cAlarmAgent, cText, err)
3196 }
3197 return nil
3198 }
3199
3200 // PropAlarmStatus
3201 type PropAlarmStatus uint8
3202
3203 // PropAlarmStatus constant values
3204 const (
3205 AlarmStatusActive PropAlarmStatus = iota
3206 AlarmStatusCancelled
3207 AlarmStatusCompleted
3208 )
3209
3210 // New returns a pointer to the type (used with constants for ease of use with
3211 // optional values)
3212 func (p PropAlarmStatus) New() *PropAlarmStatus {
3213 return &p
3214 }
3215
3216 func (p *PropAlarmStatus) decode(params []parser.Token, value string) error {
3217 switch strings.ToUpper(value) {
3218 case "ACTIVE":
3219 *p = AlarmStatusActive
3220 case "CANCELLED":
3221 *p = AlarmStatusCancelled
3222 case "COMPLETED":
3223 *p = AlarmStatusCompleted
3224 default:
3225 return fmt.Errorf(errDecodingType, cAlarmStatus, ErrInvalidValue)
3226 }
3227 return nil
3228 }
3229
3230 func (p *PropAlarmStatus) encode(w writer) {
3231 w.WriteString("STATUS:")
3232 switch *p {
3233 case AlarmStatusActive:
3234 w.WriteString("ACTIVE")
3235 case AlarmStatusCancelled:
3236 w.WriteString("CANCELLED")
3237 case AlarmStatusCompleted:
3238 w.WriteString("COMPLETED")
3239 }
3240 w.WriteString("\r\n")
3241 }
3242
3243 func (p *PropAlarmStatus) valid() error {
3244 switch *p {
3245 case AlarmStatusActive, AlarmStatusCancelled, AlarmStatusCompleted:
3246 default:
3247 return fmt.Errorf(errValidatingType, cAlarmStatus, ErrInvalidValue)
3248 }
3249 return nil
3250 }
3251
3252 // PropLastTriggered
3253 type PropLastTriggered DateTime
3254
3255 func (p *PropLastTriggered) decode(params []parser.Token, value string) error {
3256 oParams := make(map[string]string)
3257 var ts []string
3258 for len(params) > 0 {
3259 i := 1
3260 for i < len(params) && params[i].Type != tokenParamName {
3261 i++
3262 }
3263 pValues := params[1:i]
3264 for _, v := range pValues {
3265 ts = append(ts, v.Data)
3266 }
3267 oParams[strings.ToUpper(params[0].Data)] = strings.Join(ts, ",")
3268 params = params[i:]
3269 ts = ts[:0]
3270 }
3271 var t DateTime
3272 if err := t.decode(oParams, value); err != nil {
3273 return fmt.Errorf(errDecodingType, cLastTriggered, err)
3274 }
3275 *p = PropLastTriggered(t)
3276 return nil
3277 }
3278
3279 func (p *PropLastTriggered) encode(w writer) {
3280 w.WriteString("LAST-TRIGGERED")
3281 t := DateTime(*p)
3282 t.aencode(w)
3283 w.WriteString("\r\n")
3284 }
3285
3286 func (p *PropLastTriggered) valid() error {
3287 t := DateTime(*p)
3288 if err := t.valid(); err != nil {
3289 return fmt.Errorf(errValidatingType, cLastTriggered, err)
3290 }
3291 return nil
3292 }
3293
3294 // PropAcknowledged
3295 type PropAcknowledged DateTime
3296
3297 func (p *PropAcknowledged) decode(params []parser.Token, value string) error {
3298 oParams := make(map[string]string)
3299 var ts []string
3300 for len(params) > 0 {
3301 i := 1
3302 for i < len(params) && params[i].Type != tokenParamName {
3303 i++
3304 }
3305 pValues := params[1:i]
3306 for _, v := range pValues {
3307 ts = append(ts, v.Data)
3308 }
3309 oParams[strings.ToUpper(params[0].Data)] = strings.Join(ts, ",")
3310 params = params[i:]
3311 ts = ts[:0]
3312 }
3313 var t DateTime
3314 if err := t.decode(oParams, value); err != nil {
3315 return fmt.Errorf(errDecodingType, cAcknowledged, err)
3316 }
3317 *p = PropAcknowledged(t)
3318 return nil
3319 }
3320
3321 func (p *PropAcknowledged) encode(w writer) {
3322 w.WriteString("ACKNOWLEDGED")
3323 t := DateTime(*p)
3324 t.aencode(w)
3325 w.WriteString("\r\n")
3326 }
3327
3328 func (p *PropAcknowledged) valid() error {
3329 t := DateTime(*p)
3330 if err := t.valid(); err != nil {
3331 return fmt.Errorf(errValidatingType, cAcknowledged, err)
3332 }
3333 return nil
3334 }
3335
3336 // PropProximity
3337 type PropProximity Text
3338
3339 func (p *PropProximity) decode(params []parser.Token, value string) error {
3340 oParams := make(map[string]string)
3341 var ts []string
3342 for len(params) > 0 {
3343 i := 1
3344 for i < len(params) && params[i].Type != tokenParamName {
3345 i++
3346 }
3347 pValues := params[1:i]
3348 for _, v := range pValues {
3349 ts = append(ts, v.Data)
3350 }
3351 oParams[strings.ToUpper(params[0].Data)] = strings.Join(ts, ",")
3352 params = params[i:]
3353 ts = ts[:0]
3354 }
3355 var t Text
3356 if err := t.decode(oParams, value); err != nil {
3357 return fmt.Errorf(errDecodingType, cProximity, err)
3358 }
3359 *p = PropProximity(t)
3360 return nil
3361 }
3362
3363 func (p *PropProximity) encode(w writer) {
3364 w.WriteString("PROXIMITY")
3365 t := Text(*p)
3366 t.aencode(w)
3367 w.WriteString("\r\n")
3368 }
3369
3370 func (p *PropProximity) valid() error {
3371 t := Text(*p)
3372 if err := t.valid(); err != nil {
3373 return fmt.Errorf(errValidatingType, cProximity, err)
3374 }
3375 return nil
3376 }
3377
3378 // PropGeoLocation
3379 type PropGeoLocation URI
3380
3381 func (p *PropGeoLocation) decode(params []parser.Token, value string) error {
3382 oParams := make(map[string]string)
3383 var ts []string
3384 for len(params) > 0 {
3385 i := 1
3386 for i < len(params) && params[i].Type != tokenParamName {
3387 i++
3388 }
3389 pValues := params[1:i]
3390 for _, v := range pValues {
3391 ts = append(ts, v.Data)
3392 }
3393 oParams[strings.ToUpper(params[0].Data)] = strings.Join(ts, ",")
3394 params = params[i:]
3395 ts = ts[:0]
3396 }
3397 var t URI
3398 if err := t.decode(oParams, value); err != nil {
3399 return fmt.Errorf(errDecodingType, cGeoLocation, err)
3400 }
3401 *p = PropGeoLocation(t)
3402 return nil
3403 }
3404
3405 func (p *PropGeoLocation) encode(w writer) {
3406 w.WriteString("GEO-LOCATION")
3407 t := URI(*p)
3408 t.aencode(w)
3409 w.WriteString("\r\n")
3410 }
3411
3412 func (p *PropGeoLocation) valid() error {
3413 t := URI(*p)
3414 if err := t.valid(); err != nil {
3415 return fmt.Errorf(errValidatingType, cGeoLocation, err)
3416 }
3417 return nil
3418 }
3419
3420 // PropDefaultAlarm
3421 type PropDefaultAlarm Boolean
3422
3423 func (p *PropDefaultAlarm) decode(params []parser.Token, value string) error {
3424 oParams := make(map[string]string)
3425 var ts []string
3426 for len(params) > 0 {
3427 i := 1
3428 for i < len(params) && params[i].Type != tokenParamName {
3429 i++
3430 }
3431 pValues := params[1:i]
3432 for _, v := range pValues {
3433 ts = append(ts, v.Data)
3434 }
3435 oParams[strings.ToUpper(params[0].Data)] = strings.Join(ts, ",")
3436 params = params[i:]
3437 ts = ts[:0]
3438 }
3439 var t Boolean
3440 if err := t.decode(oParams, value); err != nil {
3441 return fmt.Errorf(errDecodingType, cDefaultAlarm, err)
3442 }
3443 *p = PropDefaultAlarm(t)
3444 return nil
3445 }
3446
3447 func (p *PropDefaultAlarm) encode(w writer) {
3448 w.WriteString("DEFAULT-ALARM")
3449 t := Boolean(*p)
3450 t.aencode(w)
3451 w.WriteString("\r\n")
3452 }
3453
3454 func (p *PropDefaultAlarm) valid() error {
3455 t := Boolean(*p)
3456 if err := t.valid(); err != nil {
3457 return fmt.Errorf(errValidatingType, cDefaultAlarm, err)
3458 }
3459 return nil
3460 }
3461
3462 // Errors
3463 var (
3464 ErrDuplicateParam = errors.New("duplicate param")
3465 )
3466
3467 const (
3468 errDecodingProp = "error decoding %s->%s: %w"
3469 errValidatingProp = "error validating %s->%s: %w"
3470 cAction = "Action"
3471 cAttachment = "Attachment"
3472 cAttendee = "Attendee"
3473 cCalendarScale = "CalendarScale"
3474 cCategories = "Categories"
3475 cClass = "Class"
3476 cComment = "Comment"
3477 cCompleted = "Completed"
3478 cContact = "Contact"
3479 cCreated = "Created"
3480 cDescription = "Description"
3481 cDateTimeEnd = "DateTimeEnd"
3482 cDateTimeStamp = "DateTimeStamp"
3483 cDateTimeStart = "DateTimeStart"
3484 cDue = "Due"
3485 cDuration = "Duration"
3486 cExceptionDateTime = "ExceptionDateTime"
3487 cFreeBusy = "FreeBusy"
3488 cGeo = "Geo"
3489 cLastModified = "LastModified"
3490 cLocation = "Location"
3491 cMethod = "Method"
3492 cOrganizer = "Organizer"
3493 cPercentComplete = "PercentComplete"
3494 cPriority = "Priority"
3495 cProductID = "ProductID"
3496 cRecurrenceDateTimes = "RecurrenceDateTimes"
3497 cRecurrenceID = "RecurrenceID"
3498 cRelatedTo = "RelatedTo"
3499 cRepeat = "Repeat"
3500 cRequestStatus = "RequestStatus"
3501 cResources = "Resources"
3502 cRecurrenceRule = "RecurrenceRule"
3503 cSequence = "Sequence"
3504 cStatus = "Status"
3505 cSummary = "Summary"
3506 cTimeTransparency = "TimeTransparency"
3507 cTrigger = "Trigger"
3508 cTimezoneName = "TimezoneName"
3509 cTimezoneOffsetFrom = "TimezoneOffsetFrom"
3510 cTimezoneOffsetTo = "TimezoneOffsetTo"
3511 cTimezoneURL = "TimezoneURL"
3512 cUID = "UID"
3513 cURL = "URL"
3514 cVersion = "Version"
3515 cAlarmAgent = "AlarmAgent"
3516 cAlarmStatus = "AlarmStatus"
3517 cLastTriggered = "LastTriggered"
3518 cAcknowledged = "Acknowledged"
3519 cProximity = "Proximity"
3520 cGeoLocation = "GeoLocation"
3521 cDefaultAlarm = "DefaultAlarm"
3522 )