3 * Copyright (C) 2015 by Larry Wall and others
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
9 #ifndef DQUOTE_INLINE_H /* Guard against nested #inclusion */
10 #define DQUOTE_INLINE_H
13 - regcurly - a little FSA that accepts {\d+,?\d*}
16 PERL_STATIC_INLINE I32
17 S_regcurly(const char *s)
19 PERL_ARGS_ASSERT_REGCURLY;
36 PERL_STATIC_INLINE bool
37 S_grok_bslash_x(pTHX_ char **s, UV *uv, const char** error_msg,
38 const bool output_warning, const bool strict,
39 const bool silence_non_portable,
43 /* Documentation to be supplied when interface nailed down finally
44 * This returns FALSE if there is an error which the caller need not recover
45 * from; otherwise TRUE.
46 * It guarantees that the returned codepoint, *uv, when expressed as
47 * utf8 bytes, would fit within the skipped "\x{...}" bytes.
50 * s is the address of a pointer to a NULL terminated string that begins
51 * with 'x', and the previous character was a backslash. At exit, *s
52 * will be advanced to the byte just after those absorbed by this
53 * function. Hence the caller can continue parsing from there. In
54 * the case of an error, this routine has generally positioned *s to
55 * point just to the right of the first bad spot, so that a message
56 * that has a "<--" to mark the spot will be correctly positioned.
57 * uv points to a UV that will hold the output value, valid only if the
58 * return from the function is TRUE
59 * error_msg is a pointer that will be set to an internal buffer giving an
60 * error message upon failure (the return is FALSE). Untouched if
62 * output_warning says whether to output any warning messages, or suppress
64 * strict is true if anything out of the ordinary should cause this to
65 * fail instead of warn or be silent. For example, it requires
66 * exactly 2 digits following the \x (when there are no braces).
67 * 3 digits could be a mistake, so is forbidden in this mode.
68 * silence_non_portable is true if to suppress warnings about the code
69 * point returned being too large to fit on all platforms.
70 * UTF is true iff the string *s is encoded in UTF-8.
74 I32 flags = PERL_SCAN_DISALLOW_PREFIX;
77 assert(*start == '\\');
80 PERL_ARGS_ASSERT_GROK_BSLASH_X;
85 if (strict || ! output_warning) {
86 flags |= PERL_SCAN_SILENT_ILLDIGIT;
90 STRLEN len = (strict) ? 3 : 2;
92 *uv = grok_hex(*s, &len, &flags, NULL);
94 if (strict && len != 2) {
96 *s += (UTF) ? UTF8SKIP(*s) : 1;
97 *error_msg = "Non-hex character";
100 *error_msg = "Use \\x{...} for more than two hex characters";
109 (*s)++; /* Move past the '{' */
110 while (isXDIGIT(**s)) { /* Position beyond the legal digits */
113 /* XXX The corresponding message above for \o is just '\\o{'; other
114 * messages for other constructs include the '}', so are inconsistent.
116 *error_msg = "Missing right brace on \\x{}";
120 (*s)++; /* Point to expected first digit (could be first byte of utf8
121 sequence if not a digit) */
122 numbers_len = e - *s;
123 if (numbers_len == 0) {
125 (*s)++; /* Move past the } */
126 *error_msg = "Number with no digits";
134 flags |= PERL_SCAN_ALLOW_UNDERSCORES;
135 if (silence_non_portable) {
136 flags |= PERL_SCAN_SILENT_NON_PORTABLE;
139 *uv = grok_hex(*s, &numbers_len, &flags, NULL);
140 /* Note that if has non-hex, will ignore everything starting with that up
143 if (strict && numbers_len != (STRLEN) (e - *s)) {
145 *s += (UTF) ? UTF8SKIP(*s) : 1;
146 *error_msg = "Non-hex character";
150 /* Return past the '}' */
156 #endif /* DQUOTE_INLINE_H */