Browse Source

Another test - tokenizer.

pull/50/head
Rafal Kupiec 2 years ago
parent
commit
5d3acf74d0
Signed by: belliash GPG Key ID: 4E829243E0CFE6B4
2 changed files with 40 additions and 0 deletions
  1. +36
    -0
      tests/tokenizer.aer
  2. +4
    -0
      tests/tokenizer.exp

+ 36
- 0
tests/tokenizer.aer View File

@ -0,0 +1,36 @@
class StringTokenizer {
private $token;
private $delim;
public function __construct(string $str, string $delim = ' ') {
$this->token = strtok($str, $delim);
$this->delim = $delim;
}
public function __destruct() {
unset($this);
}
public function hasMoreTokens() {
return ($this->token !== false);
}
public function nextToken() {
string $current = $this->token;
$this->token = strtok($this->delim);
return $current;
}
}
class Program {
function 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);
}
}

+ 4
- 0
tests/tokenizer.exp View File

@ -0,0 +1,4 @@
This
is
a
TEST

Loading…
Cancel
Save