Annotation of parser3/src/classes/string.C, revision 1.6

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.6     ! paf         6:        $Id: string.C,v 1.5 2001/03/11 08:16:31 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: 
                     16: VClass *string_class;
                     17: 
                     18: // methods
                     19: 
                     20: static void _length(Request& r, Array *) {
                     21:        Pool& pool=r.pool();
                     22:        Value& value=*new(pool) VDouble(pool, r.self->as_string().size());
1.3       paf        23:        r.wcontext->write(value, String::Untaint_lang::NO /*always object, not string*/);
1.1       paf        24: }
                     25: 
                     26: static void _int(Request& r, Array *) {
                     27:        Pool& pool=r.pool();
                     28:        Value& value=*new(pool) VInt(pool, static_cast<int>(r.self->get_double()));
1.3       paf        29:        r.wcontext->write(value, String::Untaint_lang::NO /*always object, not string*/);
1.1       paf        30: }
                     31: 
                     32: static void _double(Request& r, Array *) {
                     33:        Pool& pool=r.pool();
                     34:        Value& value=*new(pool) VDouble(pool, r.self->get_double());
1.3       paf        35:        r.wcontext->write(value, String::Untaint_lang::NO /*always object, not string*/);
1.1       paf        36: }
                     37: 
1.2       paf        38: void initialize_string_class(Pool& pool, VClass& vclass) {
1.1       paf        39:        // ^string.length[]
1.6     ! paf        40:        vclass.add_native_method("length", _length, 0, 0);
        !            41:        
1.1       paf        42:        // ^string.int[]
1.6     ! paf        43:        vclass.add_native_method("int", _int, 0, 0);
        !            44:        
1.1       paf        45:        // ^string.double[]
1.6     ! paf        46:        vclass.add_native_method("double", _double, 0, 0);
1.2       paf        47: }      
1.1       paf        48: 

E-mail: