static CScriptArrayInterface *QAS_SplitString( const asstring_t &str, const asstring_t &delim ) { asIScriptContext *ctx = asGetActiveContext(); asIScriptEngine *engine = ctx->GetEngine(); asIObjectType *ot = engine->GetObjectTypeById(engine->GetTypeIdByDecl("array<String @>")); CScriptArrayInterface *arr = QAS_NEW(CScriptArray)(0, ot); const char *pdelim = delim.buffer; const size_t delim_len = strlen( pdelim ); const char *pbuf = str.buffer; const char *prev_pbuf = pbuf; // find all occurences of the delimiter in source string unsigned int count = 0; while( 1 ) { pbuf = strstr( prev_pbuf, pdelim ); if( !pbuf ) { break; } arr->Resize( count + 1 ); *((asstring_t **)arr->At(count)) = objectString_FactoryBuffer( prev_pbuf, pbuf - prev_pbuf ); prev_pbuf = pbuf + delim_len; count++; } // append the remaining part arr->Resize( count + 1 ); *((asstring_t **)arr->At(count)) = objectString_FactoryBuffer( prev_pbuf, strlen( prev_pbuf ) ); return arr; }
CScriptAnyInterface *qasCreateAnyCpp( asIScriptEngine *engine ) { return QAS_NEW(CScriptAny)( engine ); }
CScriptDictionaryInterface *qasCreateDictionaryCpp( asIScriptEngine *engine ) { return QAS_NEW(CScriptDictionary)( engine ); }
CScriptArrayInterface *qasCreateArrayCpp( unsigned int length, void *ot ) { return QAS_NEW(CScriptArray)( length, static_cast<asIObjectType *>( ot ) ); }
void *qasCreateAnyCpp( void *engine ) { return static_cast<void*>( QAS_NEW(CScriptAny)( static_cast<asIScriptEngine *>( engine ) ) ); }
void *qasCreateDictionaryCpp( void *engine ) { return static_cast<void*>( QAS_NEW(CScriptDictionary)( static_cast<asIScriptEngine *>( engine ) ) ); }