From c91061498ca9137c0bb2e65765ab15c1439941fd Mon Sep 17 00:00:00 2001 From: George Abbott Date: Mon, 9 Oct 2023 18:11:41 +0100 Subject: Another commit with some more progress --- source/sort.d | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 source/sort.d (limited to 'source/sort.d') 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); + } +} + + + -- cgit v1.2.1