1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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);
}
}
|