Skip to content

Commit ad4444e

Browse files
Merge pull request #35 from TesteurManiak/dev
release: v1.0.1+1
2 parents 8d284e6 + e9c2c71 commit ad4444e

File tree

12 files changed

+204
-1035
lines changed

12 files changed

+204
-1035
lines changed

.github/workflows/dart.yml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,23 @@
66
name: Dart
77

88
on:
9-
push:
10-
branches: [ main ]
11-
pull_request:
12-
branches: [ main ]
9+
push
1310

1411
jobs:
1512
analyze:
1613
runs-on: ubuntu-latest
17-
1814
steps:
1915
- uses: actions/checkout@v2
2016
- uses: dart-lang/setup-dart@v1
2117
- name: Install dependencies
2218
run: dart pub get
23-
24-
# Uncomment this step to verify the use of 'dart format' on each commit.
25-
# - name: Verify formatting
26-
# run: dart format --output=none --set-exit-if-changed .
27-
28-
# Consider passing '--fatal-infos' for slightly stricter analysis.
2919
- name: Analyze project source
3020
run: dart analyze
3121
working-directory: ./lib
3222

3323
test:
3424
needs: analyze
3525
runs-on: ubuntu-latest
36-
3726
steps:
3827
- uses: actions/checkout@v2
3928
- uses: dart-lang/setup-dart@v1

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## [1.0.1+1] - 07/04/2022
4+
5+
* Updated linting rules
6+
37
## [1.0.1] - 04/10/2021
48

59
* Fixed [issue #33](https://github.com/TesteurManiak/icalendar_parser/issues/33): Exception on ORGANIZER field parsing

analysis_options.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
include: lint_analysis_options.yaml
1+
include: package:lint/analysis_options_package.yaml
22

33
linter:
44
rules:
5-
unnecessary_raw_strings: false
5+
# Util classes are awesome!
6+
# avoid_classes_with_only_static_members: false
7+
8+
# Make constructors the first thing in every class
9+
# sort_constructors_first: true
10+
11+
# Choose wisely, but you don't have to
12+
# prefer_double_quotes: true
13+
# prefer_single_quotes: true

example/pubspec.lock

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ packages:
77
name: async
88
url: "https://pub.dartlang.org"
99
source: hosted
10-
version: "2.6.1"
10+
version: "2.8.2"
1111
boolean_selector:
1212
dependency: transitive
1313
description:
@@ -21,14 +21,14 @@ packages:
2121
name: characters
2222
url: "https://pub.dartlang.org"
2323
source: hosted
24-
version: "1.1.0"
24+
version: "1.2.0"
2525
charcode:
2626
dependency: transitive
2727
description:
2828
name: charcode
2929
url: "https://pub.dartlang.org"
3030
source: hosted
31-
version: "1.2.0"
31+
version: "1.3.1"
3232
clock:
3333
dependency: transitive
3434
description:
@@ -87,7 +87,7 @@ packages:
8787
path: ".."
8888
relative: true
8989
source: path
90-
version: "0.8.0+1"
90+
version: "1.0.1"
9191
intl:
9292
dependency: transitive
9393
description:
@@ -101,14 +101,21 @@ packages:
101101
name: matcher
102102
url: "https://pub.dartlang.org"
103103
source: hosted
104-
version: "0.12.10"
104+
version: "0.12.11"
105+
material_color_utilities:
106+
dependency: transitive
107+
description:
108+
name: material_color_utilities
109+
url: "https://pub.dartlang.org"
110+
source: hosted
111+
version: "0.1.3"
105112
meta:
106113
dependency: transitive
107114
description:
108115
name: meta
109116
url: "https://pub.dartlang.org"
110117
source: hosted
111-
version: "1.3.0"
118+
version: "1.7.0"
112119
path:
113120
dependency: transitive
114121
description:
@@ -218,7 +225,7 @@ packages:
218225
name: test_api
219226
url: "https://pub.dartlang.org"
220227
source: hosted
221-
version: "0.3.0"
228+
version: "0.4.8"
222229
typed_data:
223230
dependency: transitive
224231
description:
@@ -232,7 +239,7 @@ packages:
232239
name: vector_math
233240
url: "https://pub.dartlang.org"
234241
source: hosted
235-
version: "2.1.0"
242+
version: "2.1.1"
236243
win32:
237244
dependency: transitive
238245
description:
@@ -248,5 +255,5 @@ packages:
248255
source: hosted
249256
version: "0.1.0"
250257
sdks:
251-
dart: ">=2.12.0 <3.0.0"
258+
dart: ">=2.14.0 <3.0.0"
252259
flutter: ">=1.12.13+hotfix.5"

lib/src/model/icalendar.dart

Lines changed: 82 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import 'dart:convert';
22

33
import 'package:icalendar_parser/icalendar_parser.dart';
4-
import 'package:icalendar_parser/src/exceptions/icalendar_exception.dart';
5-
import 'package:icalendar_parser/src/model/ics_datetime.dart';
64
import 'package:icalendar_parser/src/utils/parsing_methods.dart';
75

86
/// Core object
@@ -67,17 +65,26 @@ class ICalendar {
6765

6866
/// Map containing the methods used to parse each kind of fields in the file.
6967
static final Map<String, Function> _objects = {
70-
'BEGIN': (String value, Map<String, String> params, List events,
71-
Map<String, dynamic> lastEvent) {
68+
'BEGIN': (
69+
String value,
70+
Map<String, String> params,
71+
List events,
72+
Map<String, dynamic> lastEvent,
73+
) {
7274
if (value == 'VCALENDAR') return null;
7375

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

7779
return lastEvent;
7880
},
79-
'END': (String value, Map<String, String> params, List events,
80-
Map<String, dynamic>? lastEvent, List<Map<String, dynamic>?> data) {
81+
'END': (
82+
String value,
83+
Map<String, String> params,
84+
List events,
85+
Map<String, dynamic>? lastEvent,
86+
List<Map<String, dynamic>?> data,
87+
) {
8188
if (value == 'VCALENDAR') return lastEvent;
8289

8390
data.add(lastEvent);
@@ -104,8 +111,12 @@ class ICalendar {
104111
'DESCRIPTION': generateSimpleParamFunction('description'),
105112
'LOCATION': generateSimpleParamFunction('location'),
106113
'URL': generateSimpleParamFunction('url'),
107-
'ORGANIZER': (String value, Map<String, String> params, List events,
108-
Map<String, dynamic> lastEvent) {
114+
'ORGANIZER': (
115+
String value,
116+
Map<String, String> params,
117+
List events,
118+
Map<String, dynamic> lastEvent,
119+
) {
109120
final mail = value.replaceAll('MAILTO:', '').trim();
110121

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

120131
return lastEvent;
121132
},
122-
'GEO': (String value, Map<String, String> params, List events,
123-
Map<String, dynamic> lastEvent) {
133+
'GEO': (
134+
String value,
135+
Map<String, String> params,
136+
List events,
137+
Map<String, dynamic> lastEvent,
138+
) {
124139
final pos = value.split(';');
125140
if (pos.length != 2) return lastEvent;
126141

127-
lastEvent['geo'] = {};
128-
lastEvent['geo']['latitude'] = num.parse(pos[0]);
129-
lastEvent['geo']['longitude'] = num.parse(pos[1]);
142+
final geo = <String, dynamic>{};
143+
geo['latitude'] = num.parse(pos[0]);
144+
geo['longitude'] = num.parse(pos[1]);
145+
lastEvent['geo'] = geo;
130146
return lastEvent;
131147
},
132-
'CATEGORIES': (String value, Map<String, String> params, List events,
133-
Map<String, dynamic> lastEvent) {
148+
'CATEGORIES': (
149+
String value,
150+
Map<String, String> params,
151+
List events,
152+
Map<String, dynamic> lastEvent,
153+
) {
134154
lastEvent['categories'] = value.split(',');
135155
return lastEvent;
136156
},
137-
'ATTENDEE': (String value, Map<String, String> params, List _,
138-
Map<String, dynamic> lastEvent) {
157+
'ATTENDEE': (
158+
String value,
159+
Map<String, String> params,
160+
_,
161+
Map<String, dynamic> lastEvent,
162+
) {
139163
lastEvent['attendee'] ??= [];
140164

141165
final mail = value.replaceAll('MAILTO:', '').trim();
@@ -153,16 +177,14 @@ class ICalendar {
153177
return lastEvent;
154178
},
155179
'ACTION': generateSimpleParamFunction('action'),
156-
'STATUS': (String value, Map<String, String> _, List __,
157-
Map<String, dynamic> lastEvent) {
180+
'STATUS': (String value, _, __, Map<String, dynamic> lastEvent) {
158181
lastEvent['status'] = value.trim().toIcsStatus();
159182
return lastEvent;
160183
},
161184
'SEQUENCE': generateSimpleParamFunction('sequence'),
162185
'REPEAT': generateSimpleParamFunction('repeat'),
163186
'CLASS': generateSimpleParamFunction('class'),
164-
'TRANSP': (String value, Map<String, String> _, List __,
165-
Map<String, dynamic> lastEvent) {
187+
'TRANSP': (String value, _, __, Map<String, dynamic> lastEvent) {
166188
lastEvent['transp'] = value.trim().toIcsTransp();
167189
return lastEvent;
168190
},
@@ -185,8 +207,12 @@ class ICalendar {
185207
/// `ICalendarFormatException`.
186208
static void registerField({
187209
required String field,
188-
Function(String value, Map<String, String> params, List event,
189-
Map<String, dynamic> lastEvent)?
210+
Function(
211+
String value,
212+
Map<String, String> params,
213+
List event,
214+
Map<String, dynamic> lastEvent,
215+
)?
190216
function,
191217
}) {
192218
if (_objects.containsKey(field)) {
@@ -215,8 +241,10 @@ class ICalendar {
215241
/// `List<Map<String, dynamic>> data`.
216242
///
217243
/// If [allowEmptyLine] is false the method will throw [EmptyLineException].
218-
static List<dynamic> fromListToJson(List<String> lines,
219-
{bool allowEmptyLine = true}) {
244+
static List<dynamic> fromListToJson(
245+
List<String> lines, {
246+
bool allowEmptyLine = true,
247+
}) {
220248
final data = <Map<String, dynamic>>[];
221249
final _headData = <String, dynamic>{};
222250
final events = [];
@@ -226,13 +254,15 @@ class ICalendar {
226254
// Ensure first line is BEGIN:VCALENDAR
227255
if (lines.first.trim() != 'BEGIN:VCALENDAR') {
228256
throw ICalendarBeginException(
229-
'The first line must be BEGIN:VCALENDAR but was ${lines.first}.');
257+
'The first line must be BEGIN:VCALENDAR but was ${lines.first}.',
258+
);
230259
}
231260

232261
// Ensure last line is END:VCALENDAR
233262
if (lines.last.trim() != 'END:VCALENDAR') {
234263
throw ICalendarEndException(
235-
'The last line must be END:VCALENDAR but was ${lines.last}.');
264+
'The last line must be END:VCALENDAR but was ${lines.last}.',
265+
);
236266
}
237267

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

245-
final exp = RegExp(r'^ ');
275+
final exp = RegExp('^ ');
246276
while (i + 1 < lines.length && exp.hasMatch(lines[i + 1])) {
247277
i += 1;
248278
line.write(lines[i].trim());
@@ -254,7 +284,9 @@ class ICalendar {
254284
dataLine[0].toUpperCase() != dataLine[0] &&
255285
!dataLine[0].contains(';'))) {
256286
if (line.isNotEmpty && currentName != null) {
257-
lastEvent![currentName] += line.toString();
287+
final buffer = StringBuffer(lastEvent![currentName] as String);
288+
buffer.write(line.toString());
289+
lastEvent[currentName] = buffer.toString();
258290
}
259291
continue;
260292
}
@@ -271,25 +303,38 @@ class ICalendar {
271303

272304
dataLine.removeRange(0, 1);
273305
final value = dataLine.join(':').replaceAll(RegExp(r'\\,'), ',');
274-
if (_objects.containsKey(name)) {
306+
final nameFunc = _objects[name];
307+
if (_objects.containsKey(name) && nameFunc != null) {
275308
currentName = name.toLowerCase();
276309
if (name == 'END') {
310+
final func = nameFunc as Map<String, dynamic>? Function(
311+
String,
312+
Map<String, String>,
313+
List,
314+
Map<String, dynamic>?,
315+
List<Map<String, dynamic>>,
316+
);
277317
currentName = null;
278-
lastEvent = _objects[name]!(value, params, events, lastEvent, data)
279-
as Map<String, dynamic>?;
318+
lastEvent = func(value, params, events, lastEvent, data);
280319
} else {
281-
lastEvent =
282-
_objects[name]!(value, params, events, lastEvent ?? _headData)
283-
as Map<String, dynamic>?;
320+
final func = nameFunc as Map<String, dynamic>? Function(
321+
String,
322+
Map<String, String>,
323+
List,
324+
Map<String, dynamic>,
325+
);
326+
lastEvent = func(value, params, events, lastEvent ?? _headData);
284327
}
285328
}
286329
}
287330
if (!_headData.containsKey('version')) {
288331
throw const ICalendarNoVersionException(
289-
'The body is missing the property VERSION');
332+
'The body is missing the property VERSION',
333+
);
290334
} else if (!_headData.containsKey('prodid')) {
291335
throw const ICalendarNoProdidException(
292-
'The body is missing the property PRODID');
336+
'The body is missing the property PRODID',
337+
);
293338
}
294339
return [_headData, data];
295340
}

0 commit comments

Comments
 (0)