summaryrefslogtreecommitdiff
path: root/Build/source/utils/asymptote/runstring.in
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2016-03-14 22:52:10 +0000
committerKarl Berry <karl@freefriends.org>2016-03-14 22:52:10 +0000
commit355bf72b81c6931539dd365430e78ebc10bcd0a2 (patch)
treeff9e855fb9eeb6cbc286d58e6cfe07bdb9cdf4ba /Build/source/utils/asymptote/runstring.in
parent1cdee1080e0ad8f88624629e00039d9fe89c1b54 (diff)
asy 2.37 sources
git-svn-id: svn://tug.org/texlive/trunk@40025 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/utils/asymptote/runstring.in')
-rw-r--r--Build/source/utils/asymptote/runstring.in43
1 files changed, 34 insertions, 9 deletions
diff --git a/Build/source/utils/asymptote/runstring.in b/Build/source/utils/asymptote/runstring.in
index dc51972fe72..3da636d325a 100644
--- a/Build/source/utils/asymptote/runstring.in
+++ b/Build/source/utils/asymptote/runstring.in
@@ -64,7 +64,7 @@ void checkformat(const char *ptr, bool intformat)
while(*ptr && strchr ("hlL", *ptr))
ptr++;
- if(*ptr == '%') ++ptr;
+ if(*ptr == '%') {++ptr; continue;}
else if(*ptr != '\0') {
if(intformat) {
switch(*ptr) {
@@ -101,6 +101,7 @@ void checkformat(const char *ptr, bool intformat)
}
}
}
+ break; // Only one argument is allowed.
} /* End of else statement */
}
}
@@ -203,10 +204,32 @@ string replace(string *S, stringarray2 *translate)
string format(string *format, Int x, string locale=emptystring)
{
- const char *f=format->c_str();
+ ostringstream out;
+ const char *p0=format->c_str();
+ checkformat(p0,true);
- checkformat(f,true);
+ const char *p=p0;
+ const char *start=NULL;
+ while(*p != 0) {
+ char curr=*p;
+ if(curr == '%') {
+ p++;
+ if(*p != '%') {start=p-1; break;}
+ }
+ out << *(p++);
+ }
+ if(!start) return out.str();
+
+ // Allow at most 1 argument
+ while(*p != 0) {
+ if(*p == '*' || *p == '$') return out.str();
+ if(isupper(*p) || islower(*p)) {p++; break;}
+ p++;
+ }
+
+ string f=format->substr(start-p0,p-start);
+
const char *oldlocale=NULL;
if(!locale.empty()) {
@@ -215,12 +238,14 @@ string format(string *format, Int x, string locale=emptystring)
setlocale(LC_ALL,locale.c_str());
}
- Int size=snprintf(NULL,0,f,x)+1;
+ Int size=snprintf(NULL,0,f.c_str(),x)+1;
if(size < 1) size=255; // Workaround for non-C99 compliant systems.
char *buf=new char[size];
- snprintf(buf,size,f,x);
+ snprintf(buf,size,f.c_str(),x);
+
+ out << string(buf);
+ out << p;
- string s=string(buf);
delete[] buf;
if(oldlocale) {
@@ -228,7 +253,7 @@ string format(string *format, Int x, string locale=emptystring)
delete[] oldlocale;
}
- return s;
+ return out.str();
}
string format(string *format, string separator, real x,
@@ -238,10 +263,10 @@ string format(string *format, string separator, real x,
bool texify=false;
ostringstream out;
- checkformat(format->c_str(),false);
+ const char *p0=format->c_str();
+ checkformat(p0,false);
const char *phantom="\\phantom{+}";
- const char *p0=format->c_str();
const char *p=p0;
const char *start=NULL;