Annotation of parser3/src/types/pa_vstring.h, revision 1.86
1.23 paf 1: /** @file
2: Parser: @b string parser class decl.
1.13 paf 3:
1.85 moko 4: Copyright (c) 2001-2026 Art. Lebedev Studio (https://www.artlebedev.com)
1.76 moko 5: Authors: Konstantin Morshnev <moko@design.ru>, Alexandr Petrosian <paf@design.ru>
1.1 paf 6: */
7:
8: #ifndef PA_VSTRING_H
9: #define PA_VSTRING_H
1.47 paf 10:
1.86 ! moko 11: #define IDENT_PA_VSTRING_H "$Id: pa_vstring.h,v 1.85 2026/04/25 13:38:46 moko Exp $"
1.1 paf 12:
1.55 paf 13: // includes
1.1 paf 14:
1.4 paf 15: #include "pa_vstateless_object.h"
1.1 paf 16: #include "pa_vdouble.h"
1.24 paf 17:
1.55 paf 18: // externs
19:
20: extern Methoded* string_class;
1.1 paf 21:
1.13 paf 22: /// value of type 'string'. implemented with @c String
1.55 paf 23: class VString: public VStateless_object {
1.1 paf 24: public: // Value
25:
1.55 paf 26: override const char* type() const { return "string"; }
27: override VStateless_class *get_class() { return string_class; }
1.31 parser 28: /// VString: eq ''=false, ne ''=true
1.55 paf 29: override bool is_defined() const { return !fstring->is_empty(); }
1.32 parser 30: /// VString: 0 or !0
1.55 paf 31: override bool as_bool() const { return as_double()!=0; }
1.16 paf 32: /// VString: true
1.55 paf 33: override bool is_string() const { return true; }
1.69 moko 34:
35: /// VString: VDouble
36: override Value& as_expr_result() { return *new VDouble(fstring->as_double()); }
1.13 paf 37: /// VString: fstring
1.55 paf 38: override const String* get_string() { return fstring; };
1.13 paf 39: /// VString: fstring
1.55 paf 40: override double as_double() const { return fstring->as_double(); }
1.26 parser 41: /// VString: fstring
1.55 paf 42: override int as_int() const { return fstring->as_int(); }
1.84 moko 43: /// VString: fstring
44: override pa_wint as_wint() const { return fstring->as_wint(); }
1.20 paf 45:
46: /// VString: vfile
1.61 misha 47: override VFile* as_vfile(String::Language lang, const Request_charsets *charsets=0);
1.9 paf 48:
1.63 misha 49: /// VString: json string
1.84 moko 50: override const String* get_json_string(Json_options&) {
1.63 misha 51: String* result = new String();
52: result->append_quoted(fstring);
53: return result;
54: }
55:
1.86 ! moko 56: /// VString: no elements, hash compatible if empty
1.62 misha 57: override Value* get_element(const String& aname) {
1.86 ! moko 58: MAYBE_GET_SPECIAL_OR_METHOD(VStateless_object::get_element(aname));
1.78 moko 59: // void, empty or whitespace string are hash compatible
1.73 moko 60: if (fstring->is_empty() || fstring->trim().is_empty())
61: return 0;
1.9 paf 62:
1.73 moko 63: // bad $string.field
1.71 moko 64: return Value::get_element(aname);
65: }
1.64 moko 66:
1.1 paf 67: public: // usage
68:
1.80 moko 69: VString(): fstring(&String::Empty) {}
1.55 paf 70: VString(const String& avalue): fstring(&avalue) {}
1.82 moko 71: /// VString is L_TAINTED by default, opposite to String, which is L_CLEAN by default
72: VString(const char *avalue, String::Language alang=String::L_TAINTED): fstring(new String(avalue, alang)) {}
73: VString(String::Body avalue, String::Language alang=String::L_TAINTED): fstring(new String(avalue, alang)) {}
1.1 paf 74:
1.45 paf 75: const String& string() const { return *fstring; }
1.38 paf 76: void set_string(const String& astring) { fstring=&astring; }
1.1 paf 77:
1.83 moko 78: inline static VString* empty(){
1.68 moko 79: static VString singleton;
80: return &singleton;
81: }
1.83 moko 82: // L_CLEAN as nothing to escape in digits
83: static VString* uitoa(size_t aindex);
1.68 moko 84:
1.1 paf 85: private:
1.55 paf 86: const String* fstring;
1.1 paf 87:
88: };
89:
90: #endif
E-mail: