]> git.tdb.fi Git - libs/core.git/blobdiff - source/fmt.cpp
Rewrite lexical_cast to use internal conversion routines
[libs/core.git] / source / fmt.cpp
index fdd73f3c43b726175f927fe4d0ade866db577315..0c1531d8315dfe8c19560be5b28ed2b8374cf9e7 100644 (file)
@@ -1,9 +1,10 @@
 /* $Id$
 
 This file is part of libmspstrings
-Copyright © 2006-2007 Mikko Rasa
+Copyright © 2006-2008 Mikko Rasa
 Distributed under the LGPL
 */
+
 #include <msp/core/except.h>
 #include "fmt.h"
 
@@ -22,10 +23,11 @@ Fmt &Fmt::reset()
        fillc=' ';
        base=DEC;
        sbase=false;
-       fmode=EXP;
+       fmode=AUTOFLT;
        spoint=false;
        align=RIGHT;
        ucase=false;
+       type=STR;
 
        return *this;
 }
@@ -94,27 +96,36 @@ void Fmt::parse(const char *f)
                }
        }
 
-       if(*f=='x' || *f=='X')
+       type=NUM;
+       if(*f=='d' || *f=='u')
+               base=DEC;
+       else if(*f=='x' || *f=='X')
                base=HEX;
        else if(*f=='o')
                base=OCT;
+       else if(*f=='b')
+               base=BIN;
        else if(*f=='e' || *f=='E')
                fmode=SCI;
        else if(*f=='f' || *f=='F')
                fmode=FIXED;
        else if(*f=='g' || *f=='G')
-               fmode=EXP;
-       else if(*f=='p')
+               fmode=AUTOFLT;
+       else if(*f=='p' || *f=='P')
        {
                base=HEX;
                sbase=true;
        }
-       else if(*f=='d' || *f=='i' || *f=='u' || *f=='c' || *f=='s')
-               ;
+       else if(*f=='c')
+               type=CHAR;
+       else if(*f=='s')
+               type=STR;
+       else if(*f=='i')
+               base=AUTOBASE;
        else
                throw InvalidParameterValue("Invalid conversion specifier");
 
-       if(*f=='E' || *f=='F' || *f=='G' || *f=='X')
+       if(*f=='E' || *f=='F' || *f=='G' || *f=='X' || *f=='P')
                ucase=true;
 
        ++f;