Annotation of parser3/src/types/pa_vstring.h, revision 1.8

1.1       paf         1: /*
                      2:        Parser
                      3:        Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.2       paf         4:        Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
1.1       paf         5: 
1.8     ! paf         6:        $Id: pa_vstring.h,v 1.7 2001/03/15 09:37:57 paf Exp $
1.1       paf         7: */
                      8: 
                      9: #ifndef PA_VSTRING_H
                     10: #define PA_VSTRING_H
                     11: 
                     12: #include <stdlib.h>
                     13: 
1.4       paf        14: #include "pa_vstateless_object.h"
1.1       paf        15: #include "pa_vdouble.h"
                     16: #include "_string.h"
                     17: 
1.4       paf        18: class VString : public VStateless_object {
1.1       paf        19: public: // Value
                     20: 
                     21:        // all: for error reporting after fail(), etc
                     22:        const char *type() const { return "string"; }
                     23:        // string: fvalue as VDouble
                     24:        Value *get_expr_result() { return NEW VDouble(pool(), get_double()); }
                     25:        // string: fvalue
                     26:        const String *get_string() { return &fvalue; };
                     27:        // string: fvalue
1.6       paf        28:        double get_double() { 
                     29:                double result;
                     30:                const char *cstr=fvalue.cstr();
                     31:                char *error_pos=0;
1.8     ! paf        32:                // 0xABC
        !            33:                if(cstr[0]=='0' && (cstr[1]=='x' || cstr[1]=='X'))
1.6       paf        34:                        result=(double)strtoul(cstr, &error_pos, 0);
                     35:                else
                     36:                        result=strtod(cstr, &error_pos);
                     37: 
1.8     ! paf        38:                if(error_pos&&*error_pos)
        !            39:                        THROW(0, 0,
        !            40:                                &fvalue,
        !            41:                                "invalid number");
        !            42: 
        !            43:                //return error_pos&&*error_pos?0:result;
        !            44:                return result;
1.6       paf        45:        }
1.1       paf        46:        // string: empty or not
                     47:        bool get_bool() { return fvalue.size()!=0; };
                     48: 
                     49: public: // usage
                     50: 
1.4       paf        51:        VString(Pool& apool) : VStateless_object(apool, *string_class), 
1.5       paf        52:                fvalue(*new(apool) String(apool)) {
1.1       paf        53:        }
                     54: 
1.4       paf        55:        VString(const String& avalue) : VStateless_object(avalue.pool(), *string_class),
1.1       paf        56:                fvalue(avalue) {
                     57:        }
                     58: 
                     59:        const String& value() { return fvalue; }
                     60: 
                     61: private:
                     62:        const String& fvalue;
                     63: 
                     64: };
                     65: 
                     66: #endif

E-mail: