Skip to content

Commit

Permalink
Merge pull request #35 from TesteurManiak/dev
Browse files Browse the repository at this point in the history
release: v1.0.1+1
  • Loading branch information
TesteurManiak authored Apr 7, 2022
2 parents 8d284e6 + e9c2c71 commit ad4444e
Show file tree
Hide file tree
Showing 12 changed files with 204 additions and 1,035 deletions.
13 changes: 1 addition & 12 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,23 @@
name: Dart

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
push

jobs:
analyze:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: dart-lang/setup-dart@v1
- name: Install dependencies
run: dart pub get

# Uncomment this step to verify the use of 'dart format' on each commit.
# - name: Verify formatting
# run: dart format --output=none --set-exit-if-changed .

# Consider passing '--fatal-infos' for slightly stricter analysis.
- name: Analyze project source
run: dart analyze
working-directory: ./lib

test:
needs: analyze
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: dart-lang/setup-dart@v1
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [1.0.1+1] - 07/04/2022

* Updated linting rules

## [1.0.1] - 04/10/2021

* Fixed [issue #33](https://github.com/TesteurManiak/icalendar_parser/issues/33): Exception on ORGANIZER field parsing
Expand Down
12 changes: 10 additions & 2 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
include: lint_analysis_options.yaml
include: package:lint/analysis_options_package.yaml

linter:
rules:
unnecessary_raw_strings: false
# Util classes are awesome!
# avoid_classes_with_only_static_members: false

# Make constructors the first thing in every class
# sort_constructors_first: true

# Choose wisely, but you don't have to
# prefer_double_quotes: true
# prefer_single_quotes: true
25 changes: 16 additions & 9 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.6.1"
version: "2.8.2"
boolean_selector:
dependency: transitive
description:
Expand All @@ -21,14 +21,14 @@ packages:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.2.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.1"
clock:
dependency: transitive
description:
Expand Down Expand Up @@ -87,7 +87,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.8.0+1"
version: "1.0.1"
intl:
dependency: transitive
description:
Expand All @@ -101,14 +101,21 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.10"
version: "0.12.11"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "1.7.0"
path:
dependency: transitive
description:
Expand Down Expand Up @@ -218,7 +225,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.0"
version: "0.4.8"
typed_data:
dependency: transitive
description:
Expand All @@ -232,7 +239,7 @@ packages:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
version: "2.1.1"
win32:
dependency: transitive
description:
Expand All @@ -248,5 +255,5 @@ packages:
source: hosted
version: "0.1.0"
sdks:
dart: ">=2.12.0 <3.0.0"
dart: ">=2.14.0 <3.0.0"
flutter: ">=1.12.13+hotfix.5"
119 changes: 82 additions & 37 deletions lib/src/model/icalendar.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import 'dart:convert';

import 'package:icalendar_parser/icalendar_parser.dart';
import 'package:icalendar_parser/src/exceptions/icalendar_exception.dart';
import 'package:icalendar_parser/src/model/ics_datetime.dart';
import 'package:icalendar_parser/src/utils/parsing_methods.dart';

/// Core object
Expand Down Expand Up @@ -67,17 +65,26 @@ class ICalendar {

/// Map containing the methods used to parse each kind of fields in the file.
static final Map<String, Function> _objects = {
'BEGIN': (String value, Map<String, String> params, List events,
Map<String, dynamic> lastEvent) {
'BEGIN': (
String value,
Map<String, String> params,
List events,
Map<String, dynamic> lastEvent,
) {
if (value == 'VCALENDAR') return null;

lastEvent = {'type': value};
events.add(lastEvent);

return lastEvent;
},
'END': (String value, Map<String, String> params, List events,
Map<String, dynamic>? lastEvent, List<Map<String, dynamic>?> data) {
'END': (
String value,
Map<String, String> params,
List events,
Map<String, dynamic>? lastEvent,
List<Map<String, dynamic>?> data,
) {
if (value == 'VCALENDAR') return lastEvent;

data.add(lastEvent);
Expand All @@ -104,8 +111,12 @@ class ICalendar {
'DESCRIPTION': generateSimpleParamFunction('description'),
'LOCATION': generateSimpleParamFunction('location'),
'URL': generateSimpleParamFunction('url'),
'ORGANIZER': (String value, Map<String, String> params, List events,
Map<String, dynamic> lastEvent) {
'ORGANIZER': (
String value,
Map<String, String> params,
List events,
Map<String, dynamic> lastEvent,
) {
final mail = value.replaceAll('MAILTO:', '').trim();

if (params.containsKey('CN')) {
Expand All @@ -119,23 +130,36 @@ class ICalendar {

return lastEvent;
},
'GEO': (String value, Map<String, String> params, List events,
Map<String, dynamic> lastEvent) {
'GEO': (
String value,
Map<String, String> params,
List events,
Map<String, dynamic> lastEvent,
) {
final pos = value.split(';');
if (pos.length != 2) return lastEvent;

lastEvent['geo'] = {};
lastEvent['geo']['latitude'] = num.parse(pos[0]);
lastEvent['geo']['longitude'] = num.parse(pos[1]);
final geo = <String, dynamic>{};
geo['latitude'] = num.parse(pos[0]);
geo['longitude'] = num.parse(pos[1]);
lastEvent['geo'] = geo;
return lastEvent;
},
'CATEGORIES': (String value, Map<String, String> params, List events,
Map<String, dynamic> lastEvent) {
'CATEGORIES': (
String value,
Map<String, String> params,
List events,
Map<String, dynamic> lastEvent,
) {
lastEvent['categories'] = value.split(',');
return lastEvent;
},
'ATTENDEE': (String value, Map<String, String> params, List _,
Map<String, dynamic> lastEvent) {
'ATTENDEE': (
String value,
Map<String, String> params,
_,
Map<String, dynamic> lastEvent,
) {
lastEvent['attendee'] ??= [];

final mail = value.replaceAll('MAILTO:', '').trim();
Expand All @@ -153,16 +177,14 @@ class ICalendar {
return lastEvent;
},
'ACTION': generateSimpleParamFunction('action'),
'STATUS': (String value, Map<String, String> _, List __,
Map<String, dynamic> lastEvent) {
'STATUS': (String value, _, __, Map<String, dynamic> lastEvent) {
lastEvent['status'] = value.trim().toIcsStatus();
return lastEvent;
},
'SEQUENCE': generateSimpleParamFunction('sequence'),
'REPEAT': generateSimpleParamFunction('repeat'),
'CLASS': generateSimpleParamFunction('class'),
'TRANSP': (String value, Map<String, String> _, List __,
Map<String, dynamic> lastEvent) {
'TRANSP': (String value, _, __, Map<String, dynamic> lastEvent) {
lastEvent['transp'] = value.trim().toIcsTransp();
return lastEvent;
},
Expand All @@ -185,8 +207,12 @@ class ICalendar {
/// `ICalendarFormatException`.
static void registerField({
required String field,
Function(String value, Map<String, String> params, List event,
Map<String, dynamic> lastEvent)?
Function(
String value,
Map<String, String> params,
List event,
Map<String, dynamic> lastEvent,
)?
function,
}) {
if (_objects.containsKey(field)) {
Expand Down Expand Up @@ -215,8 +241,10 @@ class ICalendar {
/// `List<Map<String, dynamic>> data`.
///
/// If [allowEmptyLine] is false the method will throw [EmptyLineException].
static List<dynamic> fromListToJson(List<String> lines,
{bool allowEmptyLine = true}) {
static List<dynamic> fromListToJson(
List<String> lines, {
bool allowEmptyLine = true,
}) {
final data = <Map<String, dynamic>>[];
final _headData = <String, dynamic>{};
final events = [];
Expand All @@ -226,13 +254,15 @@ class ICalendar {
// Ensure first line is BEGIN:VCALENDAR
if (lines.first.trim() != 'BEGIN:VCALENDAR') {
throw ICalendarBeginException(
'The first line must be BEGIN:VCALENDAR but was ${lines.first}.');
'The first line must be BEGIN:VCALENDAR but was ${lines.first}.',
);
}

// Ensure last line is END:VCALENDAR
if (lines.last.trim() != 'END:VCALENDAR') {
throw ICalendarEndException(
'The last line must be END:VCALENDAR but was ${lines.last}.');
'The last line must be END:VCALENDAR but was ${lines.last}.',
);
}

for (var i = 0; i < lines.length; i++) {
Expand All @@ -242,7 +272,7 @@ class ICalendar {
throw const EmptyLineException();
}

final exp = RegExp(r'^ ');
final exp = RegExp('^ ');
while (i + 1 < lines.length && exp.hasMatch(lines[i + 1])) {
i += 1;
line.write(lines[i].trim());
Expand All @@ -254,7 +284,9 @@ class ICalendar {
dataLine[0].toUpperCase() != dataLine[0] &&
!dataLine[0].contains(';'))) {
if (line.isNotEmpty && currentName != null) {
lastEvent![currentName] += line.toString();
final buffer = StringBuffer(lastEvent![currentName] as String);
buffer.write(line.toString());
lastEvent[currentName] = buffer.toString();
}
continue;
}
Expand All @@ -271,25 +303,38 @@ class ICalendar {

dataLine.removeRange(0, 1);
final value = dataLine.join(':').replaceAll(RegExp(r'\\,'), ',');
if (_objects.containsKey(name)) {
final nameFunc = _objects[name];
if (_objects.containsKey(name) && nameFunc != null) {
currentName = name.toLowerCase();
if (name == 'END') {
final func = nameFunc as Map<String, dynamic>? Function(
String,
Map<String, String>,
List,
Map<String, dynamic>?,
List<Map<String, dynamic>>,
);
currentName = null;
lastEvent = _objects[name]!(value, params, events, lastEvent, data)
as Map<String, dynamic>?;
lastEvent = func(value, params, events, lastEvent, data);
} else {
lastEvent =
_objects[name]!(value, params, events, lastEvent ?? _headData)
as Map<String, dynamic>?;
final func = nameFunc as Map<String, dynamic>? Function(
String,
Map<String, String>,
List,
Map<String, dynamic>,
);
lastEvent = func(value, params, events, lastEvent ?? _headData);
}
}
}
if (!_headData.containsKey('version')) {
throw const ICalendarNoVersionException(
'The body is missing the property VERSION');
'The body is missing the property VERSION',
);
} else if (!_headData.containsKey('prodid')) {
throw const ICalendarNoProdidException(
'The body is missing the property PRODID');
'The body is missing the property PRODID',
);
}
return [_headData, data];
}
Expand Down
Loading

0 comments on commit ad4444e

Please sign in to comment.