1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date        : 2017-05-06
7  * Description : utilities for digiKam setup
8  *
9  * Copyright (C) 2017      by Simon Frei <freisim93 at gmail dot com>
10  *
11  * This program is free software; you can redistribute it
12  * and/or modify it under the terms of the GNU Album
13  * Public License as published by the Free Software Foundation;
14  * either version 2, or (at your option)
15  * any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU Album Public License for more details.
21  *
22  * ============================================================ */
23 
24 #include "setuputils.h"
25 
26 // Qt includes
27 
28 #include <QStringList>
29 
30 namespace Digikam
31 {
32 
cleanUserFilterString(QString filterString,const bool caseSensitive,const bool useSemicolon)33 QStringList cleanUserFilterString(QString filterString,
34                                   const bool caseSensitive,
35                                   const bool useSemicolon)
36 {
37     if (!caseSensitive)
38     {
39         filterString = filterString.toLower();
40     }
41 
42     QChar separator;
43 
44     if (!useSemicolon)
45     {
46         separator = QLatin1Char(' ');
47         filterString.remove(QLatin1Char('*'));
48         filterString.replace(QLatin1Char(';'), QLatin1Char(' '));
49         filterString.replace(QLatin1String(" ."), QLatin1String(" "));
50         filterString.replace(QLatin1String(" -."), QLatin1String(" -"));
51     }
52     else
53     {
54         separator = QLatin1Char(';');
55         filterString.replace(QLatin1String(";."), QLatin1String(";"));
56         filterString.replace(QLatin1String(";-."), QLatin1String(";-"));
57     }
58 
59     QStringList filterList;
60 
61     foreach (const QString& filter, filterString.split(separator, QString::SkipEmptyParts))
62     {
63         filterList << filter.trimmed();
64     }
65 
66     return filterList;
67 }
68 
69 } // namespace Digikam
70