summaryrefslogtreecommitdiff
path: root/sv_append_till
diff options
context:
space:
mode:
Diffstat (limited to 'sv_append_till')
-rw-r--r--sv_append_till39
1 files changed, 39 insertions, 0 deletions
diff --git a/sv_append_till b/sv_append_till
new file mode 100644
index 0000000000..c2299ea692
--- /dev/null
+++ b/sv_append_till
@@ -0,0 +1,39 @@
+char *
+sv_append_till(sv,from,fromend,delim,keeplist)
+register SV *sv;
+register char *from;
+register char *fromend;
+register I32 delim;
+char *keeplist;
+{
+ register char *to;
+ register STRLEN len;
+
+ if (SvREADONLY(sv))
+ fatal(no_modify);
+ if (!from)
+ return Nullch;
+ len = fromend - from;
+ if (!SvUPGRADE(sv, SVt_PV))
+ return 0;
+ SvGROW(sv, SvCUR(sv) + len + 1);
+ SvPOK_only(sv); /* validate pointer */
+ to = SvPV(sv)+SvCUR(sv);
+ for (; from < fromend; from++,to++) {
+ if (*from == '\\' && from+1 < fromend && delim != '\\') {
+ if (!keeplist)
+ *to++ = *from++;
+ else if (from[1] && index(keeplist,from[1]))
+ *to++ = *from++;
+ else
+ from++;
+ }
+ else if (*from == delim)
+ break;
+ *to = *from;
+ }
+ *to = '\0';
+ SvCUR_set(sv, to - SvPV(sv));
+ return from;
+}
+