1 /************************************************************************
2 **
3 **  Copyright (C) 2021 Kevin B. Hendricks, Stratford, Ontario, Canada
4 **
5 **  This file is part of Sigil.
6 **
7 **  Sigil is free software: you can redistribute it and/or modify
8 **  it under the terms of the GNU General Public License as published by
9 **  the Free Software Foundation, either version 3 of the License, or
10 **  (at your option) any later version.
11 **
12 **  Sigil is distributed in the hope that it will be useful,
13 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 **  GNU General Public License for more details.
16 **
17 **  You should have received a copy of the GNU General Public License
18 **  along with Sigil.  If not, see <http://www.gnu.org/licenses/>.
19 **
20 *************************************************************************/
21 
22 #include <QTranslator>
23 #include <QString>
24 #include <QHash>
25 
26 #include "PCRE/PCREErrors.h"
27 
28 PCREErrors *PCREErrors::m_instance = 0;
29 
instance()30 PCREErrors *PCREErrors::instance()
31 {
32     if (m_instance == 0) {
33         m_instance = new PCREErrors();
34     }
35 
36     return m_instance;
37 }
38 
PCREErrors()39 PCREErrors::PCREErrors()
40 {
41     SetErrorMap();
42 }
43 
44 
GetError(const QString & code,const QString & ow)45 QString PCREErrors::GetError(const QString &code, const QString &ow)
46 {
47     QString emsg = m_XlateError.value(code, ow);
48     return emsg;
49 }
50 
51 
52 
SetErrorMap()53 void PCREErrors::SetErrorMap()
54 {
55     if (!m_XlateError.isEmpty()) {
56         return;
57     }
58 
59     m_XlateError[ "no error" ] = tr(  "no error" );
60     m_XlateError[ "\\ at end of pattern" ] = tr( "\\ at end of pattern" );
61     m_XlateError[ "\\c at end of pattern" ] = tr( "\\c at end of pattern" );
62     m_XlateError[ "unrecognized character follows \\" ] = tr( "unrecognized character follows \\" );
63     m_XlateError[ "numbers out of order in {} quantifier" ] = tr( "numbers out of order in {} quantifier" );
64     m_XlateError[ "number too big in {} quantifier" ] = tr( "number too big in {} quantifier" );
65     m_XlateError[ "missing terminating ] for character class" ] = tr( "missing terminating ] for character class" );
66     m_XlateError[ "invalid escape sequence in character class" ] = tr( "invalid escape sequence in character class" );
67     m_XlateError[ "range out of order in character class" ] = tr( "range out of order in character class" );
68     m_XlateError[ "nothing to repeat" ] = tr( "nothing to repeat" );
69     m_XlateError[ "operand of unlimited repeat could match the empty string" ] = tr( "operand of unlimited repeat could match the empty string" );
70     m_XlateError[ "internal error: unexpected repeat" ] = tr( "internal error: unexpected repeat" );
71     m_XlateError[ "unrecognized character after (? or (?-" ] = tr( "unrecognized character after (? or (?-" );
72     m_XlateError[ "POSIX named classes are supported only within a class" ] = tr( "POSIX named classes are supported only within a class" );
73     m_XlateError[ "missing )" ] = tr( "missing )" );
74     m_XlateError[ "reference to non-existent subpattern" ] = tr( "reference to non-existent subpattern" );
75     m_XlateError[ "erroffset passed as NULL" ] = tr( "erroffset passed as NULL" );
76     m_XlateError[ "unknown option bit(s) set" ] = tr( "unknown option bit(s) set" );
77     m_XlateError[ "missing ) after comment" ] = tr( "missing ) after comment" );
78     m_XlateError[ "parentheses nested too deeply" ] = tr( "parentheses nested too deeply" );
79     m_XlateError[ "regular expression is too large" ] = tr( "regular expression is too large" );
80     m_XlateError[ "failed to get memory" ] = tr( "failed to get memory" );
81     m_XlateError[ "unmatched parentheses" ] = tr( "unmatched parentheses" );
82     m_XlateError[ "internal error: code overflow" ] = tr( "internal error: code overflow" );
83     m_XlateError[ "unrecognized character after (?<" ] = tr( "unrecognized character after (?<" );
84     m_XlateError[ "lookbehind assertion is not fixed length" ] = tr( "lookbehind assertion is not fixed length" );
85     m_XlateError[ "malformed number or name after (?(" ] = tr( "malformed number or name after (?(" );
86     m_XlateError[ "conditional group contains more than two branches" ] = tr( "conditional group contains more than two branches" );
87     m_XlateError[ "assertion expected after (?(" ] = tr( "assertion expected after (?(" );
88     m_XlateError[ "(?R or (?[+-]digits must be followed by )" ] = tr( "(?R or (?[+-]digits must be followed by )" );
89     m_XlateError[ "unknown POSIX class name" ] = tr( "unknown POSIX class name" );
90     m_XlateError[ "POSIX collating elements are not supported" ] = tr( "POSIX collating elements are not supported" );
91     m_XlateError[ "this version of PCRE is compiled without UTF support" ] = tr( "this version of PCRE is compiled without UTF support" );
92     m_XlateError[ "spare error" ] = tr( "spare error" );
93     m_XlateError[ "character value in \\x{} or \\o{} is too large" ] = tr( "character value in \\x{} or \\o{} is too large" );
94     m_XlateError[ "invalid condition (?(0)" ] = tr( "invalid condition (?(0)" );
95     m_XlateError[ "\\C not allowed in lookbehind assertion" ] = tr( "\\C not allowed in lookbehind assertion" );
96     m_XlateError[ "PCRE does not support \\L, \\l, \\N{name}, \\U, or \\u" ] = tr( "PCRE does not support \\L, \\l, \\N{name}, \\U, or \\u" );
97     m_XlateError[ "number after (?C is > 255" ] = tr( "number after (?C is > 255" );
98     m_XlateError[ "closing ) for (?C expected" ] = tr( "closing ) for (?C expected" );
99     m_XlateError[ "recursive call could loop indefinitely" ] = tr( "recursive call could loop indefinitely" );
100     m_XlateError[ "unrecognized character after (?P" ] = tr( "unrecognized character after (?P" );
101     m_XlateError[ "syntax error in subpattern name (missing terminator)" ] = tr( "syntax error in subpattern name (missing terminator)" );
102     m_XlateError[ "two named subpatterns have the same name" ] = tr( "two named subpatterns have the same name" );
103     m_XlateError[ "invalid UTF-8 string" ] = tr( "invalid UTF-8 string" );
104     m_XlateError[ "support for \\P, \\p, and \\X has not been compiled" ] = tr( "support for \\P, \\p, and \\X has not been compiled" );
105     m_XlateError[ "malformed \\P or \\p sequence" ] = tr( "malformed \\P or \\p sequence" );
106     m_XlateError[ "unknown property name after \\P or \\p" ] = tr( "unknown property name after \\P or \\p" );
107     m_XlateError[ "subpattern name is too long (maximum 32 characters)" ] = tr( "subpattern name is too long (maximum 32 characters)" );
108     m_XlateError[ "too many named subpatterns (maximum 10000)" ] = tr( "too many named subpatterns (maximum 10000)" );
109     m_XlateError[ "repeated subpattern is too long" ] = tr( "repeated subpattern is too long" );
110     m_XlateError[ "octal value is greater than \\377 in 8-bit non-UTF-8 mode" ] = tr( "octal value is greater than \\377 in 8-bit non-UTF-8 mode" );
111     m_XlateError[ "internal error: overran compiling workspace" ] = tr( "internal error: overran compiling workspace" );
112     m_XlateError[ "internal error: previously-checked referenced subpattern not found" ] = tr( "internal error: previously-checked referenced subpattern not found" );
113     m_XlateError[ "DEFINE group contains more than one branch" ] = tr( "DEFINE group contains more than one branch" );
114     m_XlateError[ "repeating a DEFINE group is not allowed" ] = tr( "repeating a DEFINE group is not allowed" );
115     m_XlateError[ "inconsistent NEWLINE options" ] = tr( "inconsistent NEWLINE options" );
116     m_XlateError[ "\\g is not followed by a braced, angle-bracketed, or quoted name/number or by a plain number" ] = tr( "\\g is not followed by a braced, angle-bracketed, or quoted name/number or by a plain number" );
117     m_XlateError[ "a numbered reference must not be zero" ] = tr( "a numbered reference must not be zero" );
118     m_XlateError[ "an argument is not allowed for (*ACCEPT), (*FAIL), or (*COMMIT)" ] = tr( "an argument is not allowed for (*ACCEPT), (*FAIL), or (*COMMIT)" );
119     m_XlateError[ "(*VERB) not recognized or malformed" ] = tr( "(*VERB) not recognized or malformed" );
120     m_XlateError[ "number is too big" ] = tr( "number is too big" );
121     m_XlateError[ "subpattern name expected" ] = tr( "subpattern name expected" );
122     m_XlateError[ "digit expected after (?+" ] = tr( "digit expected after (?+" );
123     m_XlateError[ "] is an invalid data character in JavaScript compatibility mode" ] = tr( "] is an invalid data character in JavaScript compatibility mode" );
124     m_XlateError[ "different names for subpatterns of the same number are not allowed" ] = tr( "different names for subpatterns of the same number are not allowed" );
125     m_XlateError[ "(*MARK) must have an argument" ] = tr( "(*MARK) must have an argument" );
126     m_XlateError[ "this version of PCRE is not compiled with Unicode property support" ] = tr( "this version of PCRE is not compiled with Unicode property support" );
127     m_XlateError[ "\\c must be followed by an ASCII character" ] = tr( "\\c must be followed by an ASCII character" );
128     m_XlateError[ "\\k is not followed by a braced, angle-bracketed, or quoted name" ] = tr( "\\k is not followed by a braced, angle-bracketed, or quoted name" );
129     m_XlateError[ "internal error: unknown opcode in find_fixedlength()" ] = tr( "internal error: unknown opcode in find_fixedlength()" );
130     m_XlateError[ "\\N is not supported in a class" ] = tr( "\\N is not supported in a class" );
131     m_XlateError[ "too many forward references" ] = tr( "too many forward references" );
132     m_XlateError[ "disallowed Unicode code point (>= 0xd800 && <= 0xdfff)" ] = tr( "disallowed Unicode code point (>= 0xd800 && <= 0xdfff)" );
133     m_XlateError[ "invalid UTF-16 string" ] = tr( "invalid UTF-16 string" );
134     m_XlateError[ "name is too long in (*MARK), (*PRUNE), (*SKIP), or (*THEN)" ] = tr( "name is too long in (*MARK), (*PRUNE), (*SKIP), or (*THEN)" );
135     m_XlateError[ "character value in \\u.... sequence is too large" ] = tr( "character value in \\u.... sequence is too large" );
136     m_XlateError[ "invalid UTF-32 string" ] = tr( "invalid UTF-32 string" );
137     m_XlateError[ "setting UTF is disabled by the application" ] = tr( "setting UTF is disabled by the application" );
138     m_XlateError[ "non-hex character in \\x{} (closing brace missing?)" ] = tr( "non-hex character in \\x{} (closing brace missing?)" );
139     m_XlateError[ "non-octal character in \\o{} (closing brace missing?)" ] = tr( "non-octal character in \\o{} (closing brace missing?)" );
140     m_XlateError[ "missing opening brace after \\o" ] = tr( "missing opening brace after \\o" );
141     m_XlateError[ "parentheses are too deeply nested" ] = tr( "parentheses are too deeply nested" );
142     m_XlateError[ "invalid range in character class" ] = tr( "invalid range in character class" );
143     m_XlateError[ "group name must start with a non-digit" ] = tr( "group name must start with a non-digit" );
144     m_XlateError[ "parentheses are too deeply nested (stack check)" ] = tr( "parentheses are too deeply nested (stack check)" );
145     m_XlateError[ "digits missing in \\x{} or \\o{}" ] = tr( "digits missing in \\x{} or \\o{}" );
146 }
147