comparison src/xlsx/xlsxnumformatparser.cpp @ 1:93d3106bb9a4

Add qt xlsx library
author Andre Heinecke <andre.heinecke@intevation.de>
date Tue, 22 Mar 2016 10:38:08 +0100
parents
children
comparison
equal deleted inserted replaced
0:49cd5cc0b072 1:93d3106bb9a4
1 /****************************************************************************
2 ** Copyright (c) 2013-2014 Debao Zhang <hello@debao.me>
3 ** All right reserved.
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining
6 ** a copy of this software and associated documentation files (the
7 ** "Software"), to deal in the Software without restriction, including
8 ** without limitation the rights to use, copy, modify, merge, publish,
9 ** distribute, sublicense, and/or sell copies of the Software, and to
10 ** permit persons to whom the Software is furnished to do so, subject to
11 ** the following conditions:
12 **
13 ** The above copyright notice and this permission notice shall be
14 ** included in all copies or substantial portions of the Software.
15 **
16 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 ** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 ** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 ** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 ** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 **
24 ****************************************************************************/
25 #include "xlsxnumformatparser_p.h"
26
27 #include <QString>
28
29 namespace QXlsx {
30
31 bool NumFormatParser::isDateTime(const QString &formatCode)
32 {
33 for (int i = 0; i < formatCode.length(); ++i) {
34 const QChar &c = formatCode[i];
35
36 switch (c.unicode()) {
37 case '[':
38 // [h], [m], [s] are valid format for time
39 if (i < formatCode.length()-2 && formatCode[i+2] == QLatin1Char(']')) {
40 const QChar cc = formatCode[i+1].toLower();
41 if (cc == QLatin1Char('h') || cc == QLatin1Char('m') || cc == QLatin1Char('s'))
42 return true;
43 i+=2;
44 break;
45 } else {
46 // condition or color: don't care, ignore
47 while (i < formatCode.length() && formatCode[i] != QLatin1Char(']'))
48 ++i;
49 break;
50 }
51
52 // quoted plain text block: don't care, ignore
53 case '"':
54 while (i < formatCode.length()-1 && formatCode[++i] != QLatin1Char('"'))
55 ;
56 break;
57
58 // escaped char: don't care, ignore
59 case '\\':
60 if (i < formatCode.length() - 1)
61 ++i;
62 break;
63
64 // date/time can only be positive number,
65 // so only the first section of the format make sense.
66 case ';':
67 return false;
68 break;
69
70 // days
71 case 'D':
72 case 'd':
73 // years
74 case 'Y':
75 case 'y':
76 // hours
77 case 'H':
78 case 'h':
79 // seconds
80 case 'S':
81 case 's':
82 // minutes or months, depending on context
83 case 'M':
84 case 'm':
85 return true;
86
87 default:
88 break;
89 }
90 }
91 return false;
92 }
93
94 } // namespace QXlsx
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)