Pol  Revision:4b29d2b
basicmod.cpp
Go to the documentation of this file.
1 
12 #include "basicmod.h"
13 
14 #include <cstdio>
15 #include <cstdlib>
16 #include <cstring>
17 #include <picojson.h>
18 #include <string>
19 
20 #include "../../bscript/berror.h"
21 #include "../../bscript/bobject.h"
22 #include "../../bscript/dict.h"
23 #include "../../bscript/executor.h"
24 #include "../../bscript/impstr.h"
25 #include "../../clib/stlutil.h"
26 
27 namespace Pol
28 {
29 namespace Module
30 {
31 using namespace Bscript;
32 
33 static const std::string base64_chars =
34  "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
35  "abcdefghijklmnopqrstuvwxyz"
36  "0123456789+/";
37 
38 
39 static inline bool is_base64( unsigned char c )
40 {
41  return ( isalnum( c ) || ( c == '+' ) || ( c == '/' ) );
42 }
43 
45  : Bscript::TmplExecutorModule<BasicExecutorModule>( "Basic", exec )
46 {
47 }
48 
50 {
52  if ( imp->isa( Bscript::BObjectImp::OTArray ) )
53  {
54  Bscript::ObjArray* arr = static_cast<Bscript::ObjArray*>( imp );
55  return new BLong( static_cast<int>( arr->ref_arr.size() ) );
56  }
57  else if ( imp->isa( Bscript::BObjectImp::OTString ) )
58  {
59  return new BLong( static_cast<int>( imp->getStringRep().length() ) );
60  }
61  else if ( imp->isa( Bscript::BObjectImp::OTError ) )
62  {
63  BError* err = static_cast<BError*>( imp );
64  return new BLong( static_cast<int>( err->mapcount() ) );
65  }
66  else
67  {
68  return new BLong( 0 );
69  }
70 }
71 
73 {
74  exec.makeString( 0 );
75  String* str = static_cast<String*>( exec.getParamImp( 0 ) );
76  const char* s = exec.paramAsString( 1 );
77  int d = static_cast<int>( exec.paramAsLong( 2 ) );
78 
79  int posn = str->find( d ? ( d - 1 ) : 0, s ) + 1;
80 
81  return new BLong( posn );
82 }
83 
85 {
86  exec.makeString( 0 );
87  String* str = static_cast<String*>( exec.getParamImp( 0 ) );
88  int start = static_cast<int>( exec.paramAsLong( 1 ) );
89  int length = static_cast<int>( exec.paramAsLong( 2 ) );
90 
91  return str->StrStr( start, length );
92 }
93 
95 {
97  if ( !( imp->isa( Bscript::BObjectImp::OTString ) ) )
98  {
99  return new BError( "Param 1 must be a string." );
100  }
101  String* string = static_cast<String*>( imp );
102  int type = static_cast<int>( exec.paramAsLong( 1 ) );
103  const char* cset = exec.paramAsString( 2 );
104  if ( type > 3 )
105  type = 3;
106  if ( type < 1 )
107  type = 1;
108 
109  return string->ETrim( cset, type );
110 }
111 
112 /*
113 eScript Function Useage
114 
115 StrReplace(str, to_replace, replace_with);
116 */
118 {
120  std::unique_ptr<String> string( new String( imp->getStringRep().c_str() ) );
121  String* to_replace = static_cast<String*>( exec.getParamImp( 1, Bscript::BObjectImp::OTString ) );
122  if ( !to_replace )
123  return new BError( "Invalid parameter type" );
124  String* replace_with =
125  static_cast<String*>( exec.getParamImp( 2, Bscript::BObjectImp::OTString ) );
126  if ( !replace_with )
127  return new BError( "Invalid parameter type" );
128 
129  if ( string->length() < 1 )
130  return new BError( "Cannot use empty string for string haystack." );
131  if ( to_replace->length() < 1 )
132  return new BError( "Cannot use empty string for string needle." );
133 
134  string->EStrReplace( to_replace, replace_with );
135 
136  return string.release();
137 }
138 
139 // SubStrReplace(str, replace_with, start, length:=0);
141 {
143  std::unique_ptr<String> string( new String( imp->getStringRep().c_str() ) );
144  String* replace_with =
145  static_cast<String*>( exec.getParamImp( 1, Bscript::BObjectImp::OTString ) );
146  if ( !replace_with )
147  return new BError( "Invalid parameter type" );
148  int index = static_cast<int>( exec.paramAsLong( 2 ) );
149  int len = static_cast<int>( exec.paramAsLong( 3 ) );
150 
151  if ( index < 0 )
152  return new BError( "Index must not be negative" );
153  if ( static_cast<unsigned>( index - 1 ) > string->length() )
154  return new BError( "Index out of range" );
155 
156  // We set it to 1 because of doing -1 later to stay with eScript handling.
157  if ( !index )
158  index = 1;
159 
160  if ( static_cast<unsigned>( len ) > ( string->length() - index ) )
161  return new BError( "Length out of range" );
162  if ( len < 0 )
163  return new BError( "Length must not be negative" );
164 
165  if ( !len )
166  len = static_cast<int>( replace_with->length() - index );
167 
168  string->ESubStrReplace( replace_with, static_cast<unsigned>( index ),
169  static_cast<unsigned>( len ) );
170 
171  return string.release();
172 }
173 
174 // OMG I HATED THIS REQUEST. Ugly code, but necessary for all the checks
175 // just in case someone's code is bugged :(
177 {
178  std::string str1 = exec.paramAsString( 0 );
179  std::string str2 = exec.paramAsString( 1 );
180  int pos1_index = static_cast<int>( exec.paramAsLong( 2 ) );
181  int pos1_len = static_cast<int>( exec.paramAsLong( 3 ) );
182  int pos2_index = static_cast<int>( exec.paramAsLong( 4 ) );
183  int pos2_len = static_cast<int>( exec.paramAsLong( 5 ) );
184 
185  if ( pos1_index != 0 )
186  {
187  if ( pos1_index < 0 )
188  return new BError( "Index must not be negative for param 1" );
189  if ( static_cast<unsigned>( pos1_index - 1 ) > str1.length() )
190  return new BError( "Index out of range for param 1" );
191  }
192  if ( pos2_index != 0 )
193  {
194  if ( pos2_index < 0 )
195  return new BError( "Index must not be negative for param 2" );
196  if ( static_cast<unsigned>( pos2_index - 1 ) > str2.length() )
197  return new BError( "Index out of range for param 2" );
198  }
199 
200 
201  if ( pos1_len < 0 )
202  return new BError( "Length must not be negative for param 1" );
203  if ( static_cast<unsigned>( pos1_len ) > ( str1.length() - pos1_index ) )
204  return new BError( "Length out of range for param 1" );
205  if ( pos2_len < 0 )
206  return new BError( "Length must not be negative for param 2" );
207  if ( static_cast<unsigned>( pos2_len ) > ( str2.length() - pos2_index ) )
208  return new BError( "Length out of range for param 2" );
209 
210 
211  if ( pos1_index == 0 )
212  {
213  unsigned int result = str1.compare( str2 );
214  if ( result != 0 )
215  return new BLong( 0 );
216  else
217  return new BLong( 1 );
218  }
219  else if ( pos1_index > 0 && pos2_index == 0 )
220  {
221  unsigned int result = str1.compare( pos1_index - 1, pos1_len, str2 );
222  if ( result != 0 )
223  return new BLong( 0 );
224  else
225  return new BLong( 1 );
226  }
227  else
228  {
229  unsigned int result = str1.compare( pos1_index - 1, pos1_len, str2, pos2_index - 1, pos2_len );
230  if ( result != 0 )
231  return new BLong( 0 );
232  else
233  return new BLong( 1 );
234  }
235 }
236 
238 {
239  String* string = new String( exec.paramAsString( 0 ) );
240  string->toLower();
241  return string;
242 }
243 
245 {
246  String* string = new String( exec.paramAsString( 0 ) );
247  string->toUpper();
248  return string;
249 }
250 
252 {
254  if ( imp->isa( Bscript::BObjectImp::OTLong ) )
255  {
256  return imp->copy();
257  }
258  else if ( imp->isa( Bscript::BObjectImp::OTString ) )
259  {
260  String* str = static_cast<String*>( imp );
261  return new BLong( strtoul( str->data(), nullptr, 0 ) );
262  }
263  else if ( imp->isa( Bscript::BObjectImp::OTDouble ) )
264  {
265  Double* dbl = static_cast<Double*>( imp );
266  return new BLong( static_cast<int>( dbl->value() ) );
267  }
268  else
269  {
270  return new BLong( 0 );
271  }
272 }
273 
275 {
277  if ( imp->isa( Bscript::BObjectImp::OTLong ) )
278  {
279  BLong* lng = static_cast<BLong*>( imp );
280  return new Double( lng->value() );
281  }
282  else if ( imp->isa( Bscript::BObjectImp::OTString ) )
283  {
284  String* str = static_cast<String*>( imp );
285  return new Double( strtod( str->data(), nullptr ) );
286  }
287  else if ( imp->isa( Bscript::BObjectImp::OTDouble ) )
288  {
289  return imp->copy();
290  }
291  else
292  {
293  return new Double( 0 );
294  }
295 }
296 
298 {
300  return new String( imp->getStringRep() );
301 }
302 
304 {
306  if ( imp->isa( Bscript::BObjectImp::OTString ) )
307  {
308  String* str = static_cast<String*>( imp );
309  return new BLong( static_cast<unsigned char>( str->data()[0] ) );
310  }
311  else
312  {
313  return new BError( "Invalid parameter type" );
314  }
315 }
316 
318 {
320  std::string tmp = imp->getStringRep();
321  int nullterm = static_cast<int>( exec.paramAsLong( 1 ) );
322  std::unique_ptr<Bscript::ObjArray> arr( new Bscript::ObjArray );
323  for ( size_t i = 0; i < tmp.size(); ++i )
324  {
325  arr->addElement( new BLong( static_cast<unsigned char>( tmp[i] ) ) );
326  }
327  if ( nullterm )
328  arr->addElement( new BLong( 0 ) );
329 
330  return arr.release();
331 }
332 
334 {
335  int val;
336  if ( getParam( 0, val ) )
337  {
338  char s[2];
339  s[0] = static_cast<char>( val );
340  s[1] = '\0';
341  return new String( s );
342  }
343  else
344  {
345  return new BError( "Invalid parameter type" );
346  }
347 }
348 
350 {
351  std::string res;
352  Bscript::ObjArray* arr =
354  int break_first_null = static_cast<int>( exec.paramAsLong( 1 ) );
355  if ( !arr )
356  return new BError( "Invalid parameter type" );
357  for ( Bscript::ObjArray::const_iterator itr = arr->ref_arr.begin(), itrend = arr->ref_arr.end();
358  itr != itrend; ++itr )
359  {
360  BObject* bo = ( itr->get() );
361  if ( bo == nullptr )
362  continue;
363  Bscript::BObjectImp* imp = bo->impptr();
364  if ( imp )
365  {
366  if ( imp->isa( Bscript::BObjectImp::OTLong ) )
367  {
368  BLong* blong = static_cast<BLong*>( imp );
369  if ( break_first_null && blong->value() == 0 )
370  break;
371  char s[2];
372  s[0] = static_cast<char>( blong->value() );
373  s[1] = '\0';
374  res += s;
375  }
376  }
377  }
378  return new String( res );
379 }
380 
382 {
384  if ( imp->isa( Bscript::BObjectImp::OTLong ) )
385  {
386  BLong* plong = static_cast<BLong*>( imp );
387  char s[20];
388  sprintf( s, "0x%X", static_cast<unsigned int>( plong->value() ) );
389  return new String( s );
390  }
391  else if ( imp->isa( Bscript::BObjectImp::OTDouble ) )
392  {
393  Double* pdbl = static_cast<Double*>( imp );
394  char s[20];
395  sprintf( s, "0x%X", static_cast<unsigned int>( pdbl->value() ) );
396  return new String( s );
397  }
398  else if ( imp->isa( Bscript::BObjectImp::OTString ) )
399  {
400  String* str = static_cast<String*>( imp );
401  char s[20];
402  sprintf( s, "0x%X", static_cast<unsigned int>( strtoul( str->data(), nullptr, 0 ) ) );
403  return new String( s );
404  }
405  else
406  {
407  return new BError( "Hex() expects an Integer, Real, or String" );
408  }
409 }
410 
411 #ifdef __unix__
412 char* itoa( int value, char* result, int base )
413 {
414  // check that the base is valid
415  if ( base < 2 || base > 16 )
416  {
417  *result = 0;
418  return result;
419  }
420 
421  char* out = result;
422  int quotient = value;
423 
424  do
425  {
426  *out = "0123456789abcdef"[std::abs( quotient % base )];
427  ++out;
428  quotient /= base;
429  } while ( quotient );
430 
431  // Only apply negative sign for base 10
432  if ( value < 0 && base == 10 )
433  *out++ = '-';
434 
435  std::reverse( result, out );
436  *out = 0;
437  return result;
438 }
439 #endif
440 
442 {
444  if ( imp->isa( Bscript::BObjectImp::OTLong ) )
445  {
446  BLong* plong = static_cast<BLong*>( imp );
447  int number = plong->value();
448  char buffer[sizeof( int ) * 8 + 1];
449  return new String( itoa( number, buffer, 2 ) );
450  }
451  else
452  {
453  return new BError( "Bin() expects an Integer" );
454  }
455 }
456 
458 {
459  Bscript::BObjectImp* bimp_split = exec.getParamImp( 0 );
460  std::string source = bimp_split->getStringRep();
461 
462  const String* bimp_delimiter;
463  if ( !exec.getStringParam( 1, bimp_delimiter ) )
464  {
465  return new BError( "Invalid parameter type." );
466  }
467  std::string delimiter = bimp_delimiter->getStringRep();
468 
469  // max_split parameter
470  int max_split = -1;
471  int count = 0;
472 
473  if ( exec.hasParams( 3 ) )
474  {
475  max_split = static_cast<int>( exec.paramAsLong( 2 ) );
476  }
477 
478  std::unique_ptr<Bscript::ObjArray> objarr( new Bscript::ObjArray );
479 
480  // Support for how it previously worked.
481  // Kept to support spaces and tabs as the same.
482  if ( delimiter == " " )
483  {
484  ISTRINGSTREAM is( source );
485  std::string tmp;
486  std::streamoff tellg = -1;
487  bool splitted = false;
488 
489  while ( is >> tmp )
490  {
491  tellg = is.tellg();
492  if ( count == max_split && tellg != -1 )
493  { // added max_split parameter
494  splitted = true;
495  break;
496  }
497  objarr->addElement( new String( tmp ) );
498  tmp = "";
499  count += 1;
500  }
501 
502  // Merges the remaining of the string
503  if ( splitted )
504  {
505  std::string remaining_string;
506  remaining_string = source.substr( tellg - tmp.length(), source.length() );
507  objarr->addElement( new String( remaining_string ) );
508  }
509 
510  return objarr.release();
511  }
512 
513  // New delimiter support.
514  std::string new_string = source;
515  std::string::size_type found;
516  do
517  {
518  found = new_string.find( delimiter, 0 );
519  if ( found == std::string::npos )
520  break;
521  else if ( count == max_split )
522  { // added max_split parameter
523  break;
524  }
525 
526  std::string add_string = new_string.substr( 0, found );
527 
528  // Shinigami: will not hang server on queue of delimiter
529  // if ( add_string.empty() )
530  // continue;
531 
532  objarr->addElement( new String( add_string ) );
533  std::string tmp_string = new_string.substr( found + delimiter.length(), new_string.length() );
534  new_string = tmp_string;
535  count += 1;
536  } while ( found != std::string::npos );
537 
538  // Catch leftovers here.
539  if ( !new_string.empty() )
540  objarr->addElement( new String( new_string ) );
541 
542  return objarr.release();
543 }
544 
546 {
548  return new String( imp->pack() );
549 }
550 
552 {
553  const String* str;
554 
555  if ( exec.getStringParam( 0, str ) )
556  {
557  return Bscript::BObjectImp::unpack( str->data() );
558  }
559  else
560  {
561  return new BError( "Invalid parameter type" );
562  }
563 }
565 {
567  return new String( imp->typeOf() );
568 }
570 {
572  return new BLong( static_cast<int>( imp->sizeEstimate() ) );
573 }
575 {
576  BObjectImp* imp = exec.getParamImp( 0 );
577  return new BLong( imp->typeOfInt() );
578 }
579 
580 picojson::value recurseE2J( BObjectImp* v )
581 {
582  if ( v->isa( BObjectImp::OTString ) )
583  {
584  return picojson::value( v->getStringRep() );
585  }
586  else if ( v->isa( BObjectImp::OTLong ) )
587  {
588  int intVal = static_cast<BLong*>( v )->value();
589  return picojson::value( static_cast<double>( intVal ) );
590  }
591  else if ( v->isa( BObjectImp::OTDouble ) )
592  {
593  return picojson::value( static_cast<Double*>( v )->value() );
594  }
595  else if ( v->isa( BObjectImp::OTBoolean ) )
596  {
597  return picojson::value( static_cast<BBoolean*>( v )->value() );
598  }
599  else if ( v->isa( BObjectImp::OTArray ) )
600  {
601  ObjArray* arr = static_cast<ObjArray*>( v );
602  picojson::array jsonArr;
603 
604  for ( const auto& elem : arr->ref_arr )
605  {
606  BObject* bo = elem.get();
607  if ( bo == nullptr )
608  continue;
609  BObjectImp* imp = bo->impptr();
610  jsonArr.push_back( recurseE2J( imp ) );
611  }
612  return picojson::value( jsonArr );
613  }
614  else if ( v->isa( BObjectImp::OTStruct ) )
615  {
616  BStruct* bstruct = static_cast<BStruct*>( v );
617  picojson::object jsonObj;
618  for ( const auto& content : bstruct->contents() )
619  {
620  BObjectImp* imp = content.second->impptr();
621  jsonObj.insert( std::pair<std::string, picojson::value>( content.first, recurseE2J( imp ) ) );
622  }
623  return picojson::value( jsonObj );
624  }
625  else if ( v->isa( BObjectImp::OTDictionary ) )
626  {
627  BDictionary* cpropdict = static_cast<Bscript::BDictionary*>( v );
628  picojson::object jsonObj;
629  for ( const auto& content : cpropdict->contents() )
630  {
631  BObjectImp* imp = content.second->impptr();
632  jsonObj.insert( std::pair<std::string, picojson::value>( content.first->getStringRep(),
633  recurseE2J( imp ) ) );
634  }
635  return picojson::value( jsonObj );
636  }
637  return picojson::value();
638 }
640 {
641  BObjectImp* imp = exec.getParamImp( 0 );
642  return new String( recurseE2J( imp ).serialize() );
643 }
644 
645 
646 Bscript::BObjectImp* recurseJ2E( const picojson::value& v )
647 {
648  if ( v.is<std::string>() )
649  {
650  return new String( v.get<std::string>() );
651  }
652  else if ( v.is<double>() )
653  {
654  // Possible improvement: separate into BLong and Double
655  return new Double( v.get<double>() );
656  }
657  else if ( v.is<bool>() )
658  {
659  return new BBoolean( v.get<bool>() );
660  }
661  else if ( v.is<picojson::array>() )
662  {
663  std::unique_ptr<ObjArray> objarr( new ObjArray );
664  const picojson::array& arr = v.get<picojson::array>();
665  for ( const auto& elem : arr )
666  {
667  objarr->addElement( recurseJ2E( elem ) );
668  }
669  return objarr.release();
670  }
671  else if ( v.is<picojson::object>() )
672  {
673  std::unique_ptr<BStruct> objstruct( new BStruct );
674  for ( const auto& content : v.get<picojson::object>() )
675  {
676  objstruct->addMember( content.first.c_str(), recurseJ2E( content.second ) );
677  }
678  return objstruct.release();
679  }
680  else
681  return UninitObject::create();
682 }
683 
685 {
686  const String* str;
687 
688  if ( exec.getStringParam( 0, str ) )
689  {
690  picojson::value v;
691  std::string err = picojson::parse( v, str->data() );
692  if ( !err.empty() )
693  {
694  return new BError( err );
695  }
696  return recurseJ2E( v );
697  }
698  else
699  {
700  return new BError( "Invalid parameter type" );
701  }
702 }
703 
705 {
707  if ( imp->isa( Bscript::BObjectImp::OTLong ) )
708  {
709  BLong* plong = static_cast<BLong*>( imp );
710  return new BBoolean( plong->value() != 0 );
711  }
712  else if ( imp->isa( Bscript::BObjectImp::OTBoolean ) )
713  {
714  return new BBoolean( *static_cast<BBoolean*>( imp ) );
715  }
716  else
717  {
718  return new BError( "Boolean() expects an Integer or Boolean" );
719  }
720 }
721 
722 /*
723 Base64 encode/decode snippit by Rene Nyffenegger rene.nyffenegger@adp-gmbh.ch
724 Copyright (C) 2004-2008 Rene Nyffenegger
725 */
727 {
728  std::string encoded_string = exec.paramAsString( 0 );
729 
730  if ( encoded_string.empty() )
731  return new BError( "Invalid parameter type" );
732 
733  unsigned int in_len = static_cast<unsigned int>( encoded_string.length() );
734 
735  unsigned char const* bytes_to_encode =
736  reinterpret_cast<const unsigned char*>( encoded_string.c_str() );
737  std::string ret;
738  int i = 0;
739  int j = 0;
740  unsigned char char_array_3[3];
741  unsigned char char_array_4[4];
742 
743  while ( in_len-- )
744  {
745  char_array_3[i++] = *( bytes_to_encode++ );
746  if ( i == 3 )
747  {
748  char_array_4[0] = ( char_array_3[0] & 0xfc ) >> 2;
749  char_array_4[1] = ( ( char_array_3[0] & 0x03 ) << 4 ) + ( ( char_array_3[1] & 0xf0 ) >> 4 );
750  char_array_4[2] = ( ( char_array_3[1] & 0x0f ) << 2 ) + ( ( char_array_3[2] & 0xc0 ) >> 6 );
751  char_array_4[3] = char_array_3[2] & 0x3f;
752 
753  for ( i = 0; ( i < 4 ); i++ )
754  ret += base64_chars[char_array_4[i]];
755  i = 0;
756  }
757  }
758 
759  if ( i )
760  {
761  for ( j = i; j < 3; j++ )
762  char_array_3[j] = '\0';
763 
764  char_array_4[0] = ( char_array_3[0] & 0xfc ) >> 2;
765  char_array_4[1] = ( ( char_array_3[0] & 0x03 ) << 4 ) + ( ( char_array_3[1] & 0xf0 ) >> 4 );
766  char_array_4[2] = ( ( char_array_3[1] & 0x0f ) << 2 ) + ( ( char_array_3[2] & 0xc0 ) >> 6 );
767  char_array_4[3] = char_array_3[2] & 0x3f;
768 
769  for ( j = 0; ( j < i + 1 ); j++ )
770  ret += base64_chars[char_array_4[j]];
771 
772  while ( ( i++ < 3 ) )
773  ret += '=';
774  }
775 
776  return new String( ret );
777 }
778 
780 {
781  std::string encoded_string = exec.paramAsString( 0 );
782 
783  if ( encoded_string.empty() )
784  return new BError( "Invalid parameter type" );
785 
786  int in_len = static_cast<int>( encoded_string.size() );
787  int i = 0;
788  int j = 0;
789  int in_ = 0;
790  unsigned char char_array_4[4], char_array_3[3];
791  std::string ret;
792 
793  while ( in_len-- && ( encoded_string[in_] != '=' ) && is_base64( encoded_string[in_] ) )
794  {
795  char_array_4[i++] = encoded_string[in_];
796  in_++;
797  if ( i == 4 )
798  {
799  for ( i = 0; i < 4; i++ )
800  char_array_4[i] = static_cast<u8>( base64_chars.find( char_array_4[i] ) );
801 
802  char_array_3[0] = ( char_array_4[0] << 2 ) + ( ( char_array_4[1] & 0x30 ) >> 4 );
803  char_array_3[1] = ( ( char_array_4[1] & 0xf ) << 4 ) + ( ( char_array_4[2] & 0x3c ) >> 2 );
804  char_array_3[2] = ( ( char_array_4[2] & 0x3 ) << 6 ) + char_array_4[3];
805 
806  for ( i = 0; ( i < 3 ); i++ )
807  ret += char_array_3[i];
808  i = 0;
809  }
810  }
811 
812  if ( i )
813  {
814  for ( j = i; j < 4; j++ )
815  char_array_4[j] = 0;
816 
817  for ( j = 0; j < 4; j++ )
818  char_array_4[j] = static_cast<u8>( base64_chars.find( char_array_4[j] ) );
819 
820  char_array_3[0] = ( char_array_4[0] << 2 ) + ( ( char_array_4[1] & 0x30 ) >> 4 );
821  char_array_3[1] = ( ( char_array_4[1] & 0xf ) << 4 ) + ( ( char_array_4[2] & 0x3c ) >> 2 );
822  char_array_3[2] = ( ( char_array_4[2] & 0x3 ) << 6 ) + char_array_4[3];
823 
824  for ( j = 0; ( j < i - 1 ); j++ )
825  ret += char_array_3[j];
826  }
827 
828  return new String( ret );
829 }
830 } // namespace Module
831 
832 namespace Bscript
833 {
834 using namespace Module;
835 template <>
838  {"find", &BasicExecutorModule::find},
839  {"len", &BasicExecutorModule::len},
840  {"upper", &BasicExecutorModule::upper},
841  {"lower", &BasicExecutorModule::lower},
842  {"Substr", &BasicExecutorModule::mf_substr},
843  {"Trim", &BasicExecutorModule::mf_Trim},
844  {"StrReplace", &BasicExecutorModule::mf_StrReplace},
845  {"SubStrReplace", &BasicExecutorModule::mf_SubStrReplace},
846  {"Compare", &BasicExecutorModule::mf_Compare},
847  {"CInt", &BasicExecutorModule::mf_CInt},
848  {"CStr", &BasicExecutorModule::mf_CStr},
849  {"CDbl", &BasicExecutorModule::mf_CDbl},
850  {"CAsc", &BasicExecutorModule::mf_CAsc},
851  {"CChr", &BasicExecutorModule::mf_CChr},
852  {"CAscZ", &BasicExecutorModule::mf_CAscZ},
853  {"CChrZ", &BasicExecutorModule::mf_CChrZ},
854  {"Bin", &BasicExecutorModule::mf_Bin},
855  {"Hex", &BasicExecutorModule::mf_Hex},
856  {"SplitWords", &BasicExecutorModule::mf_SplitWords},
857  {"Pack", &BasicExecutorModule::mf_Pack},
858  {"Unpack", &BasicExecutorModule::mf_Unpack},
859  {"TypeOf", &BasicExecutorModule::mf_TypeOf},
860  {"SizeOf", &BasicExecutorModule::mf_SizeOf},
861  {"TypeOfInt", &BasicExecutorModule::mf_TypeOfInt},
862  {"Boolean", &BasicExecutorModule::mf_Boolean},
863  {"PackJSON", &BasicExecutorModule::mf_PackJSON},
864  {"UnpackJSON", &BasicExecutorModule::mf_UnpackJSON},
865  {"EncodeBase64", &BasicExecutorModule::mf_EncodeBase64},
866  {"DecodeBase64", &BasicExecutorModule::mf_DecodeBase64}};
867 } // namespace Bscript
868 } // namespace Pol
Bscript::BObjectImp * mf_Trim()
Definition: basicmod.cpp:94
virtual std::string getStringRep() const =0
size_t mapcount() const
Definition: bstruct.cpp:190
Bscript::BObjectImp * mf_Compare()
Definition: basicmod.cpp:176
static bool is_base64(unsigned char c)
Definition: basicmod.cpp:39
int value() const
Definition: bobject.h:592
Bscript::BObjectImp * lower()
Definition: basicmod.cpp:237
int find(int begin, const char *target)
Definition: str.cpp:170
bool isa(BObjectType type) const
Definition: bobject.h:353
Bscript::BObjectImp * mf_TypeOfInt()
Definition: basicmod.cpp:574
Bscript::BObjectImp * len()
Definition: basicmod.cpp:49
Bscript::BObjectImp * mf_SplitWords()
Definition: basicmod.cpp:457
unsigned int release()
Definition: refptr.h:126
bool getParam(unsigned param, int &value)
Definition: execmodl.cpp:62
Bscript::BObjectImp * mf_Boolean()
Definition: basicmod.cpp:704
Bscript::BObjectImp * mf_StrReplace()
Definition: basicmod.cpp:117
virtual std::string getStringRep() const POL_OVERRIDE
Definition: impstr.h:129
const Contents & contents() const
Definition: bstruct.cpp:466
Bscript::BObjectImp * upper()
Definition: basicmod.cpp:244
int makeString(unsigned param)
Definition: executor.cpp:196
virtual BObjectImp * copy() const =0
virtual u8 typeOfInt() const
Definition: object.cpp:263
Bscript::BObjectImp * mf_PackJSON()
Definition: basicmod.cpp:639
int paramAsLong(unsigned param)
Definition: executor.cpp:240
Bscript::BObjectImp * recurseJ2E(const picojson::value &v)
Definition: basicmod.cpp:646
const char * paramAsString(unsigned param)
Definition: executor.cpp:209
void toUpper(void)
Definition: str.cpp:368
Bscript::BObjectImp * mf_TypeOf()
Definition: basicmod.cpp:564
virtual std::string pack() const
Definition: object.cpp:201
Bscript::BObjectImp * mf_EncodeBase64()
Definition: basicmod.cpp:726
Cont::const_iterator const_iterator
Definition: bobject.h:509
unsigned char buffer[10000]
Definition: UoToolMain.cpp:109
picojson::value recurseE2J(BObjectImp *v)
Definition: basicmod.cpp:580
Bscript::BObjectImp * mf_CStr()
Definition: basicmod.cpp:297
Bscript::BObjectImp * mf_Pack()
Definition: basicmod.cpp:545
static const std::string base64_chars
Definition: basicmod.cpp:33
static UninitObject * create()
Definition: bobject.h:482
BasicExecutorModule(Bscript::Executor &exec)
Definition: basicmod.cpp:44
static BObjectImp * unpack(const char *pstr)
Definition: object.cpp:120
Bscript::BObjectImp * find()
Definition: basicmod.cpp:72
Bscript::BObjectImp * mf_CAscZ()
Definition: basicmod.cpp:317
Bscript::BObjectImp * mf_SubStrReplace()
Definition: basicmod.cpp:140
String * StrStr(int begin, int len)
Definition: str.cpp:37
Bscript::BObjectImp * mf_CDbl()
Definition: basicmod.cpp:274
Bscript::BObjectImp * mf_UnpackJSON()
Definition: basicmod.cpp:684
Bscript::BObjectImp * mf_CChrZ()
Definition: basicmod.cpp:349
#define ISTRINGSTREAM
Definition: stlutil.h:73
const Contents & contents() const
Definition: dict.cpp:435
const String * getStringParam(unsigned param)
Definition: executor.cpp:347
Bscript::BObjectImp * mf_DecodeBase64()
Definition: basicmod.cpp:779
Bscript::BObjectImp * mf_CChr()
Definition: basicmod.cpp:333
Bscript::BObjectImp * mf_substr()
Definition: basicmod.cpp:84
bool hasParams(unsigned howmany) const
Definition: executor.h:144
virtual size_t sizeEstimate() const =0
void toLower(void)
Definition: str.cpp:376
double value() const
Definition: bobject.h:713
Bscript::BObjectImp * mf_Unpack()
Definition: basicmod.cpp:551
const char * data() const
Definition: impstr.h:66
Bscript::BObjectImp * mf_Bin()
Definition: basicmod.cpp:441
Bscript::BObjectImp * mf_CInt()
Definition: basicmod.cpp:251
Definition: berror.cpp:12
Bscript::BObjectImp * mf_SizeOf()
Definition: basicmod.cpp:569
virtual const char * typeOf() const
Definition: object.cpp:257
Bscript::BObjectImp * mf_CAsc()
Definition: basicmod.cpp:303
size_t length() const
Definition: impstr.h:68
Bscript::BObjectImp * mf_Hex()
Definition: basicmod.cpp:381
BObjectImp * getParamImp(unsigned param)
Definition: executor.cpp:266