Skip to content

Instantly share code, notes, and snippets.

@Seregamil
Last active November 19, 2015 09:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Seregamil/6b439d7cd27a878a4dc9 to your computer and use it in GitHub Desktop.
Save Seregamil/6b439d7cd27a878a4dc9 to your computer and use it in GitHub Desktop.
//-- by Seregamil
/*
Functions:
List<string>.Create()
List<string>.Get( _ID, index )
List<string>.Add( _ID, item[] )
List<string>.AddRange( _ID, range[][] )
List<string>.IndexOf( _ID, item )
List<string>.Length( _ID )
List<string>.SetID( _ID, oldIndex, newIndex )
List<string>.Swap( _ID, x, y )
List<string>.Insert( _ID, index, item[] )
List<string>.RemoveAt( _ID, index )
List<string>.Remove( _ID, item[] )
*/
#if defined _multiArray_included
#endinput
#endif
#define _multiArray_included
#define MAX_MULTI_ARRAYS 100 // optional
new multiArray[ MAX_MULTI_ARRAYS ] = { 0, ... } ;
#define List<string>. StringArray
stock StringArrayCreate() {
new _ID = getproperty( .id = 0, .name = "stringArrays" ) + 1 ;
multiArray[ _ID ] = 0 ;
setproperty( .name = "stringArrays", .value = _ID ) ;
return _ID ;
}
stock StringArrayAdd( _ID, item[] ) {
setproperty( .id = _ID, .name = "", .value = multiArray[ _ID ], .string = item);
multiArray[ _ID ] ++ ;
return multiArray[ _ID ] - 1 ;
}
stock StringArrayAddRange( _ID, range[][], length = sizeof( range ) ) {
for( new j = 0 ; j != length ; j ++ ) StringArrayAdd( _ID, range[ j ] ) ;
}
stock StringArrayGet( _ID, index ) {
new _RESULT[ 128 ] ;
getproperty( _ID, "", index, _RESULT);
strunpack( _RESULT, _RESULT, sizeof( _RESULT ) );
return _RESULT ;
}
stock StringArrayLength( _ID ) {
return multiArray[ _ID ] ;
}
stock StringArraySetID( _ID, oldIndex, newIndex ) {
new temp[ 128 ] ;
strcat( temp, List<string>.Get( _ID, oldIndex ) );
deleteproperty( _ID, "", oldIndex );
setproperty( .id = _ID, .name = "", .value = newIndex, .string = temp);
}
stock StringArraySwap( _ID, indexX, indexY ) {
new xTemp[ 128 ], yTemp[ 128 ] ;
strcat( xTemp, List<string>.Get( _ID, indexX ) );
strcat( yTemp, List<string>.Get( _ID, indexY ) );
deleteproperty( _ID, "", indexX );
deleteproperty( _ID, "", indexY );
setproperty( .id = _ID, .name = "", .value = indexX, .string = yTemp);
setproperty( .id = _ID, .name = "", .value = indexY, .string = xTemp);
}
stock StringArrayInsert( _ID, index, item[] ) {
new length = List<string>.Length( _ID ) ;
while( --length != ( index - 1 ) )
List<string>.SetID( _ID, length, length + 1 );
multiArray[ _ID ] ++ ;
new position = List<string>.Add( _ID, item ) ;
List<string>.SetID( _ID, position, index );
multiArray[ _ID ] -- ;
}
stock StringArrayIndexOf( _ID, item[] ) {
new length = List<string>.Length( _ID ) ;
for( new j = 0 ; j != length ; j ++ ) {
if( strfind( List<string>.Get( _ID, j ), item, true) == -1 )
continue ;
return j ;
}
return 0 ;
}
stock StringArrayRemoveAt( _ID, index ) {
deleteproperty( _ID, "", index );
new length = List<string>.Length( _ID ) ;
while( ++index != length ) List<string>.SetID( _ID, index, index - 1 );
multiArray[ _ID ] -- ;
}
stock StringArrayRemove( _ID, item[] ) {
new length = List<string>.Length( _ID ) ;
new itemLen = strlen( item ) ;
for( new j = 0 ; j != length ; j++ ) {
if( strcmp( item, List<string>.Get( _ID, j ), false, itemLen ) )
continue ;
List<string>.RemoveAt( _ID, j );
break ;
}
}
@Zaur-Lumanov
Copy link

Кек.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment