Aer/tests/tokenizer.aer
belliash d924d41a7a
All checks were successful
The build was successful.
Do not unset $this.
Let the garbage collector do its job and fix the test.
2019-05-29 13:53:52 +02:00

36 lines
679 B
Plaintext

class StringTokenizer {
private string $token;
private string $delim;
public void __construct(string $str, string $delim = ' ') {
$this->token = strtok($str, $delim);
$this->delim = $delim;
}
public void __destruct() {
}
public bool hasMoreTokens() {
return ($this->token != NULL);
}
public string nextToken() {
string $current = $this->token;
$this->token = strtok($this->delim);
return $current;
}
}
class Program {
public void main() {
string $str = "This is:@\t\n a TEST!";
string $delim = " !@:\t\n";
object $st = new StringTokenizer($str, $delim);
while ($st->hasMoreTokens()) {
print($st->nextToken(), "\n");
}
unset($st);
}
}