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

1.24      paf         1: /** @file
                      2:        Parser: @b string parser class.
                      3: 
1.126   ! paf         4:        Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com)
1.97      paf         5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.113     paf         6: */
1.24      paf         7: 
1.126   ! paf         8: static const char* IDENT_STRING_C="$Date: 2003/06/26 11:51:30 $";
1.1       paf         9: 
1.43      paf        10: #include "classes.h"
1.126   ! paf        11: #include "pa_vmethod_frame.h"
        !            12: 
1.1       paf        13: #include "pa_request.h"
                     14: #include "pa_vdouble.h"
                     15: #include "pa_vint.h"
1.17      paf        16: #include "pa_vtable.h"
1.25      paf        17: #include "pa_vbool.h"
1.27      paf        18: #include "pa_string.h"
1.53      parser     19: #include "pa_sql_connection.h"
1.71      parser     20: #include "pa_dictionary.h"
1.119     paf        21: #include "pa_vmethod_frame.h"
1.1       paf        22: 
1.41      paf        23: // class
                     24: 
1.126   ! paf        25: class MString: public Methoded {
1.41      paf        26: public:
1.126   ! paf        27:        MString();
1.44      paf        28: public: // Methoded
1.53      parser     29:        bool used_directly() { return true; }
1.41      paf        30: };
1.1       paf        31: 
1.126   ! paf        32: // global variable
        !            33: 
        !            34: DECLARE_CLASS_VAR(string, new MString, 0);
        !            35: 
        !            36: // defines for statics
        !            37: 
        !            38: #define MATCH_VAR_NAME "match"
        !            39: 
        !            40: // statics
        !            41: 
        !            42: static const String match_var_name(MATCH_VAR_NAME);
        !            43: 
1.1       paf        44: // methods
                     45: 
1.126   ! paf        46: static void _length(Request& r, MethodParams&) {
        !            47:        double result=GET_SELF(r, VString).string().length();
        !            48:        r.write_no_lang(*new VDouble(result));
1.1       paf        49: }
                     50: 
1.126   ! paf        51: static void _int(Request& r, MethodParams& params) {
        !            52:        const String& self_string=GET_SELF(r, VString).string();
1.72      parser     53:        int converted;
1.126   ! paf        54:        Value* default_code=params.count()>0?&params.as_junction(0, "default must be int")
        !            55:                :0; // (default)
1.84      parser     56:        try {
1.126   ! paf        57:                if(self_string.is_empty())
1.121     paf        58:                        throw Exception("parser.runtime",
1.126   ! paf        59:                                0,
1.121     paf        60:                                "parameter is empty string, error converting");
1.126   ! paf        61:                converted=self_string.as_int();
1.84      parser     62:        } catch(...) { // convert problem
1.126   ! paf        63:                if(default_code)
        !            64:                        converted=r.process_to_value(*default_code).as_int();
1.84      parser     65:                else
1.126   ! paf        66:                        rethrow; // we have a problem when no default                   
1.72      parser     67:        }
1.126   ! paf        68:        r.write_no_lang(*new VInt(converted));
1.1       paf        69: }
                     70: 
1.126   ! paf        71: static void _double(Request& r, MethodParams& params) {
        !            72:        const String& self_string=GET_SELF(r, VString).string();
1.72      parser     73:        double converted;
1.126   ! paf        74:        Value* default_code=params.count()>0?&params.as_junction(0, "default must be double")
        !            75:                :0; // (default)
1.84      parser     76:        try {
1.126   ! paf        77:                if(self_string.is_empty())
1.121     paf        78:                        throw Exception("parser.runtime",
1.126   ! paf        79:                                0,
1.121     paf        80:                                "parameter is empty string, error converting");
1.126   ! paf        81:                converted=self_string.as_double();
1.84      parser     82:        } catch(...) { // convert problem
1.126   ! paf        83:                if(default_code)
        !            84:                        converted=r.process_to_value(*default_code).as_double();
1.84      parser     85:                else
1.126   ! paf        86:                        rethrow; // we have a problem when no default
1.72      parser     87:        }
                     88: 
1.126   ! paf        89:        r.write_no_lang(*new VDouble(converted));
1.1       paf        90: }
                     91: 
1.126   ! paf        92: /*not static*/void _string_format(Request& r, MethodParams& params) {
1.9       paf        93: 
1.126   ! paf        94:        Value& fmt_maybe_code=params[0];
1.95      paf        95:        // for some time due to stupid {} in original design
1.99      paf        96:        const String& fmt=r.process_to_string(fmt_maybe_code);
1.9       paf        97: 
1.126   ! paf        98:        const char* buf=format(r.get_self().as_double(), fmt.cstrm());
1.63      parser     99: 
1.126   ! paf       100:        r.write_no_lang(String(buf));
1.9       paf       101: }
1.11      paf       102: 
1.126   ! paf       103: static void _left(Request& r, MethodParams& params) {
        !           104:        size_t n=(size_t)params.as_int(0, "n must be int", r);
1.15      paf       105:        
1.126   ! paf       106:        const String& string=GET_SELF(r, VString).string();
1.102     paf       107:        r.write_assign_lang(string.mid(0, n));
1.15      paf       108: }
                    109: 
1.126   ! paf       110: static void _right(Request& r, MethodParams& params) {
        !           111:        size_t n=(size_t)params.as_int(0, "n must be int", r);
1.15      paf       112:        
1.126   ! paf       113:        const String& string=GET_SELF(r, VString).string();
        !           114:        r.write_assign_lang(string.mid(string.length()-n, string.length()));
1.15      paf       115: }
                    116: 
1.126   ! paf       117: static void _mid(Request& r, MethodParams& params) {
        !           118:        const String& string=GET_SELF(r, VString).string();
1.83      parser    119: 
1.126   ! paf       120:        size_t p=(size_t)max(0, params.as_int(0, "p must be int", r));
        !           121:        size_t n=params.count()>1?
        !           122:                (size_t)max(0, params.as_int(1, "n must be int", r)):string.length();
1.15      paf       123:        
1.102     paf       124:        r.write_assign_lang(string.mid(p, p+n));
1.15      paf       125: }
                    126: 
1.126   ! paf       127: static void _pos(Request& r, MethodParams& params) {
        !           128:        Value& substr=params.as_no_junction(0, "substr must not be code");
1.16      paf       129:        
1.126   ! paf       130:        const String& string=GET_SELF(r, VString).string();
        !           131:        r.write_assign_lang(*new VInt((int)string.pos(substr.as_string())));
1.16      paf       132: }
                    133: 
1.126   ! paf       134: static void split_list(Request& r, 
        !           135:                       MethodParams& params, int paramIndex,
        !           136:                       const String& string, 
        !           137:                       ArrayString& result) {
        !           138:        Value& delim_value=params.as_no_junction(paramIndex, "delimiter must not be code");
1.23      paf       139: 
1.126   ! paf       140:        size_t pos_after=0;
        !           141:        string.split(result, pos_after, delim_value.as_string());
1.19      paf       142: }
                    143: 
1.118     paf       144: #define SPLIT_LEFT 0x0001
                    145: #define SPLIT_RIGHT 0x0010
                    146: #define SPLIT_HORIZONTAL 0x0100
                    147: #define SPLIT_VERTICAL 0x1000
                    148: 
1.126   ! paf       149: static int split_options(const String* options) {
1.118     paf       150:     struct Split_option {
1.126   ! paf       151:                const char* keyL;
        !           152:                const char* keyU;
1.118     paf       153:                int setBit;
                    154:                int checkBit;
                    155:     } split_option[]={
                    156:                {"l", "L", SPLIT_LEFT, SPLIT_RIGHT}, // 0xVHRL
                    157:                {"r", "R", SPLIT_RIGHT, SPLIT_LEFT},
                    158:                {"h", "H", SPLIT_HORIZONTAL, SPLIT_VERTICAL},
                    159:                {"v", "V", SPLIT_VERTICAL, SPLIT_HORIZONTAL},
                    160:                {0}
                    161:     };
                    162: 
                    163:        int result=0;
1.126   ! paf       164:        if(options) {
1.118     paf       165:                for(Split_option *o=split_option; o->keyL; o++) 
1.126   ! paf       166:                        if(options->pos(o->keyL)!=STRING_NOT_FOUND 
        !           167:                                || (o->keyU && options->pos(o->keyU)!=STRING_NOT_FOUND)) {
1.118     paf       168:                                if(result & o->checkBit)
                    169:                                        throw Exception("parser.runtime",
                    170:                                                options,
                    171:                                                "conflicting split options");
                    172:                                result |= o->setBit;
                    173:                        }
                    174:        }
                    175: 
                    176:        return result;
                    177: }
                    178: 
1.126   ! paf       179: static Table& split_vertical(Request& r, ArrayString& pieces, bool right) {
1.61      parser    180: 
1.126   ! paf       181:        Table::columns_type columns(new ArrayString);
        !           182:        *columns+=new String("piece");
1.19      paf       183: 
1.126   ! paf       184:        Table& table=*new Table(columns, pieces.count());
1.118     paf       185:        if(right) { // right
1.126   ! paf       186:                for(int i=pieces.count(); --i>=0; ) {
        !           187:                        Table::element_type row(new ArrayString);
        !           188:                        *row+=pieces[i];
        !           189:                        table+=row;
1.118     paf       190:                }
                    191:        } else { // left
1.126   ! paf       192:                Array_iterator<const String*> i(pieces);
1.118     paf       193:                while(i.has_next()) {
1.126   ! paf       194:                        Table::element_type row(new ArrayString);
        !           195:                        *row+=i.next();
        !           196:                        table+=row;
1.118     paf       197:                }
1.61      parser    198:        }
1.118     paf       199: 
1.126   ! paf       200:        return table;
1.19      paf       201: }
                    202: 
1.126   ! paf       203: static Table& split_horizontal(Request& r, ArrayString& pieces, bool right) {
        !           204:        Table& table=*new Table(Table::columns_type(0) /* nameless */);
        !           205:        Table::element_type row(new ArrayString(pieces.count()));
1.118     paf       206:        if(right) { // right
1.126   ! paf       207:                for(size_t i=pieces.count(); --i>=0; )
        !           208:                        *row+=pieces[i];
1.118     paf       209:        } else { // left
1.126   ! paf       210:                for(Array_iterator<const String*> i(pieces); i.has_next(); )
        !           211:                        *row+=i.next();
1.118     paf       212:        }
1.126   ! paf       213:        table+=row;
1.118     paf       214: 
1.126   ! paf       215:        return table;
1.118     paf       216: }
                    217: 
1.126   ! paf       218: static void split_with_options(Request& r, MethodParams& params,
1.118     paf       219:                                                           int bits) {
1.126   ! paf       220:        const String& string=GET_SELF(r, VString).string();
1.19      paf       221: 
1.126   ! paf       222:        ArrayString pieces;
        !           223:        split_list(r, params, 0, string, pieces);
1.19      paf       224: 
1.118     paf       225:        if(!bits) {
1.126   ! paf       226:                const String* options=0;
        !           227:                if(params.count()>1)
        !           228:                        options=&params.as_string(1, "options must not be code");
        !           229:                
1.118     paf       230:                bits=split_options(options);
                    231:        }
1.21      paf       232: 
1.118     paf       233:        bool right=(bits & SPLIT_RIGHT) != 0;
                    234:        bool horizontal=(bits & SPLIT_HORIZONTAL) !=0;
1.126   ! paf       235:        Table& table=horizontal?split_horizontal(r, pieces, right)
        !           236:                :split_vertical(r, pieces, right);
1.17      paf       237: 
1.126   ! paf       238:        r.write_no_lang(*new VTable(&table));
1.118     paf       239: }
1.126   ! paf       240: static void _split(Request& r, MethodParams& params) {
        !           241:        split_with_options(r, params, 0 /* maybe-determine from param #2 */);
1.118     paf       242: }
1.126   ! paf       243: static void _lsplit(Request& r, MethodParams& params) {
        !           244:        split_with_options(r, params, SPLIT_LEFT);
1.118     paf       245: }
1.126   ! paf       246: static void _rsplit(Request& r, MethodParams& params) {
        !           247:        split_with_options(r, params, SPLIT_RIGHT);
1.17      paf       248: }
                    249: 
1.126   ! paf       250: static void search_action(Table& table, Table::element_type row, int, int, int, int, void *) {
1.28      paf       251:        if(row)
                    252:                table+=row;
1.27      paf       253: }
                    254: 
1.74      parser    255: #ifndef DOXYGEN
1.27      paf       256: struct Replace_action_info {
1.126   ! paf       257:        Request* request;  
        !           258:        const String* src;  String* dest;
        !           259:        VTable* vtable;
        !           260:        Value* replacement_code;
1.27      paf       261: };
1.74      parser    262: #endif
1.105     paf       263: /// @todo they can do $global[$result] there, getting pointer to later-invalid local var, kill this
1.126   ! paf       264: static void replace_action(Table& table, ArrayString* row, 
        !           265:                           int prestart, int prefinish, 
        !           266:                           int poststart, int postfinish,
        !           267:                           void *info) {
1.27      paf       268:        Replace_action_info& ai=*static_cast<Replace_action_info *>(info);
1.31      paf       269:        if(row) { // begin&middle
1.104     paf       270:                // piece from last match['prestart'] to beginning of this match['prefinish']
                    271:                if(prestart!=prefinish)
                    272:                        *ai.dest << ai.src->mid(prestart, prefinish);//ai.dest->APPEND_CONST("-");
1.51      parser    273:                // store found parts in one-record VTable
1.126   ! paf       274:                if(table.count()) // middle
1.32      paf       275:                        table.put(0, row);
                    276:                else // begin
1.30      paf       277:                        table+=row;
                    278:                { // execute 'replacement_code' in 'table' context
1.105     paf       279:                        ai.vtable->set_table(table);
1.30      paf       280: 
1.105     paf       281:                        *ai.dest << ai.request->process_to_string(*ai.replacement_code);
1.29      paf       282:                }
                    283:        } else // end
1.104     paf       284:                *ai.dest << ai.src->mid(poststart, postfinish);
1.27      paf       285: }
                    286: 
1.50      parser    287: /// @todo use pcre:study somehow
1.126   ! paf       288: static void _match(Request& r, MethodParams& params) {
        !           289:        Value& regexp=params.as_no_junction(0, "regexp must not be code");
        !           290: 
        !           291:        const String* options=
        !           292:                params.count()>1?
        !           293:                &params.as_no_junction(1, "options must not be code").as_string():0;
        !           294: 
        !           295:        Temp_lang temp_lang(r, String::L_PASS_APPENDED);
        !           296:        const String& src=GET_SELF(r, VString).string();
        !           297:        bool just_matched;
        !           298:        if(params.count()<3) { // search
        !           299:                Table* table=src.match(r.charsets.source(),
1.32      paf       300:                        regexp.as_string(), options,
1.64      parser    301:                        search_action, 0,
1.126   ! paf       302:                        just_matched);
        !           303:                Value* result;
        !           304:                if(table) 
        !           305:                        result=new VTable(table); // table of pre/match/post+substrings
1.64      parser    306:                else 
1.126   ! paf       307:                        result=new VBool(just_matched);
1.102     paf       308:                r.write_assign_lang(*result);
1.27      paf       309:        } else { // replace
1.126   ! paf       310:                Value& replacement_code=params.as_junction(2, "replacement param must be code");
1.106     paf       311: 
1.126   ! paf       312:                String result;
        !           313:                VTable* vtable=new VTable;
        !           314:                Replace_action_info info={0};
        !           315:                info.request=&r;
        !           316:                info.src=&src;
        !           317:                info.dest=&result;
        !           318:                info.vtable=vtable;
        !           319:                info.replacement_code=&replacement_code;
1.105     paf       320:                Temp_value_element temp_match_var(
1.119     paf       321:                        *replacement_code.get_junction()->method_frame, 
1.126   ! paf       322:                        match_var_name, vtable);
        !           323:                src.match(r.charsets.source(),
1.99      paf       324:                        r.process_to_string(regexp), options,
1.126   ! paf       325:                        replace_action, &info,
        !           326:                        just_matched);
1.102     paf       327:                r.write_assign_lang(result);
1.27      paf       328:        }
1.24      paf       329: }
                    330: 
1.126   ! paf       331: static void change_case(Request& r, MethodParams& params, 
1.49      parser    332:                                                String::Change_case_kind kind) {
1.126   ! paf       333:        const String& src=GET_SELF(r, VString).string();
1.49      parser    334: 
1.126   ! paf       335:        r.write_assign_lang(src.change_case(r.charsets.source(), kind));
1.49      parser    336: }
1.126   ! paf       337: static void _upper(Request& r, MethodParams& params) {
        !           338:        change_case(r, params, String::CC_UPPER);
1.49      parser    339: }
1.126   ! paf       340: static void _lower(Request& r, MethodParams& params) {
        !           341:        change_case(r, params, String::CC_LOWER);
1.49      parser    342: }
                    343: 
1.65      parser    344: #ifndef DOXYGEN
1.126   ! paf       345: class String_sql_event_handlers: public SQL_Driver_query_event_handlers {
        !           346:        const String& statement_string; const char* statement_cstr;
        !           347:        bool got_column;
1.65      parser    348: public:
1.126   ! paf       349:        bool got_cell;
        !           350:        String& result;
        !           351: public:
        !           352:        String_sql_event_handlers(
        !           353:                const String& astatement_string, const char* astatement_cstr):
        !           354:                statement_string(astatement_string), statement_cstr(astatement_cstr),
        !           355:                got_column(false),
        !           356:                got_cell(false),
        !           357:                result(*new String) {}
1.65      parser    358: 
1.126   ! paf       359:        bool add_column(SQL_Error& error, const char* str, size_t /*length*/) {
1.124     paf       360:                if(got_column) {
                    361:                        error=SQL_Error("parser.runtime",
1.126   ! paf       362:                                //statement_string,
1.65      parser    363:                                "result must contain exactly one column");
1.124     paf       364:                        return true;
                    365:                }
1.65      parser    366:                got_column=true;
1.124     paf       367:                return false;
1.65      parser    368:        }
1.124     paf       369:        bool before_rows(SQL_Error& /*error*/ ) { /* ignore */ return false; }
                    370:        bool add_row(SQL_Error& /*error*/) { /* ignore */ return false; }
1.126   ! paf       371:        bool add_row_cell(SQL_Error& error, const char* str, size_t length) {
1.124     paf       372:                if(got_cell) {
                    373:                        error=SQL_Error("parser.runtime",
1.126   ! paf       374:                                //statement_string,
1.65      parser    375:                                "result must not contain more then one row");
1.124     paf       376:                        return true;
                    377:                }
1.65      parser    378: 
1.124     paf       379:                try {
                    380:                        got_cell=true;
1.126   ! paf       381:                        result.append_know_length(str, length, String::L_TAINTED);
1.124     paf       382:                        return false;
                    383:                } catch(...) {
                    384:                        error=SQL_Error("exception occured in String_sql_event_handlers::add_row_cell");
                    385:                        return true;
                    386:                }
1.65      parser    387:        }
                    388: };
                    389: #endif
1.126   ! paf       390: extern String sql_limit_name;
        !           391: extern String sql_offset_name;
        !           392: extern String sql_default_name;
        !           393: extern String sql_distinct_name;
        !           394: const String* sql_result_string(Request& r, MethodParams& params,
        !           395:                                HashStringValue*& options, Value*& default_code) {
        !           396:        Value& statement=params.as_junction(0, "statement must be code");
1.53      parser    397: 
1.70      parser    398:        ulong limit=0;
                    399:        ulong offset=0;
1.81      parser    400:        default_code=0;
1.126   ! paf       401:        if(params.count()>1) {
        !           402:                Value& voptions=params.as_no_junction(1, "options must be hash, not code");
1.115     paf       403:                if(!voptions.is_string())
1.126   ! paf       404:                        if(options=voptions.get_hash()) {
        !           405:                                if(Value* vlimit=options->get(sql_limit_name))
1.99      paf       406:                                        limit=(ulong)r.process_to_value(*vlimit).as_double();
1.126   ! paf       407:                                if(Value* voffset=options->get(sql_offset_name))
1.99      paf       408:                                        offset=(ulong)r.process_to_value(*voffset).as_double();
1.126   ! paf       409:                                if(default_code=options->get(sql_default_name)) {
        !           410:                                        if(Junction* default_junction=default_code->get_junction())
1.119     paf       411:                                                ;//default_junction->change_context(statement.get_junction());
1.110     paf       412:                                        else
1.98      paf       413:                                                throw Exception("parser.runtime",
1.126   ! paf       414:                                                        0,
1.81      parser    415:                                                        "default option must be code");
                    416:                                }
1.73      parser    417:                        } else
1.98      paf       418:                                throw Exception("parser.runtime",
1.126   ! paf       419:                                        0,
1.73      parser    420:                                        "options must be hash");
1.70      parser    421:        } else
                    422:                options=0;
                    423: 
1.126   ! paf       424:        Temp_lang temp_lang(r, String::L_SQL);
1.99      paf       425:        const String& statement_string=r.process_to_string(statement);
1.126   ! paf       426:        const char* statement_cstr=
        !           427:                statement_string.cstr(String::L_UNSPECIFIED, r.connection());
        !           428:        String_sql_event_handlers handlers(statement_string, statement_cstr);
        !           429:        r.connection()->query(
1.117     paf       430:                statement_cstr, offset, limit, 
                    431:                handlers,
                    432:                statement_string);
1.53      parser    433:        
1.65      parser    434:        if(!handlers.got_cell)
                    435:                return 0; // no lines, caller should return second param[default value]
1.62      parser    436: 
1.126   ! paf       437:        return &handlers.result;
1.53      parser    438: }
                    439: 
1.126   ! paf       440: static void _sql(Request& r, MethodParams& params) {
1.53      parser    441: 
1.126   ! paf       442:        HashStringValue* options;
        !           443:        Value* default_code;
        !           444:        const String* string=sql_result_string(r, params, options, default_code);
1.62      parser    445:        if(!string) {
1.81      parser    446:                if(default_code) {
1.99      paf       447:                        string=&r.process_to_string(*default_code);
1.68      parser    448:                } else
1.98      paf       449:                        throw Exception("parser.runtime",
1.126   ! paf       450:                                0,
1.81      parser    451:                                "produced no result, but no default option specified");
1.62      parser    452:        }
1.100     paf       453: 
1.102     paf       454:        r.write_assign_lang(*string);
1.53      parser    455: }
                    456: 
1.126   ! paf       457: static void _replace(Request& r, MethodParams& params) {
        !           458:        const String& src=GET_SELF(r, VString).string();
1.71      parser    459: 
1.126   ! paf       460:        Table* table=params.as_no_junction(0, "parameter must not be code").get_table();
1.71      parser    461:        if(!table)
1.98      paf       462:                throw Exception("parser.runtime",
1.126   ! paf       463:                        0,
1.71      parser    464:                        "parameter must be table");
                    465: 
                    466:        Dictionary dict(*table);
1.126   ! paf       467:        r.write_assign_lang(src.replace(dict));
1.71      parser    468: }
1.79      parser    469: 
1.126   ! paf       470: static void _save(Request& r, MethodParams& params) {
        !           471:        const String& file_name=params.as_string(params.count()-1, 
1.87      paf       472:                "file name must be string");
1.79      parser    473: 
1.126   ! paf       474:        const String& src=GET_SELF(r, VString).string();
1.79      parser    475: 
1.87      paf       476:        bool do_append=false;
1.126   ! paf       477:        if(params.count()>1) {
        !           478:                const String& mode=params.as_string(0, "mode must be string");
1.87      paf       479:                if(mode=="append")
                    480:                        do_append=true;
                    481:                else
1.98      paf       482:                        throw Exception("parser.runtime",
1.87      paf       483:                                &mode,
                    484:                                "unknown mode, must be 'append'");
                    485:        }               
                    486: 
1.79      parser    487:        // write
1.126   ! paf       488:        const char* buf=src.cstr(String::L_UNSPECIFIED, r.connection(false/*no error if none*/));
1.94      paf       489:        file_write(r.absolute(file_name), 
1.89      paf       490:                buf, strlen(buf), true, do_append);
1.79      parser    491: }
                    492: 
1.126   ! paf       493: static void _normalize(Request& r, MethodParams&) {
        !           494:        const String& src=GET_SELF(r, VString).string();
        !           495: 
        !           496:        r.write_assign_lang(src);
1.109     paf       497: }
                    498: 
1.41      paf       499: // constructor
                    500: 
1.126   ! paf       501: MString::MString(): Methoded("string") {
1.1       paf       502:        // ^string.length[]
1.41      paf       503:        add_native_method("length", Method::CT_DYNAMIC, _length, 0, 0);
1.6       paf       504:        
1.1       paf       505:        // ^string.int[]
1.72      parser    506:        // ^string.int(default)
                    507:        add_native_method("int", Method::CT_DYNAMIC, _int, 0, 1);
1.1       paf       508:        // ^string.double[]
1.72      parser    509:        // ^string.double(default)
                    510:        add_native_method("double", Method::CT_DYNAMIC, _double, 0, 1);
1.9       paf       511: 
1.24      paf       512:        // ^string.format{format}
1.41      paf       513:        add_native_method("format", Method::CT_DYNAMIC, _string_format, 1, 1);
1.14      paf       514: 
1.15      paf       515:        // ^string.left(n)
1.41      paf       516:        add_native_method("left", Method::CT_DYNAMIC, _left, 1, 1);
1.15      paf       517:        // ^string.right(n)
1.41      paf       518:        add_native_method("right", Method::CT_DYNAMIC, _right, 1, 1);
1.15      paf       519:        // ^string.mid(p;n)
1.82      parser    520:        add_native_method("mid", Method::CT_DYNAMIC, _mid, 1, 2);
1.16      paf       521: 
                    522:        // ^string.pos[substr]
1.41      paf       523:        add_native_method("pos", Method::CT_DYNAMIC, _pos, 1, 1);
1.17      paf       524: 
1.118     paf       525:        // ^string.split[delim]
                    526:        // ^string.split[delim][options]
                    527:        add_native_method("split", Method::CT_DYNAMIC, _split, 1, 2);
                    528:                // old names for backward compatibility
                    529:                // ^string.lsplit[delim]
                    530:                add_native_method("lsplit", Method::CT_DYNAMIC, _lsplit, 1, 1);
                    531:                // ^string.rsplit[delim]
                    532:                add_native_method("rsplit", Method::CT_DYNAMIC, _rsplit, 1, 1);
                    533:        
1.32      paf       534:        // ^string.match[regexp][options]
                    535:        // ^string.match[regexp][options]{replacement-code}
1.41      paf       536:        add_native_method("match", Method::CT_DYNAMIC, _match, 1, 3);
1.49      parser    537: 
                    538:        // ^string.toupper[]
                    539:        add_native_method("upper", Method::CT_DYNAMIC, _upper, 0, 0);
                    540:        // ^string.tolower[]
                    541:        add_native_method("lower", Method::CT_DYNAMIC, _lower, 0, 0);
1.53      parser    542: 
1.70      parser    543:        // ^sql[query]
                    544:        // ^sql[query][$.limit(1) $.offset(2) $.default[n/a]]
1.67      parser    545:        add_native_method("sql", Method::CT_STATIC, _sql, 1, 2);
1.71      parser    546: 
                    547:        // ^string.replace[table]
                    548:        add_native_method("replace", Method::CT_DYNAMIC, _replace, 1, 1);
1.79      parser    549: 
                    550:        // ^string.save[file]  
1.87      paf       551:        add_native_method("save", Method::CT_DYNAMIC, _save, 1, 2);
1.109     paf       552: 
1.112     paf       553:        // ^string.normalize[]  
                    554:        add_native_method("normalize", Method::CT_DYNAMIC, _normalize, 0, 0);
1.2       paf       555: }      

E-mail: