-
Notifications
You must be signed in to change notification settings - Fork 342
/
mythsorthelper.h
85 lines (69 loc) · 2.62 KB
/
mythsorthelper.h
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// -*- Mode: c++ -*-
// vim: set expandtab tabstop=4 shiftwidth=4
#ifndef MYTHSORTHELPER_H_
#define MYTHSORTHELPER_H_
#include <QCoreApplication>
#include <QRegularExpression>
#include <memory>
#include "mythbaseexp.h"
enum SortPrefixMode
{
SortPrefixKeep,
SortPrefixRemove,
SortPrefixToEnd,
};
enum SortExclusionMode
{
SortExclusionMatch,
SortExclusionPrefix,
};
/**
* A class to consolidate all the soring functions.
*/
class MBASE_PUBLIC MythSortHelper
{
Q_DECLARE_TR_FUNCTIONS(MythSortHelper)
public:
MythSortHelper();
explicit MythSortHelper(MythSortHelper *other);
MythSortHelper(Qt::CaseSensitivity case_sensitve, SortPrefixMode prefix_mode,
const QString &exclusions);
QString doTitle(const QString& title) const;
QString doPathname(const QString& filename) const;
/**
* \brief Does the language translation specify any prefixes.
*
* Returns true if there are prefixes defined. False if there are no
* prefixes specified.
*/
bool hasPrefixes(void) { return not m_prefixes.isEmpty(); }
private:
void MythSortHelperCommon(void);
/// Whether sorting two strings should ignore upper/lower case.
Qt::CaseSensitivity m_case_sensitive {Qt::CaseInsensitive};
/// Whether or not to ignore prefix words (like A, An, and The)
/// when sorting two strings.
SortPrefixMode m_prefix_mode {SortPrefixRemove};
/// A string containing the regular expression of prefixes to
/// ignore when sorting. The code will ensure that this is
/// anchored to the start of the string.
QString m_prefixes {QString()};
/// A regular expression used for removing a leading prefix. It
/// is created from m_prefixes.
QRegularExpression m_prefixes_regex {QRegularExpression()};
/// A regular expression used for moving leading prefix to the end
/// of a string. It is created from m_prefixes.
QRegularExpression m_prefixes_regex2 {QRegularExpression()};
/// A string containing names that should be ignored when greating
/// the sortable form of a title. Multiple titles should be
/// separated by a semicolon. This provides a place to specify
/// things like the show named "A to Z" should not have the prefix
/// "A " sorted to the end of the name.
QString m_exclusions {"A to Z"};
/// The m_exclusion string converted into a string list.
QStringList m_excl_list {QStringList()};
SortExclusionMode m_excl_mode {SortExclusionMatch};
};
MBASE_PUBLIC std::shared_ptr<MythSortHelper> getMythSortHelper(void);
MBASE_PUBLIC void resetMythSortHelper(void);
#endif // MYTHSORTHELPER_H_