@@ -390,26 +390,66 @@ internal static void Division(Stack context)
390390 var value = second . GetInt ( ) / first . GetInt ( ) ;
391391 result = new IntegerItem ( value ) ;
392392 }
393+ #region Split Matches
393394 else if ( tuple == ( ItemType . String , ItemType . String ) )
394395 {
395- var separator = second . GetString ( ) ;
396- var split = first . GetString ( ) . Split ( separator ) ;
397- var value = split . Where ( str => str . Length > 0 ) . Select ( str => new StringItem ( str ) ) ;
396+ var separator = first . GetString ( ) ;
397+ var split = second . GetString ( ) . Split ( separator ) ;
398+ var value = split . Select ( str => new StringItem ( str ) ) ;
398399 result = new ArrayItem ( value ) ;
399400 }
400- // TODO: Array implementation
401- //else if (tuple == (ItemType.Array, ItemType.Array))
402- //{
403- // var separator = second.GetArray();
404- // var split = first.GetArray().Split(separator);
405- // var value = split.Where(str => str.Length > 0).Select(str => new StringItem(str));
406- // result = new ArrayItem(value);
407- //}
401+ else if ( tuple == ( ItemType . Array , ItemType . Array ) )
402+ {
403+ var separator = first . GetArray ( ) ;
404+ var split = second . GetArray ( ) . Split ( separator ) ;
405+ var value = split . Select ( str => new ArrayItem ( str ) ) ;
406+ result = new ArrayItem ( value ) ;
407+ }
408+ #endregion
409+ #region Split Size
410+ else if ( tuple == ( ItemType . String , ItemType . Integer ) )
411+ {
412+ var size = ( int ) second . GetInt ( ) ;
413+ var split = first . GetString ( ) . Chunk ( size ) ;
414+ var value = split . Select ( str => new StringItem ( str ) ) ;
415+ result = new ArrayItem ( value ) ;
416+ }
417+ else if ( tuple == ( ItemType . Array , ItemType . Integer ) )
418+ {
419+ var size = ( int ) second . GetInt ( ) ;
420+ var split = first . GetArray ( ) . Chunk ( size ) ;
421+ var value = split . Select ( arr => new ArrayItem ( arr ) ) ;
422+ result = new ArrayItem ( value ) ;
423+ }
424+ #endregion
408425 else if ( tuple == ( ItemType . Block , ItemType . Array ) )
409426 {
410427 Each ( context , first , second ) ;
411428 return ;
412429 }
430+ else if ( tuple == ( ItemType . Block , ItemType . Block ) )
431+ {
432+ var condition = second . GetString ( ) ;
433+ var code = first . GetString ( ) ;
434+
435+ var list = new List < Item > ( ) ;
436+
437+ while ( true )
438+ {
439+ Duplicate ( context ) ;
440+ context . Golfscript . Run ( condition ) ;
441+
442+ if ( ! context . Pop ( ) . Truthy )
443+ break ;
444+
445+ list . Add ( context . Peek ( ) ) ;
446+ context . Golfscript . Run ( code ) ;
447+ }
448+
449+ context . Pop ( ) ;
450+ context . Push ( new ArrayItem ( list ) ) ;
451+ return ;
452+ }
413453 else
414454 {
415455 return ;
@@ -722,6 +762,24 @@ internal static void Pow(Stack context)
722762 var index = str . IndexOf ( value ) ;
723763 context . Push ( new IntegerItem ( index ) ) ;
724764 }
765+ else if ( tuple == ( ItemType . Block , ItemType . Array ) )
766+ {
767+ var array = second . GetArray ( ) ;
768+ var condition = first . GetString ( ) ;
769+
770+ foreach ( var item in array )
771+ {
772+ context . Push ( item ) ;
773+ context . Golfscript . Run ( condition ) ;
774+
775+ if ( context . Pop ( ) . Truthy )
776+ {
777+ context . Push ( item ) ;
778+ break ;
779+ }
780+ }
781+ return ;
782+ }
725783 else if ( first . Type == ItemType . Array )
726784 {
727785 var array = first . GetArray ( ) ;
0 commit comments