@@ -83,7 +83,7 @@ private function processPathTokens(array $tokens, PathParsingState $state, PathC
8383
8484 while ($ index < $ tokenCount ) {
8585 $ token = $ tokens [$ index ];
86- if (preg_match ( ' /^[A-Za-z]$/ ' , $ token ) === 1 ) {
86+ if ($ this -> isCommandToken ( $ token )) {
8787 $ currentCommand = $ token ;
8888 ++$ index ;
8989 }
@@ -174,7 +174,7 @@ private function handleMoveCommand(
174174 $ state ->lastCubicControlX = null ;
175175 $ state ->lastCubicControlY = null ;
176176
177- while ($ index < $ tokenCount && preg_match ( ' /^[A-Za-z]$/ ' , $ tokens [$ index ]) !== 1 ) {
177+ while ($ index < $ tokenCount && ! $ this -> isCommandToken ( $ tokens [$ index ])) {
178178 $ coordinates = $ this ->pathNumberReader ->readPathNumbers ($ tokens , $ index , 2 , $ context ->source );
179179 $ nextX = $ this ->resolveCoord ($ isRelative , $ state ->currentX , $ coordinates [0 ]);
180180 $ nextY = $ this ->resolveCoord ($ isRelative , $ state ->currentY , $ coordinates [1 ]);
@@ -195,7 +195,7 @@ private function handleLineCommand(
195195 PathParsingState $ state ,
196196 PathCommandContext $ context ,
197197 ): void {
198- while ($ index < $ tokenCount && preg_match ( ' /^[A-Za-z]$/ ' , $ tokens [$ index ]) !== 1 ) {
198+ while ($ index < $ tokenCount && ! $ this -> isCommandToken ( $ tokens [$ index ])) {
199199 $ coordinates = $ this ->pathNumberReader ->readPathNumbers ($ tokens , $ index , 2 , $ context ->source );
200200 $ nextX = $ this ->resolveCoord ($ isRelative , $ state ->currentX , $ coordinates [0 ]);
201201 $ nextY = $ this ->resolveCoord ($ isRelative , $ state ->currentY , $ coordinates [1 ]);
@@ -214,7 +214,7 @@ private function handleHorizontalCommand(
214214 PathParsingState $ state ,
215215 PathCommandContext $ context ,
216216 ): void {
217- while ($ index < $ tokenCount && preg_match ( ' /^[A-Za-z]$/ ' , $ tokens [$ index ]) !== 1 ) {
217+ while ($ index < $ tokenCount && ! $ this -> isCommandToken ( $ tokens [$ index ])) {
218218 $ coordinates = $ this ->pathNumberReader ->readPathNumbers ($ tokens , $ index , 1 , $ context ->source );
219219 $ state ->currentX = $ this ->resolveCoord ($ isRelative , $ state ->currentX , $ coordinates [0 ]);
220220 [$ lineX , $ lineY ] = $ this ->transformResolver ->applyTransformToPoint (
@@ -241,7 +241,7 @@ private function handleVerticalCommand(
241241 PathParsingState $ state ,
242242 PathCommandContext $ context ,
243243 ): void {
244- while ($ index < $ tokenCount && preg_match ( ' /^[A-Za-z]$/ ' , $ tokens [$ index ]) !== 1 ) {
244+ while ($ index < $ tokenCount && ! $ this -> isCommandToken ( $ tokens [$ index ])) {
245245 $ coordinates = $ this ->pathNumberReader ->readPathNumbers ($ tokens , $ index , 1 , $ context ->source );
246246 $ state ->currentY = $ this ->resolveCoord ($ isRelative , $ state ->currentY , $ coordinates [0 ]);
247247 [$ lineX , $ lineY ] = $ this ->transformResolver ->applyTransformToPoint (
@@ -268,7 +268,7 @@ private function handleCubicCommand(
268268 PathParsingState $ state ,
269269 PathCommandContext $ context ,
270270 ): void {
271- while ($ index < $ tokenCount && preg_match ( ' /^[A-Za-z]$/ ' , $ tokens [$ index ]) !== 1 ) {
271+ while ($ index < $ tokenCount && ! $ this -> isCommandToken ( $ tokens [$ index ])) {
272272 $ coordinates = $ this ->pathNumberReader ->readPathNumbers ($ tokens , $ index , 6 , $ context ->source );
273273 $ startX1 = $ this ->resolveCoord ($ isRelative , $ state ->currentX , $ coordinates [0 ]);
274274 $ startY1 = $ this ->resolveCoord ($ isRelative , $ state ->currentY , $ coordinates [1 ]);
@@ -308,7 +308,7 @@ private function handleSmoothCubicCommand(
308308 PathParsingState $ state ,
309309 PathCommandContext $ context ,
310310 ): void {
311- while ($ index < $ tokenCount && preg_match ( ' /^[A-Za-z]$/ ' , $ tokens [$ index ]) !== 1 ) {
311+ while ($ index < $ tokenCount && ! $ this -> isCommandToken ( $ tokens [$ index ])) {
312312 $ coordinates = $ this ->pathNumberReader ->readPathNumbers ($ tokens , $ index , 4 , $ context ->source );
313313 $ startX1 = $ this ->reflectControlPoint ($ state ->lastCubicControlX , $ state ->currentX );
314314 $ startY1 = $ this ->reflectControlPoint ($ state ->lastCubicControlY , $ state ->currentY );
@@ -348,7 +348,7 @@ private function handleQuadraticCommand(
348348 PathParsingState $ state ,
349349 PathCommandContext $ context ,
350350 ): void {
351- while ($ index < $ tokenCount && preg_match ( ' /^[A-Za-z]$/ ' , $ tokens [$ index ]) !== 1 ) {
351+ while ($ index < $ tokenCount && ! $ this -> isCommandToken ( $ tokens [$ index ])) {
352352 $ coordinates = $ this ->pathNumberReader ->readPathNumbers ($ tokens , $ index , 4 , $ context ->source );
353353 $ qcpX = $ this ->resolveCoord ($ isRelative , $ state ->currentX , $ coordinates [0 ]);
354354 $ qcpY = $ this ->resolveCoord ($ isRelative , $ state ->currentY , $ coordinates [1 ]);
@@ -390,7 +390,7 @@ private function handleSmoothQuadraticCommand(
390390 PathParsingState $ state ,
391391 PathCommandContext $ context ,
392392 ): void {
393- while ($ index < $ tokenCount && preg_match ( ' /^[A-Za-z]$/ ' , $ tokens [$ index ]) !== 1 ) {
393+ while ($ index < $ tokenCount && ! $ this -> isCommandToken ( $ tokens [$ index ])) {
394394 $ coordinates = $ this ->pathNumberReader ->readPathNumbers ($ tokens , $ index , 2 , $ context ->source );
395395 $ qcpX = $ this ->reflectControlPoint ($ state ->prevQuadCpX , $ state ->currentX );
396396 $ qcpY = $ this ->reflectControlPoint ($ state ->prevQuadCpY , $ state ->currentY );
@@ -431,7 +431,7 @@ private function handleArcCommand(
431431 PathParsingState $ state ,
432432 PathCommandContext $ context ,
433433 ): void {
434- while ($ index < $ tokenCount && preg_match ( ' /^[A-Za-z]$/ ' , $ tokens [$ index ]) !== 1 ) {
434+ while ($ index < $ tokenCount && ! $ this -> isCommandToken ( $ tokens [$ index ])) {
435435 $ coordinates = $ this ->pathNumberReader ->readPathNumbers ($ tokens , $ index , 7 , $ context ->source );
436436 $ radiusX = abs ($ coordinates [0 ]);
437437 $ radiusY = abs ($ coordinates [1 ]);
@@ -508,6 +508,11 @@ private function resolveCoord(bool $isRelative, float $current, float $coord): f
508508 return $ isRelative ? $ current + $ coord : $ coord ;
509509 }
510510
511+ private function isCommandToken (string $ token ): bool
512+ {
513+ return strlen ($ token ) === 1 && ctype_alpha ($ token );
514+ }
515+
511516 /**
512517 * Reflect a previous control point over the current position.
513518 * Returns current position when no prior control point exists (SVG spec default).
0 commit comments