diff options
author | Karl Williamson <khw@cpan.org> | 2016-02-18 21:43:14 -0700 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2016-02-19 10:41:43 -0700 |
commit | bb17e3266e6d1392f4152af8ef9115e2f0d2a06a (patch) | |
tree | 726af9ee87a62e73eb2808362d4831888112093b | |
parent | b9c1a2c52c1d56a2cc9c9ae73e72977d628c44ea (diff) | |
download | perl-bb17e3266e6d1392f4152af8ef9115e2f0d2a06a.tar.gz |
Add a parameter to a static function
This parameter will be used in a future commit, it changes the output
format of this function that displays the contents of an inversion list
so that it won't have to be parsed later, simplifying the code at that
time.
-rw-r--r-- | embed.fnc | 3 | ||||
-rw-r--r-- | embed.h | 2 | ||||
-rw-r--r-- | proto.h | 2 | ||||
-rw-r--r-- | regcomp.c | 40 |
4 files changed, 34 insertions, 13 deletions
@@ -1539,7 +1539,8 @@ EiMn |void |invlist_iterfinish|NN SV* invlist EiMRn |UV |invlist_highest|NN SV* const invlist EMRs |SV* |_make_exactf_invlist |NN RExC_state_t *pRExC_state \ |NN regnode *node -EsMR |SV* |invlist_contents|NN SV* const invlist +EsMR |SV* |invlist_contents|NN SV* const invlist \ + |const bool traditional_style #endif #if defined(PERL_IN_REGCOMP_C) || defined(PERL_IN_UTF8_C) EXmM |void |_invlist_intersection |NN SV* const a|NN SV* const b|NN SV** i @@ -1000,7 +1000,7 @@ #define handle_possible_posix(a,b,c,d) S_handle_possible_posix(aTHX_ a,b,c,d) #define handle_regex_sets(a,b,c,d,e) S_handle_regex_sets(aTHX_ a,b,c,d,e) #define invlist_clone(a) S_invlist_clone(aTHX_ a) -#define invlist_contents(a) S_invlist_contents(aTHX_ a) +#define invlist_contents(a,b) S_invlist_contents(aTHX_ a,b) #define invlist_extend(a,b) S_invlist_extend(aTHX_ a,b) #define invlist_highest S_invlist_highest #define invlist_is_iterating S_invlist_is_iterating @@ -4745,7 +4745,7 @@ PERL_STATIC_INLINE SV* S_invlist_clone(pTHX_ SV* const invlist) #define PERL_ARGS_ASSERT_INVLIST_CLONE \ assert(invlist) -STATIC SV* S_invlist_contents(pTHX_ SV* const invlist) +STATIC SV* S_invlist_contents(pTHX_ SV* const invlist, const bool traditional_style) __attribute__warn_unused_result__; #define PERL_ARGS_ASSERT_INVLIST_CONTENTS \ assert(invlist) @@ -9514,14 +9514,25 @@ S_invlist_highest(SV* const invlist) } SV * -S_invlist_contents(pTHX_ SV* const invlist) +S_invlist_contents(pTHX_ SV* const invlist, const bool traditional_style) { /* Get the contents of an inversion list into a string SV so that they can - * be printed out. It uses the format traditionally done for debug tracing - */ + * be printed out. If 'traditional_style' is TRUE, it uses the format + * traditionally done for debug tracing; otherwise it uses a format + * suitable for just copying to the output, with blanks between ranges and + * a dash between range components */ UV start, end; - SV* output = newSVpvs("\n"); + SV* output; + const char intra_range_delimiter = (traditional_style ? '\t' : '-'); + const char inter_range_delimiter = (traditional_style ? '\n' : ' '); + + if (traditional_style) { + output = newSVpvs("\n"); + } + else { + output = newSVpvs(""); + } PERL_ARGS_ASSERT_INVLIST_CONTENTS; @@ -9530,17 +9541,26 @@ S_invlist_contents(pTHX_ SV* const invlist) invlist_iterinit(invlist); while (invlist_iternext(invlist, &start, &end)) { if (end == UV_MAX) { - Perl_sv_catpvf(aTHX_ output, "%04"UVXf"\tINFINITY\n", start); + Perl_sv_catpvf(aTHX_ output, "%04"UVXf"%cINFINITY%c", + start, intra_range_delimiter, + inter_range_delimiter); } else if (end != start) { - Perl_sv_catpvf(aTHX_ output, "%04"UVXf"\t%04"UVXf"\n", - start, end); + Perl_sv_catpvf(aTHX_ output, "%04"UVXf"%c%04"UVXf"%c", + start, + intra_range_delimiter, + end, inter_range_delimiter); } else { - Perl_sv_catpvf(aTHX_ output, "%04"UVXf"\n", start); + Perl_sv_catpvf(aTHX_ output, "%04"UVXf"%c", + start, inter_range_delimiter); } } + if (SvCUR(output) && ! traditional_style) {/* Get rid of trailing blank */ + SvCUR_set(output, SvCUR(output) - 1); + } + return output; } @@ -17533,11 +17553,11 @@ Perl__get_regclass_nonbitmap_data(pTHX_ const regexp *prog, if (exclude_list) { SV* clone = invlist_clone(invlist); _invlist_subtract(clone, exclude_list, &clone); - sv_catsv(matches_string, invlist_contents(clone)); + sv_catsv(matches_string, invlist_contents(clone, TRUE)); SvREFCNT_dec_NN(clone); } else { - sv_catsv(matches_string, invlist_contents(invlist)); + sv_catsv(matches_string, invlist_contents(invlist, TRUE)); } } *listsvp = matches_string; |