summaryrefslogtreecommitdiff
path: root/dquote_static.c
diff options
context:
space:
mode:
authorKarl Williamson <public@khwilliamson.com>2013-01-06 20:25:24 -0700
committerKarl Williamson <public@khwilliamson.com>2013-01-11 11:50:35 -0700
commit00ce556345c5faa3eb42f47f2a510d07b5f3d7c8 (patch)
tree2c1a11fb68fff6076f1d8ee3102611ce225635f6 /dquote_static.c
parent6b976e32dcccdff3dde7682ad9314dc5cd918e17 (diff)
downloadperl-00ce556345c5faa3eb42f47f2a510d07b5f3d7c8.tar.gz
Revise calling sequences for grok_bslash_[xo]
By passing the address of the parse pointer, the functions can advance it, eliminating a parameter to the function, and simplifying the code in the caller.
Diffstat (limited to 'dquote_static.c')
-rw-r--r--dquote_static.c108
1 files changed, 53 insertions, 55 deletions
diff --git a/dquote_static.c b/dquote_static.c
index 5cc890b13c..fa8e354246 100644
--- a/dquote_static.c
+++ b/dquote_static.c
@@ -85,31 +85,30 @@ S_grok_bslash_c(pTHX_ const char source, const bool utf8, const bool output_warn
}
STATIC bool
-S_grok_bslash_o(pTHX_ const char *s,
- UV *uv,
- STRLEN *len,
- const char** error_msg,
- const bool output_warning)
+S_grok_bslash_o(pTHX_ char **s, UV *uv, const char** error_msg,
+ const bool output_warning)
{
/* Documentation to be supplied when interface nailed down finally
* This returns FALSE if there is an error which the caller need not recover
* from; , otherwise TRUE. In either case the caller should look at *len
* On input:
- * s points to a string that begins with 'o', and the previous character
- * was a backslash.
+ * s is the address of a pointer to a NULL terminated string that begins
+ * with 'o', and the previous character was a backslash. At exit, *s
+ * will be advanced to the byte just after those absorbed by this
+ * function. Hence the caller can continue parsing from there. In
+ * the case of an error, this routine has generally positioned *s to
+ * point just to the right of the first bad spot, so that a message
+ * that has a "<--" to mark the spot will be correctly positioned.
* uv points to a UV that will hold the output value, valid only if the
* return from the function is TRUE
- * len on success will point to the next character in the string past the
- * end of this construct.
- * on failure, it will point to the failure
* error_msg is a pointer that will be set to an internal buffer giving an
* error message upon failure (the return is FALSE). Untouched if
* function succeeds
* output_warning says whether to output any warning messages, or suppress
* them
*/
- const char* e;
+ char* e;
STRLEN numbers_len;
I32 flags = PERL_SCAN_ALLOW_UNDERSCORES
| PERL_SCAN_DISALLOW_PREFIX
@@ -120,75 +119,74 @@ S_grok_bslash_o(pTHX_ const char *s,
PERL_ARGS_ASSERT_GROK_BSLASH_O;
- assert(*s == 'o');
- s++;
+ assert(**s == 'o');
+ (*s)++;
- if (*s != '{') {
- *len = 1; /* Move past the o */
+ if (**s != '{') {
*error_msg = "Missing braces on \\o{}";
return FALSE;
}
- e = strchr(s, '}');
+ e = strchr(*s, '}');
if (!e) {
- *len = 2; /* Move past the o{ */
- *error_msg = "Missing right brace on \\o{";
+ (*s)++; /* Move past the '{' */
+ *error_msg = "Missing right brace on \\o{";
return FALSE;
}
- /* Return past the '}' no matter what is inside the braces */
- *len = e - s + 2; /* 2 = 1 for the 'o' + 1 for the '}' */
-
- s++; /* Point to first digit */
-
- numbers_len = e - s;
+ (*s)++; /* Point to expected first digit (could be first byte of utf8
+ sequence if not a digit) */
+ numbers_len = e - *s;
if (numbers_len == 0) {
+ (*s)++; /* Move past the } */
*error_msg = "Number with no digits";
return FALSE;
}
- *uv = grok_oct(s, &numbers_len, &flags, NULL);
+ *uv = grok_oct(*s, &numbers_len, &flags, NULL);
/* Note that if has non-octal, will ignore everything starting with that up
* to the '}' */
- if (output_warning && numbers_len != (STRLEN) (e - s)) {
+ if (output_warning && numbers_len != (STRLEN) (e - *s)) {
Perl_ck_warner(aTHX_ packWARN(WARN_DIGIT),
/* diag_listed_as: Non-octal character '%c'. Resolved as "%s" */
"Non-octal character '%c'. Resolved as \"\\o{%.*s}\"",
- *(s + numbers_len),
+ *(*s + numbers_len),
(int) numbers_len,
- s);
+ *s);
}
+ /* Return past the '}' */
+ *s = e + 1;
+
return TRUE;
}
PERL_STATIC_INLINE bool
-S_grok_bslash_x(pTHX_ const char *s,
- UV *uv,
- STRLEN *len,
- const char** error_msg,
- const bool output_warning)
+S_grok_bslash_x(pTHX_ char **s, UV *uv, const char** error_msg,
+ const bool output_warning)
{
/* Documentation to be supplied when interface nailed down finally
* This returns FALSE if there is an error which the caller need not recover
* from; , otherwise TRUE. In either case the caller should look at *len
* On input:
- * s points to a string that begins with 'x', and the previous character
- * was a backslash.
+ * s is the address of a pointer to a NULL terminated string that begins
+ * with 'x', and the previous character was a backslash. At exit, *s
+ * will be advanced to the byte just after those absorbed by this
+ * function. Hence the caller can continue parsing from there. In
+ * the case of an error, this routine has generally positioned *s to
+ * point just to the right of the first bad spot, so that a message
+ * that has a "<--" to mark the spot will be correctly positioned.
* uv points to a UV that will hold the output value, valid only if the
* return from the function is TRUE
- * len on success will point to the next character in the string past the
- * end of this construct.
- * on failure, it will point to the failure
* error_msg is a pointer that will be set to an internal buffer giving an
* error message upon failure (the return is FALSE). Untouched if
* function succeeds
* output_warning says whether to output any warning messages, or suppress
* them
*/
- const char* e;
+ char* e;
STRLEN numbers_len;
I32 flags = PERL_SCAN_ALLOW_UNDERSCORES
| PERL_SCAN_DISALLOW_PREFIX;
@@ -197,20 +195,20 @@ S_grok_bslash_x(pTHX_ const char *s,
PERL_UNUSED_ARG(output_warning);
- assert(*s == 'x');
- s++;
+ assert(**s == 'x');
+ (*s)++;
- if (*s != '{') {
- I32 flags = PERL_SCAN_DISALLOW_PREFIX;
- *len = 2;
- *uv = grok_hex(s, len, &flags, NULL);
- (*len)++;
+ if (**s != '{') {
+ I32 flags = PERL_SCAN_DISALLOW_PREFIX;
+ STRLEN len = 2;
+ *uv = grok_hex(*s, &len, &flags, NULL);
+ *s += len;
return TRUE;
}
- e = strchr(s, '}');
+ e = strchr(*s, '}');
if (!e) {
- *len = 2; /* Move past the 'x{' */
+ (*s)++; /* Move past the '{' */
/* XXX The corresponding message above for \o is just '\\o{'; other
* messages for other constructs include the '}', so are inconsistent.
*/
@@ -218,16 +216,16 @@ S_grok_bslash_x(pTHX_ const char *s,
return FALSE;
}
- /* Return past the '}' no matter what is inside the braces */
- *len = e - s + 2; /* 2 = 1 for the 'x' + 1 for the '}' */
-
- s++; /* Point to first digit */
-
- numbers_len = e - s;
- *uv = grok_hex(s, &numbers_len, &flags, NULL);
+ (*s)++; /* Point to expected first digit (could be first byte of utf8
+ sequence if not a digit) */
+ numbers_len = e - *s;
+ *uv = grok_hex(*s, &numbers_len, &flags, NULL);
/* Note that if has non-hex, will ignore everything starting with that up
* to the '}' */
+ /* Return past the '}' */
+ *s = e + 1;
+
return TRUE;
}