LibreOffice Module vcl (master) 1
PDFiumTools.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 */
10
12
13namespace vcl::pdf
14{
15OUString convertPdfDateToISO8601(std::u16string_view rInput)
16{
17 if (rInput.size() < 6)
18 return {};
19
20 std::u16string_view prefix = rInput.substr(0, 2);
21 if (prefix != u"D:")
22 return {};
23
24 std::u16string_view sYear = rInput.substr(2, 4);
25
26 std::u16string_view sMonth(u"01");
27 if (rInput.size() >= 8)
28 sMonth = rInput.substr(6, 2);
29
30 std::u16string_view sDay(u"01");
31 if (rInput.size() >= 10)
32 sDay = rInput.substr(8, 2);
33
34 std::u16string_view sHours(u"00");
35 if (rInput.size() >= 12)
36 sHours = rInput.substr(10, 2);
37
38 std::u16string_view sMinutes(u"00");
39 if (rInput.size() >= 14)
40 sMinutes = rInput.substr(12, 2);
41
42 std::u16string_view sSeconds(u"00");
43 if (rInput.size() >= 16)
44 sSeconds = rInput.substr(14, 2);
45
46 OUString sTimeZoneMark("Z");
47 if (rInput.size() >= 17)
48 sTimeZoneMark = rInput.substr(16, 1);
49
50 std::u16string_view sTimeZoneHours(u"00");
51 std::u16string_view sTimeZoneMinutes(u"00");
52 if ((sTimeZoneMark == "+" || sTimeZoneMark == "-") && rInput.size() >= 22)
53 {
54 std::u16string_view sTimeZoneSeparator = rInput.substr(19, 1);
55 if (sTimeZoneSeparator == u"'")
56 {
57 sTimeZoneHours = rInput.substr(17, 2);
58 sTimeZoneMinutes = rInput.substr(20, 2);
59 }
60 }
61
62 OUString sTimeZoneString;
63 if (sTimeZoneMark == "+" || sTimeZoneString == "-")
64 sTimeZoneString = sTimeZoneMark + sTimeZoneHours + ":" + sTimeZoneMinutes;
65 else if (sTimeZoneMark == "Z")
66 sTimeZoneString = sTimeZoneMark;
67
68 return OUString::Concat(sYear) + "-" + sMonth + "-" + sDay + "T" + sHours + ":" + sMinutes + ":"
69 + sSeconds + sTimeZoneString;
70}
71} // end vcl::pdf
72
73/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
float u
OUString convertPdfDateToISO8601(std::u16string_view rInput)
Definition: PDFiumTools.cxx:15