123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- #include "KSGSText.h"
- #include "KSGSTyp.h"
- #include "../Error/Error.h"
- #include "KSGSBool.h"
- #include "KSGSInt.h"
- #include "KSGSDouble.h"
- using namespace KSGScript;
- // Inhalt der KSGSTextKlasse Klasse aus KSGSText.h
- // Konstruktor
- KSGSTextKlasse::KSGSTextKlasse( KSGScriptProcessor *zObj, const char *std )
- : KSGSKlasseInstanz( KSGS_TEXT, 0, 0, zObj )
- {
- val = new Text( std );
- }
- // Destruktor
- KSGSTextKlasse::~KSGSTextKlasse()
- {
- val->release();
- }
- // nicht constant
- KSGSVariable *KSGSTextKlasse::startFunktion( int id, bool access, RCArray< KSGSVariable > *parameter )
- {
- KSGSVariable *ret = 0;
- switch( id )
- {
- case 0: // void setSuchGrenzen( int, int )
- if( parameter->getEintragAnzahl() < 2 )
- error( 20, {}, obj );
- val->setSuchGrenzen( (char)( parameter->z( 0 ) ? parameter->z( 0 )->getInt() : 0 ),
- (char)( parameter->z( 1 ) ? parameter->z( 1 )->getInt() : 0 ) );
- break;
- case 1: // void setText( Text )
- if( parameter->getEintragAnzahl() < 1 )
- error( 20, {}, obj );
- val->setText( parameter->z( 0 ) ? parameter->z( 0 )->getText() : new Text( "" ) );
- break;
- case 2: // void anhängen( Text )
- if( parameter->getEintragAnzahl() < 1 )
- error( 20, {}, obj );
- val->append( parameter->z( 0 ) ? parameter->z( 0 )->getText() : new Text( "" ) );
- break;
- case 3: // void einfügen( int, Text )
- if( parameter->getEintragAnzahl() < 2 )
- error( 20, {}, obj );
- val->insert( parameter->z( 0 ) ? parameter->z( 0 )->getInt() : 0,
- parameter->z( 1 ) ? parameter->z( 1 )->getText() : new Text( "" ) );
- break;
- case 4: // void ersetzen( int, int, Text )
- if( parameter->getEintragAnzahl() < 3 )
- error( 20, {}, obj );
- val->ersetzen( parameter->z( 0 ) ? parameter->z( 0 )->getInt() : 0,
- parameter->z( 1 ) ? parameter->z( 1 )->getInt() : 0,
- parameter->z( 2 ) ? parameter->z( 2 )->getText() : new Text( "" ) );
- break;
- case 5: // void löschen( int, int )
- if( parameter->getEintragAnzahl() < 2 )
- error( 20, {}, obj );
- val->remove( parameter->z( 0 ) ? parameter->z( 0 )->getInt() : 0,
- parameter->z( 1 ) ? parameter->z( 1 )->getInt() : 0 );
- break;
- case 6: // int getLänge()
- ret = new KSGSIntKlasse( obj, val->getLength() );
- break;
- case 7: // bool hat( Text )
- if( parameter->getEintragAnzahl() < 1 )
- error( 20, {}, obj );
- ret = new KSGSBoolKlasse( obj, val->hat( parameter->z( 0 ) ? parameter->z( 0 )->getText() : new Text( "" ) ) );
- break;
- case 8: // bool istGleich( Text )
- if( parameter->getEintragAnzahl() < 1 )
- error( 20, {}, obj );
- ret = new KSGSBoolKlasse( obj, val->istGleich( parameter->z( 0 ) ? parameter->z( 0 )->getText() : new Text( "" ) ) );
- break;
- case 9: // int anzahlVon( Text )
- if( parameter->getEintragAnzahl() < 1 )
- error( 20, {}, obj );
- ret = new KSGSIntKlasse( obj, val->anzahlVon( parameter->z( 0 ) ? parameter->z( 0 )->getText() : new Text( "" ) ) );
- break;
- case 10: // int positionVon( Text, int )
- if( parameter->getEintragAnzahl() < 2 )
- error( 20, {}, obj );
- ret = new KSGSIntKlasse( obj, val->positionVon( parameter->z( 0 ) ? parameter->z( 0 )->getText() : new Text( "" ),
- parameter->z( 1 ) ? parameter->z( 1 )->getInt() : 0 ) );
- break;
- case 11: // Text getTeilText( int, int )
- if( 1 )
- {
- Text *txt = val->getTeilText( parameter->z( 0 ) ? parameter->z( 0 )->getInt() : 0,
- parameter->z( 1 ) ? parameter->z( 1 )->getInt() : 0 );
- if( !txt )
- txt = new Text();
- ret = new KSGSTextKlasse( obj, *txt );
- txt->release();
- }
- break;
- default: // unbekannt
- error( 19, {}, obj );
- break;
- }
- parameter->release();
- return ret;
- }
- KSGSVariable *KSGSTextKlasse::doOperator( int id, KSGSVariable *rechts )
- {
- if( !rechts )
- {
- error( 3, {}, obj );
- return 0;
- }
- KSGSVariable *ret = 0;
- switch( id )
- {
- case KSGS_O_SET:
- val->setText( rechts->getText() );
- ret = dynamic_cast<KSGSVariable *>( getThis() );
- break;
- case KSGS_O_PLUSSET:
- val->append( rechts->getText() );
- ret = dynamic_cast<KSGSVariable *>( getThis() );
- break;
- case KSGS_O_MINUSSET:
- val->append( rechts->getText() );
- ret = dynamic_cast<KSGSVariable *>( getThis() );
- break;
- case KSGS_O_GLEICH:
- ret = new KSGSBoolKlasse( obj, val->istGleich( rechts->getText() ) );
- break;
- case KSGS_O_KLEINERGLEICH:
- if( 1 )
- {
- Text *txt = rechts->getText();
- ret = new KSGSBoolKlasse( obj, val->istGleich( rechts->getText() ) || *val < *txt );
- txt->release();
- }
- break;
- case KSGS_O_GREATERGLEICH:
- if( 1 )
- {
- Text *txt = rechts->getText();
- ret = new KSGSBoolKlasse( obj, val->istGleich( rechts->getText() ) || *val > *txt );
- txt->release();
- }
- break;
- case KSGS_O_UNGLEICH:
- ret = new KSGSBoolKlasse( obj, !val->istGleich( rechts->getText() ) );
- break;
- case KSGS_O_KLEINER:
- if( 1 )
- {
- Text *txt = rechts->getText();
- ret = new KSGSBoolKlasse( obj, *val < *txt );
- txt->release();
- }
- break;
- case KSGS_O_GREATER:
- if( 1 )
- {
- Text *txt = rechts->getText();
- ret = new KSGSBoolKlasse( obj, *val > *txt );
- txt->release();
- }
- break;
- case KSGS_O_PLUS:
- if( 1 )
- {
- Text *txt = rechts->getText();
- ret = new KSGSTextKlasse( obj, Text( (char *)val ) += (char *)*txt );
- txt->release();
- }
- break;
- case KSGS_O_MINUS:
- if( 1 )
- {
- Text t( (char *)val );
- t.remove( rechts->getText() );
- ret = new KSGSTextKlasse( obj, t );
- }
- break;
- }
- if( !ret )
- error( 21, {}, obj );
- if( rechts )
- rechts->release();
- return ret;
- }
- // constant
- Text *KSGSTextKlasse::getVal() const
- {
- return dynamic_cast<Text *>( val->getThis() );
- }
- Text *KSGSTextKlasse::zVal() const
- {
- return val;
- }
- KSGSVariable *KSGSTextKlasse::umwandelnIn( int typ ) const
- {
- switch( typ )
- {
- case KSGS_BOOL:
- if( val->istGleich( "true" ) )
- return new KSGSBoolKlasse( obj, 1 );
- if( val->istGleich( "false" ) )
- return new KSGSBoolKlasse( obj, 0 );
- return new KSGSBoolKlasse( obj, (int)*val != 0 );
- case KSGS_INT:
- return new KSGSIntKlasse( obj, *val );
- case KSGS_DOUBLE:
- return new KSGSDoubleKlasse( obj, *val );
- }
- error( 16, {}, obj );
- return 0;
- }
|