+static void
+translate_compile_error (gint *errcode, const gchar **errmsg)
+{
+ /* Compile errors are created adding 100 to the error code returned
+ * by PCRE.
+ * If errcode is known we put the translatable error message in
+ * erromsg. If errcode is unknown we put the generic
+ * G_REGEX_ERROR_COMPILE error code in errcode and keep the
+ * untranslated error message returned by PCRE.
+ * Note that there can be more PCRE errors with the same GRegexError
+ * and that some PCRE errors are useless for us.
+ */
+ *errcode += 100;
+
+ switch (*errcode)
+ {
+ case G_REGEX_ERROR_STRAY_BACKSLASH:
+ *errmsg = _("\\ at end of pattern");
+ break;
+ case G_REGEX_ERROR_MISSING_CONTROL_CHAR:
+ *errmsg = _("\\c at end of pattern");
+ break;
+ case G_REGEX_ERROR_UNRECOGNIZED_ESCAPE:
+ *errmsg = _("unrecognized character following \\");
+ break;
+ case G_REGEX_ERROR_QUANTIFIERS_OUT_OF_ORDER:
+ *errmsg = _("numbers out of order in {} quantifier");
+ break;
+ case G_REGEX_ERROR_QUANTIFIER_TOO_BIG:
+ *errmsg = _("number too big in {} quantifier");
+ break;
+ case G_REGEX_ERROR_UNTERMINATED_CHARACTER_CLASS:
+ *errmsg = _("missing terminating ] for character class");
+ break;
+ case G_REGEX_ERROR_INVALID_ESCAPE_IN_CHARACTER_CLASS:
+ *errmsg = _("invalid escape sequence in character class");
+ break;
+ case G_REGEX_ERROR_RANGE_OUT_OF_ORDER:
+ *errmsg = _("range out of order in character class");
+ break;
+ case G_REGEX_ERROR_NOTHING_TO_REPEAT:
+ *errmsg = _("nothing to repeat");
+ break;
+ case 111: /* internal error: unexpected repeat */
+ *errcode = G_REGEX_ERROR_INTERNAL;
+ *errmsg = _("unexpected repeat");
+ break;
+ case G_REGEX_ERROR_UNRECOGNIZED_CHARACTER:
+ *errmsg = _("unrecognized character after (? or (?-");
+ break;
+ case G_REGEX_ERROR_POSIX_NAMED_CLASS_OUTSIDE_CLASS:
+ *errmsg = _("POSIX named classes are supported only within a class");
+ break;
+ case G_REGEX_ERROR_UNMATCHED_PARENTHESIS:
+ *errmsg = _("missing terminating )");
+ break;
+ case G_REGEX_ERROR_INEXISTENT_SUBPATTERN_REFERENCE:
+ *errmsg = _("reference to non-existent subpattern");
+ break;
+ case G_REGEX_ERROR_UNTERMINATED_COMMENT:
+ *errmsg = _("missing ) after comment");
+ break;
+ case G_REGEX_ERROR_EXPRESSION_TOO_LARGE:
+ *errmsg = _("regular expression is too large");
+ break;
+ case G_REGEX_ERROR_MEMORY_ERROR:
+ *errmsg = _("failed to get memory");
+ break;
+ case 122: /* unmatched parentheses */
+ *errcode = G_REGEX_ERROR_UNMATCHED_PARENTHESIS;
+ *errmsg = _(") without opening (");
+ break;
+ case 123: /* internal error: code overflow */
+ *errcode = G_REGEX_ERROR_INTERNAL;
+ *errmsg = _("code overflow");
+ break;
+ case 124: /* "unrecognized character after (?<\0 */
+ *errcode = G_REGEX_ERROR_UNRECOGNIZED_CHARACTER;
+ *errmsg = _("unrecognized character after (?<");
+ break;
+ case G_REGEX_ERROR_VARIABLE_LENGTH_LOOKBEHIND:
+ *errmsg = _("lookbehind assertion is not fixed length");
+ break;
+ case G_REGEX_ERROR_MALFORMED_CONDITION:
+ *errmsg = _("malformed number or name after (?(");
+ break;
+ case G_REGEX_ERROR_TOO_MANY_CONDITIONAL_BRANCHES:
+ *errmsg = _("conditional group contains more than two branches");
+ break;
+ case G_REGEX_ERROR_ASSERTION_EXPECTED:
+ *errmsg = _("assertion expected after (?(");
+ break;
+ case 129:
+ *errcode = G_REGEX_ERROR_UNMATCHED_PARENTHESIS;
+ /* translators: '(?R' and '(?[+-]digits' are both meant as (groups of)
+ * sequences here, '(?-54' would be an example for the second group.
+ */
+ *errmsg = _("(?R or (?[+-]digits must be followed by )");
+ break;
+ case G_REGEX_ERROR_UNKNOWN_POSIX_CLASS_NAME:
+ *errmsg = _("unknown POSIX class name");
+ break;
+ case G_REGEX_ERROR_POSIX_COLLATING_ELEMENTS_NOT_SUPPORTED:
+ *errmsg = _("POSIX collating elements are not supported");
+ break;
+ case G_REGEX_ERROR_HEX_CODE_TOO_LARGE:
+ *errmsg = _("character value in \\x{...} sequence is too large");
+ break;
+ case G_REGEX_ERROR_INVALID_CONDITION:
+ *errmsg = _("invalid condition (?(0)");
+ break;
+ case G_REGEX_ERROR_SINGLE_BYTE_MATCH_IN_LOOKBEHIND:
+ *errmsg = _("\\C not allowed in lookbehind assertion");
+ break;
+ case 137: /* PCRE does not support \\L, \\l, \\N{name}, \\U, or \\u\0 */
+ /* A number of Perl escapes are not handled by PCRE.
+ * Therefore it explicitly raises ERR37.
+ */
+ *errcode = G_REGEX_ERROR_UNRECOGNIZED_ESCAPE;
+ *errmsg = _("escapes \\L, \\l, \\N{name}, \\U, and \\u are not supported");
+ break;
+ case G_REGEX_ERROR_INFINITE_LOOP:
+ *errmsg = _("recursive call could loop indefinitely");
+ break;
+ case 141: /* unrecognized character after (?P\0 */
+ *errcode = G_REGEX_ERROR_UNRECOGNIZED_CHARACTER;
+ *errmsg = _("unrecognized character after (?P");
+ break;
+ case G_REGEX_ERROR_MISSING_SUBPATTERN_NAME_TERMINATOR:
+ *errmsg = _("missing terminator in subpattern name");
+ break;
+ case G_REGEX_ERROR_DUPLICATE_SUBPATTERN_NAME:
+ *errmsg = _("two named subpatterns have the same name");
+ break;
+ case G_REGEX_ERROR_MALFORMED_PROPERTY:
+ *errmsg = _("malformed \\P or \\p sequence");
+ break;
+ case G_REGEX_ERROR_UNKNOWN_PROPERTY:
+ *errmsg = _("unknown property name after \\P or \\p");
+ break;
+ case G_REGEX_ERROR_SUBPATTERN_NAME_TOO_LONG:
+ *errmsg = _("subpattern name is too long (maximum 32 characters)");
+ break;
+ case G_REGEX_ERROR_TOO_MANY_SUBPATTERNS:
+ *errmsg = _("too many named subpatterns (maximum 10,000)");
+ break;
+ case G_REGEX_ERROR_INVALID_OCTAL_VALUE:
+ *errmsg = _("octal value is greater than \\377");
+ break;
+ case 152: /* internal error: overran compiling workspace */
+ *errcode = G_REGEX_ERROR_INTERNAL;
+ *errmsg = _("overran compiling workspace");
+ break;
+ case 153: /* internal error: previously-checked referenced subpattern not found */
+ *errcode = G_REGEX_ERROR_INTERNAL;
+ *errmsg = _("previously-checked referenced subpattern not found");
+ break;
+ case G_REGEX_ERROR_TOO_MANY_BRANCHES_IN_DEFINE:
+ *errmsg = _("DEFINE group contains more than one branch");
+ break;
+ case G_REGEX_ERROR_INCONSISTENT_NEWLINE_OPTIONS:
+ *errmsg = _("inconsistent NEWLINE options");
+ break;
+ case G_REGEX_ERROR_MISSING_BACK_REFERENCE:
+ *errmsg = _("\\g is not followed by a braced, angle-bracketed, or quoted name or "
+ "number, or by a plain number");
+ break;
+ case G_REGEX_ERROR_INVALID_RELATIVE_REFERENCE:
+ *errmsg = _("a numbered reference must not be zero");
+ break;
+ case G_REGEX_ERROR_BACKTRACKING_CONTROL_VERB_ARGUMENT_FORBIDDEN:
+ *errmsg = _("an argument is not allowed for (*ACCEPT), (*FAIL), or (*COMMIT)");
+ break;
+ case G_REGEX_ERROR_UNKNOWN_BACKTRACKING_CONTROL_VERB:
+ *errmsg = _("(*VERB) not recognized");
+ break;
+ case G_REGEX_ERROR_NUMBER_TOO_BIG:
+ *errmsg = _("number is too big");
+ break;
+ case G_REGEX_ERROR_MISSING_SUBPATTERN_NAME:
+ *errmsg = _("missing subpattern name after (?&");
+ break;
+ case G_REGEX_ERROR_MISSING_DIGIT:
+ *errmsg = _("digit expected after (?+");
+ break;
+ case G_REGEX_ERROR_INVALID_DATA_CHARACTER:
+ *errmsg = _("] is an invalid data character in JavaScript compatibility mode");
+ break;
+ case G_REGEX_ERROR_EXTRA_SUBPATTERN_NAME:
+ *errmsg = _("different names for subpatterns of the same number are not allowed");
+ break;
+ case G_REGEX_ERROR_BACKTRACKING_CONTROL_VERB_ARGUMENT_REQUIRED:
+ *errmsg = _("(*MARK) must have an argument");
+ break;
+ case G_REGEX_ERROR_INVALID_CONTROL_CHAR:
+ *errmsg = _( "\\c must be followed by an ASCII character");
+ break;
+ case G_REGEX_ERROR_MISSING_NAME:
+ *errmsg = _("\\k is not followed by a braced, angle-bracketed, or quoted name");
+ break;
+ case G_REGEX_ERROR_NOT_SUPPORTED_IN_CLASS:
+ *errmsg = _("\\N is not supported in a class");
+ break;
+ case G_REGEX_ERROR_TOO_MANY_FORWARD_REFERENCES:
+ *errmsg = _("too many forward references");
+ break;
+ case G_REGEX_ERROR_NAME_TOO_LONG:
+ *errmsg = _("name is too long in (*MARK), (*PRUNE), (*SKIP), or (*THEN)");
+ break;
+ case G_REGEX_ERROR_CHARACTER_VALUE_TOO_LARGE:
+ *errmsg = _("character value in \\u.... sequence is too large");
+ break;
+
+ case 116: /* erroffset passed as NULL */
+ /* This should not happen as we never pass a NULL erroffset */
+ g_warning ("erroffset passed as NULL");
+ *errcode = G_REGEX_ERROR_COMPILE;
+ break;
+ case 117: /* unknown option bit(s) set */
+ /* This should not happen as we check options before passing them
+ * to pcre_compile2() */
+ g_warning ("unknown option bit(s) set");
+ *errcode = G_REGEX_ERROR_COMPILE;
+ break;
+ case 132: /* this version of PCRE is compiled without UTF support */
+ case 144: /* invalid UTF-8 string */
+ case 145: /* support for \\P, \\p, and \\X has not been compiled */
+ case 167: /* this version of PCRE is not compiled with Unicode property support */
+ case 173: /* disallowed Unicode code point (>= 0xd800 && <= 0xdfff) */
+ case 174: /* invalid UTF-16 string */
+ /* These errors should not happen as we are using an UTF-8 and UCP-enabled PCRE
+ * and we do not check if strings are valid */
+ case 170: /* internal error: unknown opcode in find_fixedlength() */
+ *errcode = G_REGEX_ERROR_INTERNAL;
+ break;
+
+ default:
+ *errcode = G_REGEX_ERROR_COMPILE;
+ }
+}