Hello D Language Forum!

I’m running the InputRange example below and it dutifully reads from stdin until it spots a tilde, printing each character in every loop iteration. I even tried to break out with F6 but couldn’t get it to stop. Curiously, swapping the tilde for the '\t' character makes everything work flawlessly. Any ideas why this is happening? I’d really appreciate your insights!

```d
import std;

struct StdinByChar
{
  @property bool empty()
  {
    if(isEmpty)
      return true;

    if(!hasChar)
    {
      auto buff = new char[1];
      stdin.rawRead(buff);

      if (buff[0] == 0x7E) // tilde (~) character
      {
        isEmpty = true;
        return true;
      }
      chr = buff[0];
      hasChar = true;
    }
    return false;
  }

  @property auto front() =>  chr;

  auto popFront()  =>  hasChar = false;

  private:
    char   chr;
    bool   hasChar, isEmpty;
}

void main()
{
    auto r = StdinByChar();

    while (!r.empty)
    {
        write(r.front);
        r.popFront();
    }

    writeln();

    write("Range is ");
    if(!r.empty) write("not");
    writeln("empty!");
}
```
SDB@79

Reply via email to