Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix(testing): Make Testing TextProcessing providers unicode safe
Signed-off-by: Marcel Klehr <[email protected]>
  • Loading branch information
marcelklehr committed Jul 26, 2024
commit b9187dcb9eb33eac945ef768b0aed1a1fcc3743c
13 changes: 12 additions & 1 deletion apps/testing/lib/Provider/FakeTextProcessingProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,21 @@ public function getName(): string {
}

public function process(string $prompt): string {
return strrev($prompt) . ' (done with FakeTextProcessingProvider)';
return $this->mb_strrev($prompt) . ' (done with FakeTextProcessingProvider)';
}

public function getTaskType(): string {
return FreePromptTaskType::class;
}

/**
* Reverse a miltibyte string.
*
* @param string $string The string to be reversed.
* @return string The reversed string
*/
private function mb_strrev(string $string): string {
$chars = mb_str_split($string, 1);
return implode('', array_reverse($chars));
}
}
13 changes: 12 additions & 1 deletion apps/testing/lib/Provider/FakeTextProcessingProviderSync.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function getName(): string {
}

public function process(string $prompt): string {
return strrev($prompt) . ' (done with FakeTextProcessingProviderSync)';
return $this->mb_strrev($prompt) . ' (done with FakeTextProcessingProviderSync)';
}

public function getTaskType(): string {
Expand All @@ -30,4 +30,15 @@ public function getTaskType(): string {
public function getExpectedRuntime(): int {
return 1;
}

/**
* Reverse a miltibyte string.
*
* @param string $string The string to be reversed.
* @return string The reversed string
*/
private function mb_strrev(string $string): string {
$chars = mb_str_split($string, 1);
return implode('', array_reverse($chars));
}
}