From 78768816e2a6450c60ad7aac8e2df0abf40f5c8d Mon Sep 17 00:00:00 2001 From: Thomas Grill Date: Thu, 6 Oct 2005 19:53:34 +0000 Subject: more robust string->atom conversion eliminate jmax code svn path=/trunk/; revision=3673 --- externals/grill/flext/source/flatom_pr.cpp | 59 +++++++++++++----------------- 1 file changed, 26 insertions(+), 33 deletions(-) (limited to 'externals/grill/flext/source/flatom_pr.cpp') diff --git a/externals/grill/flext/source/flatom_pr.cpp b/externals/grill/flext/source/flatom_pr.cpp index 47430366..d589f657 100644 --- a/externals/grill/flext/source/flatom_pr.cpp +++ b/externals/grill/flext/source/flatom_pr.cpp @@ -88,41 +88,34 @@ bool flext::PrintList(int argc,const t_atom *argv,char *buf,size_t bufsz) } -bool flext::ScanAtom(t_atom &a,const char *buf) +const char *flext::ScanAtom(t_atom &a,const char *c) { - // skip whitespace - while(*buf && isspace(*buf)) ++buf; - if(!*buf) return false; - - char tmp[1024]; - strcpy(tmp,buf); - char *c = tmp; - - // check for word type (s = 0,1,2 ... int,float,symbol) - int s = 0; - for(; *c && !isspace(*c); ++c) { - if(!isdigit(*c)) - s = (*c != '.' || s == 1)?2:1; + // skip leading whitespace + while(*c && isspace(*c)) ++c; + if(!*c) return NULL; + + // go to next space and save character + char *end = const_cast(c); + while(*end && !isspace(*end)) ++end; + char sv = *end; + + float fres; + // first try float + char *endp; + // see if it's a float - thanks to Frank Barknecht + fres = (float)strtod(c,&endp); + if(!*c && endp != c) { + int ires = (int)fres; // try a cast + if(fres == ires) + SetInt(a,ires); + else + SetFloat(a,fres); } + // no, it's a symbol + else + SetString(a,c); - switch(s) { - case 0: // integer -#if FLEXT_SYS == FLEXT_SYS_MAX - SetInt(a,atol(tmp)); - break; -#endif - case 1: // float - SetFloat(a,(float)atof(tmp)); - break; - default: { // anything else is a symbol - char t = *c; *c = 0; - SetString(a,tmp); - *c = t; - break; - } - } + *end = sv; - return true; + return c; } - - -- cgit v1.2.1