"Fossies" - the Fresh Open Source Software Archive 
Member "cb2bib-2.0.1/src/c2b/monthDB.cpp" (12 Feb 2021, 2321 Bytes) of package /linux/privat/cb2bib-2.0.1.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "monthDB.cpp" see the
Fossies "Dox" file reference documentation and the latest
Fossies "Diffs" side-by-side code changes report:
2.0.0_vs_2.0.1.
1 /***************************************************************************
2 * Copyright (C) 2004-2021 by Pere Constans
3 * constans@molspaces.com
4 * cb2Bib version 2.0.1. Licensed under the GNU GPL version 3.
5 * See the LICENSE file that comes with this distribution.
6 ***************************************************************************/
7 #include "monthDB.h"
8
9 #include "settings.h"
10
11
12 monthDB::monthDB()
13 : _day_rx(QRegExp("(\\d+)")),
14 _month_rx(QRegExp("([A-Za-z]+)")),
15 _month_abbreviated(QString("jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec").split('|')),
16 _month_full(
17 QString("January|February|March|April|May|June|July|August|September|October|November|December").split('|')) {}
18
19
20 QString monthDB::retrieve(const QString& month_query)
21 {
22 bool has_month(_month_rx.indexIn(month_query) > -1);
23 if (!has_month)
24 return month_query;
25 const QString month(_month_rx.cap(1));
26 const QString month_abbreviated(abbreviated(month));
27 const QString month_full(full(month));
28 // Early return if month is not recognized
29 if (month_abbreviated == month_full)
30 return month_query;
31 const bool has_day(_day_rx.indexIn(month_query) > -1);
32 if (settings::instance()->value("cb2Bib/PostprocessMonth").toBool())
33 {
34 // Do '1 April' -> '"1~" # apr'
35 if (has_day)
36 return QString("\"%1~\" # %2").arg(_day_rx.cap(1), month_abbreviated);
37 else
38 return month_abbreviated;
39 }
40 else
41 {
42 // Capitalize
43 if (has_day)
44 return QString("%1 %2").arg(_day_rx.cap(1), month_full);
45 else
46 return month_full;
47 }
48 }
49
50 QString monthDB::abbreviated(const QString& month) const
51 {
52 for (int i = 0; i < 12; i++)
53 if (QString::compare(month, _month_abbreviated.at(i), Qt::CaseInsensitive) == 0 ||
54 QString::compare(month, _month_full.at(i), Qt::CaseInsensitive) == 0)
55 return _month_abbreviated.at(i);
56 return month;
57 }
58
59 QString monthDB::full(const QString& month) const
60 {
61 for (int i = 0; i < 12; i++)
62 if (QString::compare(month, _month_abbreviated.at(i), Qt::CaseInsensitive) == 0 ||
63 QString::compare(month, _month_full.at(i), Qt::CaseInsensitive) == 0)
64 return _month_full.at(i);
65 return month;
66 }