Skip to content

Commit c8d0bab

Browse files
committed
Changed algorithm for breaking code blocks into sentences (blocks like large SQL queries with comments are too long).
1 parent 5c8179d commit c8d0bab

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/S2/Rose/Helper/StringHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public static function sentencesFromText(string $text, bool $hasFormatting): arr
6565
*/
6666
public static function sentencesFromCode(string $text): array
6767
{
68-
$substrings = preg_split('#(\r?\n\r?){2,}#Su', $text);
68+
$substrings = preg_split('#(\r?\n\r?){1,}#Su', $text);
6969
array_walk($substrings, 'trim');
7070

7171
return $substrings;

tests/unit/Rose/Extractor/ExtractorTest.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,23 @@ public function htmlSentenceProvider(): array
246246
'Ошибка \\iастатически\\I даёт более простую систему.',
247247
'<?php',
248248
'require \'vendor/autoload.php\';',
249-
'use GuzzleHttp\\\\Client; use GuzzleHttp\\\\Psr7\\\\Request; use GuzzleHttp\\\\Psr7\\\\ServerRequest;',
250-
'// Создание экземпляра клиента Guzzle $client = new Client();',
251-
'// Обработка входящего запроса $request = ServerRequest::fromGlobals();',
252-
'// Получение URL-адреса запрашиваемого сайта $url = $request->getUri(); $url // Я собирался ходить на https-сайты, поэтому подменил протокол и порт ->withScheme(\'https\') ->withPort(443) // Подменяем хост (видимо, тут и есть обработка протокола http-прокси) ->withHost($request->getHeaderLine(\'host\')) ->withQuery($request->getUri()->getQuery()) ;',
249+
'use GuzzleHttp\\\\Client;',
250+
'use GuzzleHttp\\\\Psr7\\\\Request;',
251+
'use GuzzleHttp\\\\Psr7\\\\ServerRequest;',
252+
'// Создание экземпляра клиента Guzzle',
253+
'$client = new Client();',
254+
'// Обработка входящего запроса',
255+
'$request = ServerRequest::fromGlobals();',
256+
'// Получение URL-адреса запрашиваемого сайта',
257+
'$url = $request->getUri();',
258+
'$url',
259+
'// Я собирался ходить на https-сайты, поэтому подменил протокол и порт',
260+
'->withScheme(\'https\')',
261+
'->withPort(443)',
262+
'// Подменяем хост (видимо, тут и есть обработка протокола http-прокси)',
263+
'->withHost($request->getHeaderLine(\'host\'))',
264+
'->withQuery($request->getUri()->getQuery())',
265+
';',
253266
'123',
254267
'\\bПолностью жирное предложение.\\B',
255268
'\\b\\B',

0 commit comments

Comments
 (0)