| 123456789101112131415161718192021222324252627282930313233343536 |
- <?php
- namespace App\Support;
- class GradingMarkBoxCounter
- {
- public function countFillBlanks(?string $text): int
- {
- $text = (string) $text;
- $count = 0;
- $count += preg_match_all('/_{2,}/u', $text, $m);
- $count += preg_match_all('/(\s*)/u', $text, $m);
- $count += preg_match_all('/\(\s*\)/', $text, $m);
- return max(1, $count);
- }
- public function countAnswerSteps(?string $text): int
- {
- $text = (string) $text;
- if (!preg_match('/(步骤\s*\d+|第\s*\d+\s*步)/u', $text)) {
- return 1;
- }
- $parts = preg_split('/(?=步骤\s*\d+|第\s*\d+\s*步)/u', $text, -1, PREG_SPLIT_NO_EMPTY) ?: [];
- $count = 0;
- foreach ($parts as $part) {
- $stepText = trim((string) $part);
- if ($stepText !== '' && preg_match('/^(步骤\s*\d+|第\s*\d+\s*步)/u', $stepText)) {
- $count++;
- }
- }
- return max(1, $count);
- }
- }
|