This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
remove doc hedge about autovivification
[perl5.git] / dquote_inline.h
CommitLineData
f7e03a10
JH
1/* dquote_inline.h
2 *
3 * Copyright (C) 2015 by Larry Wall and others
4 *
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.
7 */
8
6a5bc5ac
KW
9#ifndef PERL_DQUOTE_INLINE_H_ /* Guard against nested #inclusion */
10#define PERL_DQUOTE_INLINE_H_
f7e03a10
JH
11
12/*
13 - regcurly - a little FSA that accepts {\d+,?\d*}
14 Pulled from reg.c.
15 */
16PERL_STATIC_INLINE I32
17S_regcurly(const char *s)
18{
19 PERL_ARGS_ASSERT_REGCURLY;
20
21 if (*s++ != '{')
22 return FALSE;
23 if (!isDIGIT(*s))
24 return FALSE;
25 while (isDIGIT(*s))
26 s++;
27 if (*s == ',') {
28 s++;
29 while (isDIGIT(*s))
30 s++;
31 }
32
33 return *s == '}';
34}
35
ce54a8b9
KW
36/* This is inline not for speed, but because it is so tiny */
37
38PERL_STATIC_INLINE char*
39S_form_short_octal_warning(pTHX_
40 const char * const s, /* Points to first non-octal */
41 const STRLEN len /* Length of octals string, so
42 (s-len) points to first
43 octal */
44)
f7e03a10 45{
ce54a8b9
KW
46 /* Return a character string consisting of a warning message for when a
47 * string constant in octal is weird, like "\078". */
f7e03a10 48
ce54a8b9 49 const char * sans_leading_zeros = s - len;
f7e03a10 50
ce54a8b9 51 PERL_ARGS_ASSERT_FORM_SHORT_OCTAL_WARNING;
f7e03a10 52
ce54a8b9 53 assert(*s == '8' || *s == '9');
f7e03a10 54
ce54a8b9
KW
55 /* Remove the leading zeros, retaining one zero so won't be zero length */
56 while (*sans_leading_zeros == '0') sans_leading_zeros++;
57 if (sans_leading_zeros == s) {
58 sans_leading_zeros--;
f7e03a10
JH
59 }
60
ce54a8b9
KW
61 return Perl_form(aTHX_
62 "'%.*s' resolved to '\\o{%.*s}%c'",
63 (int) (len + 2), s - len - 1,
64 (int) (s - sans_leading_zeros), sans_leading_zeros,
65 *s);
f7e03a10 66}
6a5bc5ac 67#endif /* PERL_DQUOTE_INLINE_H_ */