Annotation of parser3/src/classes/string.C, revision 1.13
1.1 paf 1: /*
1.4 paf 2: Parser
3: Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.5 paf 4: Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
1.4 paf 5:
1.13 ! paf 6: $Id: string.C,v 1.12 2001/03/18 13:38:45 paf Exp $
1.1 paf 7: */
8:
9: #include "pa_request.h"
10: #include "_string.h"
11: #include "pa_vdouble.h"
12: #include "pa_vint.h"
13:
14: // global var
15:
1.10 paf 16: VStateless_class *string_class;
1.1 paf 17:
18: // methods
19:
1.7 paf 20: static void _length(Request& r, const String&, Array *) {
1.1 paf 21: Pool& pool=r.pool();
22: Value& value=*new(pool) VDouble(pool, r.self->as_string().size());
1.11 paf 23: r.write_no_lang(value);
1.1 paf 24: }
25:
1.7 paf 26: static void _int(Request& r, const String&, Array *) {
1.1 paf 27: Pool& pool=r.pool();
1.13 ! paf 28: Value& value=*new(pool) VInt(pool, (int)r.self->as_double());
1.11 paf 29: r.write_no_lang(value);
1.1 paf 30: }
31:
1.7 paf 32: static void _double(Request& r, const String&, Array *) {
1.1 paf 33: Pool& pool=r.pool();
1.13 ! paf 34: Value& value=*new(pool) VDouble(pool, r.self->as_double());
1.11 paf 35: r.write_no_lang(value);
1.1 paf 36: }
37:
1.9 paf 38: void _string_format(Request& r, const String& method_name, Array *params) {
39: Pool& pool=r.pool();
40:
41: Value& fmt=*static_cast<Value *>(params->get(0));
42: // forcing ^format[this param type]
43: r.fail_if_junction_(true, fmt,
44: method_name, "fmt must not be junction");
45:
1.13 ! paf 46: char *buf=format(pool, r.self->as_double(), fmt.as_string().cstr());
1.9 paf 47:
1.12 paf 48: r.write_no_lang(String(pool, buf));
1.9 paf 49: }
1.11 paf 50:
51: // initialize
1.9 paf 52:
1.10 paf 53: void initialize_string_class(Pool& pool, VStateless_class& vclass) {
1.1 paf 54: // ^string.length[]
1.6 paf 55: vclass.add_native_method("length", _length, 0, 0);
56:
1.1 paf 57: // ^string.int[]
1.6 paf 58: vclass.add_native_method("int", _int, 0, 0);
59:
1.1 paf 60: // ^string.double[]
1.6 paf 61: vclass.add_native_method("double", _double, 0, 0);
1.9 paf 62:
63: // ^string.format[]
64: vclass.add_native_method("format", _string_format, 1, 1);
1.2 paf 65: }
1.1 paf 66:
E-mail: