diff options
Diffstat (limited to 'source/sort.d')
-rw-r--r-- | source/sort.d | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/source/sort.d b/source/sort.d new file mode 100644 index 0000000..9baa667 --- /dev/null +++ b/source/sort.d @@ -0,0 +1,50 @@ +/* For sorting the entries as per the -o flag. + * This allows a list of entries to be sorted, + * e.g. title-alphabetic, date-reverse, date-forward. + */ + +enum SortMode +{ + /* For instance: + * TitleAA, TitleZZ, TitleFF + * becomes + * TitleAA, TitleFF, TitleZZ + */ + TitleAlphabetic; + + /* For instance: + * 2023-10-01, 2023-10-05, 2023-10-03 + * becomes + * 2023-10-05, 2023-10-03, 2023-10-01 + */ + DateReverse; + + /* For instance: + * 2023-10-01, 2023-10-05, 2023-10-03 + * becomes + * 2023-10-01, 2023-10-03, 2023-10-05 + */ + DateForwards; +} + +// TODO: write sorting functions. +Entry[] sort_title_alphabetic(Entry[] entries) { return entries; } +Entry[] sort_date_reverse(Entry[] entries) { return entries; } +Entry[] sort_date_forward(Entry[] entries) { return entries; } + + +Entry[] sort(Entry[] entries, SortMode sort_mode) +{ + switch (sort_mode) + { + case SortMode.TitleAlphabetic: + return sort_title_alphabetic(entries); + case SortMode.DateReverse: + return sort_date_reverse(entries); + case SortMode.DateForward: + return sort_date_forward(entries); + } +} + + + |