summaryrefslogtreecommitdiff
path: root/metapost
diff options
context:
space:
mode:
authorContext Git Mirror Bot <phg42.2a@gmail.com>2015-04-03 20:15:06 +0200
committerContext Git Mirror Bot <phg42.2a@gmail.com>2015-04-03 20:15:06 +0200
commitf1cde6067499874bf126dfc6f5bedb598f117073 (patch)
treeda8b4e8f480df5e4caa8149253ee6711b918784c /metapost
parentd48764d88ac59aa9b0130f1049892296a3eb4684 (diff)
downloadcontext-f1cde6067499874bf126dfc6f5bedb598f117073.tar.gz
2015-04-03 20:04:00
Diffstat (limited to 'metapost')
-rw-r--r--metapost/context/base/mp-mlib.mpiv69
1 files changed, 57 insertions, 12 deletions
diff --git a/metapost/context/base/mp-mlib.mpiv b/metapost/context/base/mp-mlib.mpiv
index 907c0c4b7..07f6c2e34 100644
--- a/metapost/context/base/mp-mlib.mpiv
+++ b/metapost/context/base/mp-mlib.mpiv
@@ -1102,27 +1102,72 @@ enddef ;
% moved here from mp-grap.mpiv
+% vardef escaped_format(expr s) =
+% "" for n=0 upto length(s) : &
+% if ASCII substring (n,n+1) of s = 37 :
+% "@"
+% else :
+% substring (n,n+1) of s
+% fi
+% endfor
+% enddef ;
+
+numeric mfun_esc_b ; % begin
+numeric mfun_esc_l ; % length
+string mfun_esc_s ; % character
+
+mfun_esc_s := str 37 ;
+
+% this one is the fastest when we have a match
+
+% vardef escaped_format(expr s) =
+% "" for n=0 upto length(s)-1 : &
+% if substring (n,n+1) of s = mfun_esc_s :
+% "@"
+% else :
+% substring (n,n+1) of s
+% fi
+% endfor
+% enddef ;
+
+% this one wins when we have no match
+
vardef escaped_format(expr s) =
- "" for n=0 upto length(s) : &
- if ASCII substring (n,n+1) of s = 37 :
- "@"
- else :
- substring (n,n+1) of s
+ mfun_esc_b := 0 ;
+ mfun_esc_l := length(s) ;
+ for n=0 upto mfun_esc_l-1 :
+ if substring (n,n+1) of s = mfun_esc_s :
+ if mfun_esc_b = 0 :
+ ""
+ fi
+ if n >= mfun_esc_b :
+ & (substring (mfun_esc_b,n) of s)
+ exitif numeric begingroup mfun_esc_b := n+1 endgroup ; % hide
+ fi
+ & "@"
fi
endfor
+ if mfun_esc_b = 0 :
+ s
+ elseif mfun_esc_b > 0 :
+ & (substring (mfun_esc_b,mfun_esc_l) of s)
+ fi
enddef ;
-vardef strfmt(expr f, x) = % maybe use mfun_ namespace
- "\MPgraphformat{" & escaped_format(f) & "}{" & mfun_tagged_string(x) & "}"
-enddef ;
-
-vardef varfmt(expr f, x) = % maybe use mfun_ namespace
- "\MPformatted{" & escaped_format(f) & "}{" & mfun_tagged_string(x) & "}"
-enddef ;
+vardef strfmt(expr f, x) = "\MPgraphformat{" & escaped_format(f) & "}{" & mfun_tagged_string(x) & "}" enddef ;
+vardef varfmt(expr f, x) = "\MPformatted{" & escaped_format(f) & "}{" & mfun_tagged_string(x) & "}" enddef ;
vardef format (expr f, x) = textext(strfmt(f, x)) enddef ;
vardef formatted(expr f, x) = textext(varfmt(f, x)) enddef ;
+% could be this:
+
+% vardef format (expr f,x) = lua.mp.graphformat(f,mfun_tagged_string(x) enddef ;
+% vardef formatted(expr f,x) = lua.mp.format (f, x) enddef ;
+
+% def strfmt = format enddef ; % old
+% def varfmt = formatted enddef ; % old
+
% new
def eofill text t = fill t withpostscript "evenodd" enddef ;