Annotation of parser3/src/types/pa_vstring.h, revision 1.6
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.6 ! paf 6: $Id: pa_vstring.h,v 1.5 2001/03/12 12:00:09 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;
! 32: // 0123 or 0xABC
! 33: if(cstr[0]=='0')
! 34: result=(double)strtoul(cstr, &error_pos, 0);
! 35: else
! 36: result=strtod(cstr, &error_pos);
! 37:
! 38: return error_pos?0:result;
! 39: }
1.1 paf 40: // string: empty or not
41: bool get_bool() { return fvalue.size()!=0; };
42:
43: public: // usage
44:
1.4 paf 45: VString(Pool& apool) : VStateless_object(apool, *string_class),
1.5 paf 46: fvalue(*new(apool) String(apool)) {
1.1 paf 47: }
48:
1.4 paf 49: VString(const String& avalue) : VStateless_object(avalue.pool(), *string_class),
1.1 paf 50: fvalue(avalue) {
51: }
52:
53: const String& value() { return fvalue; }
54:
55: private:
56: const String& fvalue;
57:
58: };
59:
60: #endif
E-mail: