Debian Codegraph @

libqnapi/src/subconvert/subtitleformat.cpp

raw symbols SCIP
1 /*****************************************************************************
2 ** QNapi
3 ** Copyright (C) 2008-2017 Piotr KrzemiƄski <[email protected]>
4 **
5 ** This program is free software; you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation; either version 2 of the License, or
8 ** (at your option) any later version.
9 **
10 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
11 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
12 **
13 *****************************************************************************/
14
15 #include "subtitleformat.h"cxx . . $ `<file>/libqnapi/src/subconvert/subtitleformat.h`/
16 #include <QMap>
17
18 QVectorcxx . . $ QVector#<SubTokencxx . . $ SubToken#> SubtitleFormatcxx . . $ SubtitleFormat#::decodeTokenStreamcxx . . $ SubtitleFormat#decodeTokenStream(8709a708f98d071b).(QStringcxx . . $ QString# tokenStream) const {
19 QVectorcxx . . $ QVector#<SubTokencxx . . $ SubToken#> tokenscxx . . $ QVector#QVector(49f6e7a06ebc5aa8).;
20 SubTokencxx . . $ SubToken# tok;
21
22 QMapcxx . . $ QMap#<QStringcxx . . $ QString#, SubTokenTypecxx . . $ SubTokenType#> tokenTypes = {cxx . . $ QMap#QMap(eb367c5a9e07b320).
23 {"{y:b}", STT_BOLDcxx . . $ STT_BOLD.}, {"{b}", STT_BOLDcxx . . $ STT_BOLD.},
24 {"<b>", STT_BOLDcxx . . $ STT_BOLD.}, {"{y:i}", STT_ITALICcxx . . $ STT_ITALIC.},
25 {"{i}", STT_ITALICcxx . . $ STT_ITALIC.}, {"<i>", STT_ITALICcxx . . $ STT_ITALIC.},
26 {"{y:u}", STT_UNDERLINEcxx . . $ STT_UNDERLINE.}, {"{u}", STT_UNDERLINEcxx . . $ STT_UNDERLINE.},
27 {"<u>", STT_UNDERLINEcxx . . $ STT_UNDERLINE.}, {"{/y:b}", STT_BOLD_ENDcxx . . $ STT_BOLD_END.},
28 {"{/b}", STT_BOLD_ENDcxx . . $ STT_BOLD_END.}, {"</b>", STT_BOLD_ENDcxx . . $ STT_BOLD_END.},
29 {"{/y:i}", STT_ITALIC_ENDcxx . . $ STT_ITALIC_END.}, {"{/i}", STT_ITALIC_ENDcxx . . $ STT_ITALIC_END.},
30 {"</i>", STT_ITALIC_ENDcxx . . $ STT_ITALIC_END.}, {"{/y:u}", STT_UNDERLINE_ENDcxx . . $ STT_UNDERLINE_END.},
31 {"{/u}", STT_UNDERLINE_ENDcxx . . $ STT_UNDERLINE_END.}, {"</u>", STT_UNDERLINE_ENDcxx . . $ STT_UNDERLINE_END.},
32 {"{/c}", STT_FONTCOLOR_ENDcxx . . $ STT_FONTCOLOR_END.}, {"</font>", STT_FONTCOLOR_ENDcxx . . $ STT_FONTCOLOR_END.},
33 {"|", STT_NEWLINEcxx . . $ STT_NEWLINE.}, {"\r\n", STT_NEWLINEcxx . . $ STT_NEWLINE.},
34 {"\n", STT_NEWLINEcxx . . $ STT_NEWLINE.}};
35
36 QStringcxx . . $ QString# wordBuffcxx . . $ QString#QString(49f6e7a06ebc5aa8).;
37
38 while (!tokenStream.isEmptycxx . . $ QString#isEmpty(50ce9a9e25b4a850).()) {
39 tok.payloadcxx . . $ SubToken#payload..clearcxx . . $ QString#clear(49f6e7a06ebc5aa8).();
40
41 bool matched = false;
42
43 foreachcxx . . $ `<external>/15045578679651060896/qglobal.h:1145:13`! (QString token, tokenTypes.keys()) {
44 if (tokenStream.startsWithcxx . . $ QString#startsWith(8cce4688c16f48f3).(token, Qtcxx . . $ Qt/::CaseInsensitivecxx . . $ Qt/CaseInsensitive.)) {
45 tok.typecxx . . $ SubToken#type. = tokenTypes[cxx . . $ QMap#`operator[]`(bbd415b616967878).token];
46 tokenStream.removecxx . . $ QString#remove(6483560ce2afa901).(0, token.sizecxx . . $ QString#size(455f465bc33b4cdf).());
47 matched = true;
48 break;
49 }
50 }
51
52 if (!matched) {
53 QRegExpcxx . . $ QRegExp# colorR1cxx . . $ QRegExp#QRegExp(31e086911ff70bd0).("^\\{c:(.*)\\}"cxx . . $ QString#QString(85c52e162fed56f9).);
54 colorR1.setPatternSyntaxcxx . . $ QRegExp#setPatternSyntax(e2983a6a777435d7).(QRegExpcxx . . $ QRegExp#::RegExp2cxx . . $ QRegExp#RegExp2.);
55 colorR1.setCaseSensitivitycxx . . $ QRegExp#setCaseSensitivity(dbd87adfa24451df).(Qtcxx . . $ Qt/::CaseInsensitivecxx . . $ Qt/CaseInsensitive.);
56
57 QRegExpcxx . . $ QRegExp# colorR2cxx . . $ QRegExp#QRegExp(31e086911ff70bd0).("^<font color=(.*)>"cxx . . $ QString#QString(85c52e162fed56f9).);
58 colorR1.setPatternSyntaxcxx . . $ QRegExp#setPatternSyntax(e2983a6a777435d7).(QRegExpcxx . . $ QRegExp#::RegExp2cxx . . $ QRegExp#RegExp2.);
59 colorR1.setCaseSensitivitycxx . . $ QRegExp#setCaseSensitivity(dbd87adfa24451df).(Qtcxx . . $ Qt/::CaseInsensitivecxx . . $ Qt/CaseInsensitive.);
60
61 if (colorR1.indexIncxx . . $ QRegExp#indexIn(46f502bdfc4aeb33).(tokenStream) == 0) {
62 tok.typecxx . . $ SubToken#type. = STT_FONTCOLORcxx . . $ STT_FONTCOLOR.;
63 tok.payloadcxx . . $ SubToken#payload. =cxx . . $ QString#`operator=`(7b76e6691bca1027). parseColorcxx . . $ SubtitleFormat#parseColor(f6736f2569bd2ccc).(colorR1cxx . . $ QString#QString(e1217c004a86c950)..capcxx . . $ QRegExp#cap(ce915ed341d4a7f0).(1));
64 tokenStream.removecxx . . $ QString#remove(6483560ce2afa901).(0, colorR1.capcxx . . $ QRegExp#cap(ce915ed341d4a7f0).(0).sizecxx . . $ QString#size(455f465bc33b4cdf).());
65 matched = true;
66 } else if (colorR2.indexIncxx . . $ QRegExp#indexIn(46f502bdfc4aeb33).(tokenStream) == 0) {
67 tok.typecxx . . $ SubToken#type. = STT_FONTCOLORcxx . . $ STT_FONTCOLOR.;
68 tok.payloadcxx . . $ SubToken#payload. =cxx . . $ QString#`operator=`(7b76e6691bca1027). parseColorcxx . . $ SubtitleFormat#parseColor(f6736f2569bd2ccc).(colorR2cxx . . $ QString#QString(e1217c004a86c950)..capcxx . . $ QRegExp#cap(ce915ed341d4a7f0).(1));
69 tokenStream.removecxx . . $ QString#remove(6483560ce2afa901).(0, colorR2.capcxx . . $ QRegExp#cap(ce915ed341d4a7f0).(0).sizecxx . . $ QString#size(455f465bc33b4cdf).());
70 matched = true;
71 } else if (tokenStream[cxx . . $ QString#`operator[]`(57436120916eb52c).0] ==cxx . . $ `operator==`(266b2cc48a9d5b67). '/'cxx . . $ QChar#QChar(d4f767463ce0a6b3). && wordBuff.isEmptycxx . . $ QString#isEmpty(50ce9a9e25b4a850).()) {
72 tok.typecxx . . $ SubToken#type. = STT_ITALICcxx . . $ STT_ITALIC.;
73 tokenStream.removecxx . . $ QString#remove(6483560ce2afa901).(0, 1);
74 matched = true;
75 } else if (tokenStream[cxx . . $ QString#`operator[]`(57436120916eb52c).0].isSpacecxx . . $ QCharRef#isSpace(50ce9a9e25b4a850).()) {
76 while (!tokenStream.isEmptycxx . . $ QString#isEmpty(50ce9a9e25b4a850).() && tokenStream[cxx . . $ QString#`operator[]`(57436120916eb52c).0].isSpacecxx . . $ QCharRef#isSpace(50ce9a9e25b4a850).())
77 tokenStream.removecxx . . $ QString#remove(6483560ce2afa901).(0, 1);
78 tok.typecxx . . $ SubToken#type. = STT_WScxx . . $ STT_WS.;
79 matched = true;
80 } else {
81 wordBuff +=cxx . . $ QString#`operator+=`(3a2ffbdf8ecc25e2). tokenStream[cxx . . $ QString#`operator[]`(57436120916eb52c).0];
82 tokenStream.removecxx . . $ QString#remove(6483560ce2afa901).(0, 1);
83 }
84 }
85
86 if (matched) {
87 if (!wordBuff.isEmptycxx . . $ QString#isEmpty(50ce9a9e25b4a850).()) {
88 SubTokencxx . . $ SubToken# wordTok;
89 wordTok.typecxx . . $ SubToken#type. = STT_WORDcxx . . $ STT_WORD.;
90 wordTok.payloadcxx . . $ SubToken#payload. =cxx . . $ QString#`operator=`(6a89d0b7f4d2681c). wordBuff;
91 tokens.push_backcxx . . $ QVector#push_back(77d9f17553126ecb).(wordTok);
92 wordBuff.clearcxx . . $ QString#clear(49f6e7a06ebc5aa8).();
93 }
94 tokens.push_backcxx . . $ QVector#push_back(77d9f17553126ecb).(tok);
95 }
96 }
97
98 if (!wordBuff.isEmptycxx . . $ QString#isEmpty(50ce9a9e25b4a850).()) {
99 SubTokencxx . . $ SubToken# wordTok;
100 wordTok.typecxx . . $ SubToken#type. = STT_WORDcxx . . $ STT_WORD.;
101 wordTok.payloadcxx . . $ SubToken#payload. =cxx . . $ QString#`operator=`(6a89d0b7f4d2681c). wordBuff;
102 tokens.push_backcxx . . $ QVector#push_back(77d9f17553126ecb).(wordTok);
103 }
104
105 if (!tokens.isEmptycxx . . $ QVector#isEmpty(50ce9a9e25b4a850).() && tokens[cxx . . $ QVector#`operator[]`(7a0ef1c7079e8533).0].typecxx . . $ SubToken#type. == STT_WScxx . . $ STT_WS.) {
106 while (tokens[cxx . . $ QVector#`operator[]`(7a0ef1c7079e8533).0].typecxx . . $ SubToken#type. == STT_WScxx . . $ STT_WS.) tokens.pop_frontcxx . . $ QVector#pop_front(49f6e7a06ebc5aa8).();
107 }
108
109 return tokenscxx . . $ QVector#QVector(aa2185ac2a214c82).;
110 }
111
112 QStringcxx . . $ QString# SubtitleFormatcxx . . $ SubtitleFormat#::parseColorcxx . . $ SubtitleFormat#parseColor(f6736f2569bd2ccc).(QStringcxx . . $ QString# colorString) const {
113 return colorStringcxx . . $ QString#QString(3520e46b33348bf6)..replacecxx . . $ QString#replace(e91996333fe0469b).('"'cxx . . $ QChar#QChar(d4f767463ce0a6b3)., ""cxx . . $ QString#QString(85c52e162fed56f9).).replacecxx . . $ QString#replace(e91996333fe0469b).('#'cxx . . $ QChar#QChar(d4f767463ce0a6b3)., ""cxx . . $ QString#QString(85c52e162fed56f9).).replacecxx . . $ QString#replace(e91996333fe0469b).('$'cxx . . $ QChar#QChar(d4f767463ce0a6b3)., ""cxx . . $ QString#QString(85c52e162fed56f9).);
114 }