CLI interface to medialist (fossil mirror)
Revision | 3fb62f9551515dd48e211ddbeb3fb5bb36130198 (tree) |
---|---|
Time | 2023-02-11 13:46:12 |
Author | mio <stigma@disr...> |
Commiter | mio |
MediaList (library) v0.2.0
More of a fix where the ml_fetch_all function would call
std.string.strip on the mTSV line before splitting on a TAB, this
resulted in a RangeError being thrown if the number of "sections" didn't
match the number of "headers", even though they actually did in the .tsv
file.
NOTE: This still will through if there is a genuine mismatch between the number of headers or the number of fields in the file.
FossilOrigin-Name: 6a0938bdd1c5797799e3309637e6f7d61640b57a1f490a1e7291020bc0a98dfd
@@ -1,5 +1,5 @@ | ||
1 | 1 | /* |
2 | - * Copyright (C) 2022 dawning. | |
2 | + * Copyright (C) 2022, 2023 dawning. | |
3 | 3 | * |
4 | 4 | * This file is part of medialist-cli. |
5 | 5 | * |
@@ -28,6 +28,26 @@ import std.path; | ||
28 | 28 | import std.stdio; |
29 | 29 | import std.string; |
30 | 30 | |
31 | +/** | |
32 | + * Enumeration string containing the verison of MediaList. | |
33 | + * | |
34 | + * Since: 0.2.0 | |
35 | + */ | |
36 | +enum string MediaListVersion = "0.2.0"; | |
37 | + | |
38 | +/** | |
39 | + * Enumeration array of int containing the version of MediaList. | |
40 | + * | |
41 | + * Version represents the Major.Minor.Patch. | |
42 | + * | |
43 | + * Major version changes represent the modification or removal of an existing | |
44 | + * API. Patch versions represent compile-time fixes. Minor versions represent | |
45 | + * all other changes. | |
46 | + * | |
47 | + * Since: 0.2.0 | |
48 | + */ | |
49 | +enum int[3] MediaListVersionA = [0, 2, 0]; | |
50 | + | |
31 | 51 | struct MediaList |
32 | 52 | { |
33 | 53 | immutable string filePath; |
@@ -371,6 +391,7 @@ MediaListItem[] ml_fetch_all(MediaList* list, MLError* err = null) | ||
371 | 391 | |
372 | 392 | File listFile = File(list.filePath); |
373 | 393 | list.isOpen = true; |
394 | + scope(exit) list.isOpen = false; | |
374 | 395 | |
375 | 396 | string line; |
376 | 397 | bool pastHeader = false; |
@@ -421,15 +442,19 @@ MediaListItem[] ml_fetch_all(MediaList* list, MLError* err = null) | ||
421 | 442 | continue; |
422 | 443 | } |
423 | 444 | |
424 | - string[] sections = line.strip().split("\t"); | |
445 | + // Separate the split and strip so we don't remove any | |
446 | + // trailing \t which may be used as a placeholder. | |
447 | + string[] sections = line.split("\t"); | |
448 | + sections[$ - 1] = sections[$ - 1].strip; | |
425 | 449 | |
426 | 450 | items ~= MediaListItem(sections[titleIndex], |
427 | - sections[progressIndex], sections[statusIndex], sections[startIndex], | |
428 | - sections[endIndex], sections[lastIndex], true); | |
451 | + sections[progressIndex], | |
452 | + sections[statusIndex], | |
453 | + sections[startIndex], | |
454 | + sections[endIndex], | |
455 | + sections[lastIndex], true); | |
429 | 456 | } |
430 | 457 | |
431 | - list.isOpen = false; | |
432 | - | |
433 | 458 | return items; |
434 | 459 | } |
435 | 460 |