summaryrefslogtreecommitdiff
path: root/metapost
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2013-11-01 15:02:00 +0100
committerHans Hagen <pragma@wxs.nl>2013-11-01 15:02:00 +0100
commit642ffccd526fab491d23efce30f40c35a13262cd (patch)
tree019ee93fbb5a8aca8922d2c2aa30009fb8ab3989 /metapost
parent9cb5e3dcce51a3c07bd482b7c0575496434017e1 (diff)
downloadcontext-642ffccd526fab491d23efce30f40c35a13262cd.tar.gz
beta 2013.11.01 15:02
Diffstat (limited to 'metapost')
-rw-r--r--metapost/context/base/mp-grap.mpiv37
-rw-r--r--metapost/context/base/mp-mlib.mpiv23
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 ;