|
|
| version 1.263, 2025/10/05 19:41:27 | version 1.267, 2026/04/25 13:38:46 |
|---|---|
| Line 1 | Line 1 |
| /** @file | /** @file |
| Parser: @b string parser class. | Parser: @b string parser class. |
| Copyright (c) 2001-2024 Art. Lebedev Studio (http://www.artlebedev.com) | Copyright (c) 2001-2026 Art. Lebedev Studio (https://www.artlebedev.com) |
| Authors: Konstantin Morshnev <moko@design.ru>, Alexandr Petrosian <paf@design.ru> | Authors: Konstantin Morshnev <moko@design.ru>, Alexandr Petrosian <paf@design.ru> |
| */ | */ |
| Line 65 static const String match_var_name(MATCH | Line 65 static const String match_var_name(MATCH |
| // methods | // methods |
| static void _length(Request& r, MethodParams&) { | static void _length(Request& r, MethodParams&) { |
| double result=GET_SELF(r, VString).string().length(r.charsets.source()); | double result=(double)GET_SELF(r, VString).string().length(r.charsets.source()); |
| r.write(*new VDouble(result)); | r.write(*new VDouble(result)); |
| } | } |
| static void _int(Request& r, MethodParams& params) { | static void _int(Request& r, MethodParams& params) { |
| const String& self_string=GET_SELF(r, VString).string(); | const String& self_string=GET_SELF(r, VString).string(); |
| int converted; | |
| if(self_string.is_empty()) { | if(self_string.is_empty()) { |
| if(params.count()>0) | if(params.count()>0) |
| converted=params.as_int(0, "default must be int", r); // (default) | r.write(*new VInt(params.as_wint(0, "default must be int", r))); // (default) |
| else | else |
| throw Exception(PARSER_RUNTIME, 0, "unable to convert empty string without default specified"); | throw Exception(PARSER_RUNTIME, 0, "unable to convert empty string without default specified"); |
| } else { | } else { |
| try { | try { |
| converted=self_string.as_int(); | r.write(*new VInt(self_string.as_wint())); |
| } catch(...) { // convert problem | } catch(...) { // convert problem |
| if(params.count()>0) | if(params.count()>0) |
| converted=params.as_int(0, "default must be int", r); // (default) | r.write(*new VInt(params.as_wint(0, "default must be int", r))); // (default) |
| else | else |
| rethrow; // we have a problem when no default | rethrow; // we have a problem when no default |
| } | } |
| } | } |
| r.write(*new VInt(converted)); | |
| } | } |
| static void _double(Request& r, MethodParams& params) { | static void _double(Request& r, MethodParams& params) { |