Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update parse.go #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 26 additions & 9 deletions parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ type Calendar struct {

// An Event represent a VEVENT component in an iCalendar
type Event struct {
Properties []*Property
Alarms []*Alarm
UID string
Timestamp time.Time
StartDate time.Time
EndDate time.Time
Summary string
Description string
Properties []*Property
Alarms []*Alarm
UID string
Timestamp time.Time
StartDate time.Time
EndDate time.Time
Summary string
Description string
RecurringRule string
}

// An Alarm represent a VALARM component in an iCalendar
Expand Down Expand Up @@ -81,6 +82,8 @@ func Parse(r io.Reader, l *time.Location) (*Calendar, error) {
p.location = l

text := unfold(string(bytes))

// Lex
p.lex = lex(text)
return p.parse()
}
Expand Down Expand Up @@ -126,7 +129,16 @@ func NewParam() *Param {

// unfold convert multiple line value to one line
func unfold(text string) string {
return strings.Replace(text, "\r\n ", "", -1)
newstring := text

// Convert multiple line values to a single line:
newstring = strings.Replace(newstring, "\r\n ", "", -1)

// Remove extra CRLF sequences
newstring = strings.Replace(newstring, "\r\n\r\n", "\r\n", -1)

// Return the new string
return newstring
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you add some fixtures to validate this change?

}

// next returns the next token.
Expand Down Expand Up @@ -449,6 +461,11 @@ func (p *parser) validateEvent(v *Event) error {
v.Description = prop.Value
uniqueCount["DESCRIPTION"]++
}

if prop.Name == "RRULE" {
v.RecurringRule = prop.Value
uniqueCount["RRULE"]++
}
}

if p.c.Method == "" && v.Timestamp.IsZero() {
Expand Down