diff options
Diffstat (limited to 'Build/source/utils/asymptote/runstring.in')
-rw-r--r-- | Build/source/utils/asymptote/runstring.in | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/Build/source/utils/asymptote/runstring.in b/Build/source/utils/asymptote/runstring.in index e0018ded82c..4c6c1db1d85 100644 --- a/Build/source/utils/asymptote/runstring.in +++ b/Build/source/utils/asymptote/runstring.in @@ -201,7 +201,7 @@ string replace(string *S, stringarray2 *translate) return buf.str(); } -string format(string *format, Int x) +string format(string *format, Int x, string locale=emptystring) { const char *f=format->c_str(); @@ -209,14 +209,29 @@ string format(string *format, Int x) Int size=snprintf(NULL,0,f,x)+1; if(size < 1) size=255; // Workaround for non-C99 compliant systems. + const char *oldlocale=NULL; + + if(!locale.empty()) { + oldlocale=setlocale(LC_ALL,NULL); + if(oldlocale) oldlocale=StrdupNoGC(oldlocale); + setlocale(LC_ALL,locale.c_str()); + } + char *buf=new char[size]; snprintf(buf,size,f,x); + + if(oldlocale) { + setlocale(LC_ALL,oldlocale); + delete[] oldlocale; + } + string s=string(buf); delete[] buf; return s; } -string format(string *format, real x, string locale=emptystring) +string format(string *format, string separator, real x, + string locale=emptystring) { bool tex=getSetting<string>("tex") != "none"; bool texify=false; @@ -276,7 +291,7 @@ string format(string *format, real x, string locale=emptystring) char *q=buf; // beginning of formatted number - if(*q == ' ') { + if(*q == ' ' && texify) { out << phantom; q++; } @@ -294,13 +309,14 @@ string format(string *format, real x, string locale=emptystring) } if(zero) { q++; - if(plus || space) out << phantom; + if((plus || space) && texify) out << phantom; } } const char *r=p=q; bool dp=false; - while(*r != 0 && (isdigit(*r) || *r == decimal || *r == '+' || *r == '-')) { + while(*r != 0 && (isspace(*r) || isdigit(*r) || *r == decimal \ + || *r == '+' || *r == '-')) { if(*r == decimal) dp=true; r++; } @@ -319,7 +335,7 @@ string format(string *format, real x, string locale=emptystring) while(*q != 0) { if(texify && (*q == 'E' || *q == 'e') && (*(q+1) == '+' || *(q+1) == '-')) { - if(!zero) out << "\\!\\times\\!10^{"; + if(!zero) out << separator << "10^{"; bool plus=(*(q+1) == '+'); q++; if(plus) q++; @@ -352,6 +368,11 @@ Int hex(string s) error(buf); } +Int ascii(string s) +{ + return s.empty() ? -1 : (unsigned char) s[0]; +} + string string(Int x) { ostringstream buf; |