diff options
author | Marius <mariausol@gmail.com> | 2013-11-01 16:20:13 +0200 |
---|---|---|
committer | Marius <mariausol@gmail.com> | 2013-11-01 16:20:13 +0200 |
commit | 7d896afa09526aee508c4484f1bf61f7139c752b (patch) | |
tree | 10ffaf0ccdfbd6e0c178cd3d3dd8aadb0f201dd5 /metapost | |
parent | 1d04224cdd84e606f0c70a47d10acc231f271b9f (diff) | |
download | context-7d896afa09526aee508c4484f1bf61f7139c752b.tar.gz |
beta 2013.11.01 15:02
Diffstat (limited to 'metapost')
-rw-r--r-- | metapost/context/base/mp-grap.mpiv | 37 | ||||
-rw-r--r-- | metapost/context/base/mp-mlib.mpiv | 23 |
2 files changed, 46 insertions, 14 deletions
diff --git a/metapost/context/base/mp-grap.mpiv b/metapost/context/base/mp-grap.mpiv index 81a410db2..417bfbe69 100644 --- a/metapost/context/base/mp-grap.mpiv +++ b/metapost/context/base/mp-grap.mpiv @@ -1075,7 +1075,7 @@ enddef ; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% we could pass via variables and save escaping +% we could pass via variables and save escaping as that is inefficient Ten_to0 = 1 ; Ten_to1 = 10 ; @@ -1083,21 +1083,30 @@ Ten_to2 = 100 ; Ten_to3 = 1000 ; Ten_to4 = 10000 ; -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 ; +if unknown context_mlib : -vardef strfmt(expr f, x) = - "\MPgraphformat{" & escaped_format(f) & "}{" & mfun_tagged_string(x) & "}" -enddef ; + 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 ; + + 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 format (expr f, x) = textext(strfmt(f,x)) enddef ; + vardef formatted(expr f, x) = textext(varfmt(f,x)) enddef ; -vardef format(expr f, x) = textext(strfmt(f, x)) enddef ; +fi ; % A couple of extensions : diff --git a/metapost/context/base/mp-mlib.mpiv b/metapost/context/base/mp-mlib.mpiv index 6139a63c2..dfb3f7102 100644 --- a/metapost/context/base/mp-mlib.mpiv +++ b/metapost/context/base/mp-mlib.mpiv @@ -865,3 +865,26 @@ vardef mfun_tagged_string(expr value) = else : "2:" & value fi 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 ; + +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 format (expr f, x) = textext(strfmt(f, x)) enddef ; +vardef formatted(expr f, x) = textext(varfmt(f, x)) enddef ; |