TextStream.java

/**
* Copyright 2010,2021 Nikolas S Boyd.
Permission is granted to copy this work provided this copyright statement is retained in all copies.

*/
package Hoot.Tests;

import Hoot.Runtime.Functions.*;
import Hoot.Runtime.Faces.*;
import Hoot.Runtime.Values.*;
import Hoot.Runtime.Blocks.*;
import Smalltalk.Core.*;
import Smalltalk.Blocks.*;
import Smalltalk.Magnitudes.*;
import Hoot.Behaviors.*;
import Hoot.Behaviors.Nil;
import Hoot.Behaviors.Object;
import Hoot.Behaviors.True;
import Hoot.Behaviors.False;
import Hoot.Behaviors.Boolean;
import Hoot.Magnitudes.*;
import Hoot.Magnitudes.Integer;
import Hoot.Magnitudes.Character;
import Hoot.Magnitudes.Float;
import Hoot.Magnitudes.Double;
import Hoot.Collections.*;
import Hoot.Collections.String;
import Hoot.Streams.*;

public class TextStream extends TestableClosure
{

  protected static final String TextReport = String.from("%s w/o vowels = %s");

  /**
   * @return 
   */
  @Override public   void runTest()
  {
    java.lang.String exitID = "TextStream>>runTest";
    Frame f0 = new Frame(exitID);
    this.testVowelRemoval();
    this.testUpToVowels();
  }

  /**
   * @return 
   */
  public   void testVowelRemoval()
  {
    java.lang.String exitID = "TextStream>>testVowelRemoval";
    Frame f0 = new Frame(exitID);
    String vowels = String.from("aeiou");

    String source = String.from("abcdefghijklmnopqrstuvwxyz");

    TextReadStream iStream = source.readStream();

    TextWriteStream oStream = String.type().writeStream(source.size());
    Predicate.with(f2 -> {
      return iStream.atEnd();
    }, "").whileFalse(Closure.with(f2 -> {
      
    Character c = iStream.next();
    vowels.includes(c).ifFalse(Closure.with(f3 -> {
      oStream.nextPut(c);
    }, ""));
    }, ""));
    this.log().printLine(TextReport.formatWith(source, oStream.contents()));
  }

  /**
   * @return 
   */
  public   void testUpToVowels()
  {
    java.lang.String exitID = "TextStream>>testUpToVowels";
    Frame f0 = new Frame(exitID);
    String vowels = String.from("aeiou");

    String source = String.from("abcdefghijklmnopqrstuvwxyz");

    TextReadStream vStream = vowels.readStream();

    TextReadStream rStream = source.readStream();

    TextWriteStream wStream = String.type().writeStream(source.size());
    Predicate.with(f2 -> {
      return vStream.atEnd();
    }, "").whileFalse(Closure.with(f2 -> {
      
    Character c = vStream.next();
    wStream.nextPutAll(rStream.upTo(c));
    }, ""));
    this.log().printLine(TextReport.formatWith(source, wStream.contents()));
  }
}