15 #include "../clib/stlutil.h" 27 #pragma warning( disable : 4244 ) 49 size_t startpos = tmp.find_first_not_of( CRSet );
50 if ( std::string::npos != startpos )
51 tmp = tmp.substr( startpos );
59 size_t endpos = tmp.find_last_not_of( CRSet );
60 if ( std::string::npos != endpos )
61 tmp = tmp.substr( 0, endpos + 1 );
69 size_t startpos = tmp.find_first_not_of( CRSet );
71 size_t endpos = tmp.find_last_not_of( CRSet );
74 if ( ( std::string::npos == startpos ) || ( std::string::npos == endpos ) )
77 tmp = tmp.substr( startpos, endpos - startpos + 1 );
86 std::string::size_type valpos = 0;
87 while ( std::string::npos != ( valpos =
value_.find( str1->
value_, valpos ) ) )
110 os <<
"S" << value.size() <<
":" <<
value;
115 return new String( pstr );
130 if ( !( is >> len >> colon ) )
132 return new BError(
"Unable to unpack string length." );
136 return new BError(
"Unable to unpack string length. Invalid length!" );
140 return new BError(
"Unable to unpack string length. Bad format. Colon not found!" );
143 is.unsetf( std::ios::skipws );
149 if ( !( is >> ch ) || ch ==
'\0' )
151 return new BError(
"Unable to unpack string length. String length excessive." );
156 is.setf( std::ios::skipws );
173 std::string::size_type pos;
174 pos =
value_.find( target, begin );
175 if ( pos == std::string::npos )
178 return static_cast<int>( pos );
185 while ( isalnum(
value_[c] ) )
194 int strlen =
static_cast<int>( this->
length() );
195 for (
int i = 0; i < strlen; i++ )
197 unsigned char tmp =
value_[i];
198 if ( isalnum( tmp ) )
200 else if ( ispunct( tmp ) )
202 if ( tmp ==
'{' || tmp ==
'}' )
279 size_t len = strlen( rm );
281 auto pos =
value_.find( rm );
282 if ( pos != std::string::npos )
338 remove( objimp.
value_.data() );
348 return (
value_ == static_cast<const String&>( objimp ).value_ );
358 return (
value_ < static_cast<const String&>( objimp ).value_ );
386 std::string::size_type pos, len;
398 pos = lng.
value() - 1;
404 pos =
static_cast<std::string::size_type
>( dbl.
value() );
412 if ( pos != std::string::npos )
434 BObject& length_obj = *length_ref;
435 BObject& start_obj = *start_ref;
445 index = (unsigned)lng.
value();
446 if ( index == 0 || index >
value_.size() )
452 std::string::size_type pos =
value_.find( rtstr.
value_ );
453 if ( pos != std::string::npos )
454 index =
static_cast<unsigned int>( pos + 1 );
469 len = (int)lng.
value();
475 len = (int)dbl.
value();
503 BObject& length_obj = *length_ref;
504 BObject& start_obj = *start_ref;
514 index = (unsigned)lng.
value();
515 if ( index == 0 || index >
value_.size() )
521 std::string::size_type pos =
value_.find( rtstr.
value_ );
522 if ( pos != std::string::npos )
523 index =
static_cast<unsigned int>( pos + 1 );
538 len = (int)lng.
value();
544 len = (int)dbl.
value();
562 if ( lng.
value() < 0 )
565 unsigned index = (unsigned)lng.
value();
567 if ( index == 0 || index >
value_.size() )
576 if ( dbl.
value() < 0 )
578 unsigned index = (unsigned)dbl.
value();
580 if ( index == 0 || index >
value_.size() )
589 if ( pos != std::string::npos )
608 i = strtol( s.c_str(), &end, 10 );
623 std::stringstream trimmer;
632 for ( i = 31; i > 0; i-- )
634 if ( value & ( 1 << i ) )
637 for ( ; i >= 0; i-- )
639 if ( value & ( 1 << i ) )
655 if ( frmt.find(
'b' ) != std::string::npos )
659 to_stream <<
"<needs Int>";
663 int n = plong->
value();
664 if ( frmt.find(
'#' ) != std::string::npos )
665 to_stream << ( ( n < 0 ) ?
"-" :
"" ) <<
"0b";
668 else if ( frmt.find(
'x' ) != std::string::npos )
672 to_stream <<
"<needs Int>";
676 int n = plong->
value();
677 if ( frmt.find(
'#' ) != std::string::npos )
679 to_stream << std::hex << n << std::dec;
681 else if ( frmt.find(
'o' ) != std::string::npos )
685 to_stream <<
"<needs Int>";
689 int n = plong->
value();
690 if ( frmt.find(
'#' ) != std::string::npos )
692 to_stream << std::oct << n << std::dec;
694 else if ( frmt.find(
'd' ) != std::string::npos )
705 n = (int)pdbl->
value();
709 to_stream <<
"<needs Int, Double>";
712 to_stream << std::dec << n;
716 to_stream <<
"<bad format: " << frmt <<
">";
726 if ( objmethod != NULL )
737 return new BLong( static_cast<int>(
value_.length() ) );
739 return new BError(
"string.length() doesn't take parameters." );
744 return new BError(
"string.find(Search, [Start]) takes only two parameters" );
746 return new BError(
"string.find(Search, [Start]) takes at least one parameter" );
751 int posn =
find( d ? ( d - 1 ) : 0, s ) + 1;
752 return new BLong( posn );
762 return new BError(
"string.upper() doesn't take parameters." );
773 return new BError(
"string.lower() doesn't take parameters." );
780 std::stringstream result;
782 size_t tag_start_pos;
789 unsigned int next_param_idx = 0;
791 char w_spaces[] =
"\t ";
794 bool last_tag_was_int =
true;
796 while ( ( tag_start_pos =
value_.find(
'{', str_pos ) ) != std::string::npos )
798 if ( ( tag_stop_pos =
value_.find(
'}', tag_start_pos ) ) != std::string::npos )
800 result <<
value_.substr( str_pos, tag_start_pos - str_pos );
801 str_pos = tag_stop_pos + 1;
803 std::string tag_body =
804 value_.substr( tag_start_pos + 1, ( tag_stop_pos - tag_start_pos ) - 1 );
806 tag_start_pos = tag_body.find_first_not_of( w_spaces );
807 tag_stop_pos = tag_body.find_last_not_of( w_spaces );
812 if ( tag_start_pos != std::string::npos && tag_stop_pos != std::string::npos )
813 tag_body = tag_body.substr( tag_start_pos, ( tag_stop_pos - tag_start_pos ) + 1 );
814 else if ( tag_start_pos != std::string::npos )
815 tag_body = tag_body.substr( tag_start_pos );
816 else if ( tag_stop_pos != std::string::npos )
817 tag_body = tag_body.substr( 0, tag_stop_pos + 1 );
824 size_t formatter_pos = tag_body.find(
':' );
826 if ( formatter_pos != std::string::npos )
828 frmt = tag_body.substr( formatter_pos + 1, std::string::npos );
829 tag_body = tag_body.substr( 0, formatter_pos );
832 std::string prop_name;
834 tag_dot_pos = tag_body.find(
'.', 0 );
837 if ( tag_dot_pos != std::string::npos )
839 last_tag_was_int =
true;
840 prop_name = tag_body.substr( tag_dot_pos + 1, std::string::npos );
841 tag_body = tag_body.substr( 0, tag_dot_pos );
850 result <<
"<idx required before: '" << prop_name <<
"'>";
856 if ( tag_body ==
"" )
859 last_tag_was_int =
true;
860 tag_param_idx = next_param_idx++;
864 last_tag_was_int =
true;
872 last_tag_was_int =
false;
873 prop_name = tag_body;
874 tag_param_idx = last_tag_was_int ? next_param_idx++ : next_param_idx;
882 if ( (
int)ex.
numParams() <= tag_param_idx )
884 result <<
"<invalid index: #" << ( tag_param_idx + 1 ) <<
">";
890 if ( !prop_name.empty() )
893 BObjectImp* member_imp = obj_member->impptr();
907 if ( str_pos <
value_.length() )
909 result <<
value_.substr( str_pos, std::string::npos );
912 return new String( result.str() );
916 return new BError(
"string.format() requires a parameter." );
925 return new BError(
"string.join expects an array" );
948 return new BError(
"string.join(array) requires a parameter." );
virtual BObjectRef get_member(const char *membername)
virtual std::string getStringRep() const =0
virtual size_t sizeEstimate() const POL_OVERRIDE
const std::string & value() const
int find(int begin, const char *target)
void EStrReplace(String *str1, String *str2)
bool isa(BObjectType type) const
virtual void packonto(std::ostream &os) const POL_OVERRIDE
virtual std::string getStringRep() const POL_OVERRIDE
#define OSTRINGSTREAM_STR(x)
virtual bool operator<(const BObjectImp &objimp) const POL_OVERRIDE
virtual BObjectRef OperMultiSubscriptAssign(std::stack< BObjectRef > &indices, BObjectImp *target) POL_OVERRIDE
ObjMethod * getKnownObjMethod(const char *token)
int paramAsLong(unsigned param)
void ESubStrReplace(String *replace_with, unsigned int index, unsigned int len)
const char * paramAsString(unsigned param)
virtual BObjectImp * selfPlusObj(const BObjectImp &objimp) const POL_OVERRIDE
String * midstring(int begin, int len) const
virtual std::string getStringRep() const POL_OVERRIDE
BObject * getParamObj(unsigned param)
virtual BObjectImp * selfMinusObj(const BObjectImp &objimp) const POL_OVERRIDE
void remove(const char *s)
virtual bool operator==(const BObjectImp &objimp) const
virtual bool operator==(const BObjectImp &objimp) const POL_OVERRIDE
void int_to_binstr(int &value, std::stringstream &s)
virtual BObjectRef OperSubscript(const BObject &obj) POL_OVERRIDE
virtual BObjectImp * copy() const POL_OVERRIDE
virtual bool operator<(const BObjectImp &objimp) const
virtual BObjectImp * call_method_id(const int id, Executor &ex, bool forcebuiltin=false) POL_OVERRIDE
String * ETrim(const char *CRSet, int type)
virtual BObjectImp * selfPlusObjImp(const BObjectImp &objimp) const POL_OVERRIDE
virtual BObjectRef OperMultiSubscript(std::stack< BObjectRef > &indices) POL_OVERRIDE
static UninitObject * create()
unsigned int alnumlen() const
unsigned int SafeCharAmt() const
static BObjectImp * unpack(const char *pstr)
String * StrStr(int begin, int len)
virtual bool isTrue() const POL_OVERRIDE
virtual BObjectImp * call_method(const char *methodname, Executor &ex) POL_OVERRIDE
static BObjectImp * unpackWithLen(std::istream &is)
virtual BObjectImp * selfMinusObjImp(const BObjectImp &objimp) const POL_OVERRIDE
virtual std::string getStringRep() const POL_OVERRIDE
virtual BObjectImp * selfMinusObj(const BObjectImp &objimp) const
virtual std::string pack() const POL_OVERRIDE
void s_trim(std::string &s)
bool try_to_format(std::stringstream &to_stream, BObjectImp *what, std::string &frmt)
virtual BObjectImp * array_assign(BObjectImp *idx, BObjectImp *target, bool copy) POL_OVERRIDE
bool s_parse_int(int &i, std::string const &s)
virtual std::string getStringRep() const POL_OVERRIDE
virtual BObjectImp * selfPlusObj(const BObjectImp &objimp) const
BObjectImp * getParamImp(unsigned param)