Skip to content

Commit

Permalink
Improve parsing description of calendar event
Browse files Browse the repository at this point in the history
  • Loading branch information
sanketfirodiya committed May 2, 2018
1 parent cdd5a05 commit 65ffad7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
4 changes: 2 additions & 2 deletions CalendarKit-Swift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 6UJ7Z72VQ8;
DEVELOPMENT_TEAM = UMWTWMN2C7;
INFOPLIST_FILE = "CalendarKit-Swift/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand All @@ -754,7 +754,7 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 6UJ7Z72VQ8;
DEVELOPMENT_TEAM = UMWTWMN2C7;
INFOPLIST_FILE = "CalendarKit-Swift/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand Down
30 changes: 19 additions & 11 deletions CalendarKit-Swift/SwiftCal/ICSEventParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -260,23 +260,31 @@ class ICSEventParser: NSObject {
}

private static func description(from icsString: String) -> String? {

var descriptionString: NSString?

var eventScanner = Scanner(string: icsString)
eventScanner.charactersToBeSkipped = newlineCharacterSet()
eventScanner.scanUpTo(ICS.description, into: nil)

// Handle `DESCRIPTION;LANGUAGE=en-US:Dear Gary, Attached is the ...` format
eventScanner = Scanner(string: icsString)
eventScanner.charactersToBeSkipped = newlineCharacterSet()
eventScanner.scanUpTo(ICS.description2, into: nil)
eventScanner.scanUpTo(":", into: nil)
eventScanner.scanString(":", into: nil)
eventScanner.scanUpTo("\n", into: &descriptionString)
if descriptionString != nil {
descriptionString = descriptionString?.replacingOccurrences(of: ICS.description2, with: "").replacingOccurrences(of: "\\n", with: "\n").replacingOccurrences(of: "\\", with: "").trimmingCharacters(in: newlineCharacterSet()) as! NSString
}

// Handle description that has the language tag e.g.
// `DESCRIPTION;LANGUAGE=en-US:Dear Gary, Attached is the ...`
if descriptionString == nil {
eventScanner = Scanner(string: icsString)
eventScanner.charactersToBeSkipped = newlineCharacterSet()
eventScanner.scanUpTo(ICS.description2, into: nil)
eventScanner.scanUpTo(":", into: nil)
eventScanner.scanString(":", into: nil)
// Handle `DESCRIPTION:Dear Gary, Attached is the ...` format
if descriptionString?.length ?? 0 == 0 {
eventScanner.scanLocation = 0
eventScanner.scanUpTo(ICS.description, into: nil)
eventScanner.scanUpTo("\n", into: &descriptionString)
if descriptionString != nil {
descriptionString = descriptionString?.replacingOccurrences(of: ICS.description, with: "").replacingOccurrences(of: "\\n", with: "\n").replacingOccurrences(of: "\\", with: "").trimmingCharacters(in: newlineCharacterSet()) as! NSString
}
}

// a multi-line description can have newline characters
Expand All @@ -297,7 +305,7 @@ class ICSEventParser: NSObject {
}
}

return descriptionString?.replacingOccurrences(of: ICS.description, with: "").replacingOccurrences(of: "\\n", with: "\n").replacingOccurrences(of: "\\", with: "").trimmingCharacters(in: CharacterSet.newlines)
return descriptionString?.replacingOccurrences(of: "\\n", with: "\n").replacingOccurrences(of: "\\", with: "").trimmingCharacters(in: CharacterSet.newlines)
}

private static func newlineCharacterSet() -> CharacterSet {
Expand Down

0 comments on commit 65ffad7

Please sign in to comment.