@@ -345,24 +345,33 @@ private function unwrap(string &$string): array
345
345
if (
346
346
!$ this ->unaChecked
347
347
&&
348
- \strpos ($ string , " UNA " ) === 0
348
+ \strpos ($ string , ' UNA ' ) === 0
349
349
) {
350
- $ this ->analyseUNA (\preg_replace ("#^UNA# " , '' , substr ($ string , 0 , 9 )));
350
+ $ this ->analyseUNA (
351
+ \substr (\substr ($ string , 3 ), 0 , 9 )
352
+ );
351
353
}
352
354
353
355
if (
354
356
!$ this ->unbChecked
355
357
&&
356
- \strpos ($ string , " UNB " ) === 0
358
+ \strpos ($ string , ' UNB ' ) === 0
357
359
) {
358
- $ this ->analyseUNB (\preg_replace ("#^UNB\+# " , '' , substr ($ string , 0 , 8 )));
360
+ $ this ->analyseUNB (
361
+ \preg_replace (
362
+ "#^UNB\+# " ,
363
+ '' ,
364
+ \substr ($ string , 0 , 8 )
365
+ )
366
+ );
359
367
}
360
368
361
369
$ string = \preg_replace (
362
370
"/(([^ " . $ this ->symbRel . "] " . $ this ->symbRel . "{2})+|[^ " . $ this ->symbRel . "]) " . $ this ->symbEnd . "/ " ,
363
371
"$1 " . $ this ->stringSafe ,
364
372
$ string
365
373
);
374
+
366
375
$ file = \preg_split (
367
376
self ::$ DELIMITER . $ this ->stringSafe . self ::$ DELIMITER . "i " ,
368
377
$ string
@@ -393,31 +402,36 @@ private function unwrap(string &$string): array
393
402
*/
394
403
private function splitSegment (string &$ str ): array
395
404
{
396
- // remove ending symbEnd
397
- if ( \strpos ( $ str, $ this -> symbEnd ) !== false ) {
398
- $ str = \preg_replace (
405
+ // remove ending " symbEnd"
406
+ $ str = \trim (
407
+ \preg_replace (
399
408
self ::$ DELIMITER . $ this ->symbEnd . '$ ' . self ::$ DELIMITER ,
400
409
'' ,
401
410
$ str
402
- );
403
- }
404
-
405
- $ str = \trim ($ str );
411
+ )
412
+ );
406
413
407
- // replace duplicate symbRel
414
+ // replace duplicate " symbRel"
408
415
$ str = \str_replace (
409
416
$ this ->symbUnescapedRel . $ this ->symbUnescapedRel ,
410
417
$ this ->stringSafe ,
411
418
$ str
412
419
);
413
420
414
- // split on sepData if not escaped (negative lookbehind)
421
+ // split on " sepData" if not escaped (negative lookbehind)
415
422
$ matches = \preg_split (
416
423
self ::$ DELIMITER . "(?<! " . $ this ->symbRel . ") " . $ this ->sepData . self ::$ DELIMITER ,
417
424
$ str
418
425
);
426
+ // fallback
427
+ if ($ matches === false ) {
428
+ $ matches = [];
429
+ }
419
430
420
431
foreach ($ matches as &$ value ) {
432
+ if ($ value === '' ) {
433
+ continue ;
434
+ }
421
435
422
436
// INFO:
423
437
//
@@ -439,15 +453,11 @@ private function splitSegment(string &$str): array
439
453
}
440
454
}
441
455
442
- // split on sepComp
456
+ // split on " sepComp"
443
457
$ value = $ this ->splitData ($ value );
444
458
}
445
459
unset($ value );
446
460
447
- if ($ matches === false ) {
448
- $ matches = [];
449
- }
450
-
451
461
return $ matches ;
452
462
}
453
463
@@ -481,15 +491,20 @@ private function splitData(string &$str)
481
491
);
482
492
};
483
493
494
+ // check for "sepUnescapedComp" in the string
484
495
if (\strpos ($ str , $ this ->sepUnescapedComp ) === false ) {
485
496
return $ replace ($ str );
486
497
}
487
498
488
- // split on sepComp if not escaped (negative lookbehind)
499
+ // split on " sepComp" if not escaped (negative lookbehind)
489
500
$ array = \preg_split (
490
501
self ::$ DELIMITER . "(?<! " . $ this ->symbRel . ") " . $ this ->sepComp . self ::$ DELIMITER ,
491
502
$ str
492
503
);
504
+ // fallback
505
+ if ($ array === false ) {
506
+ $ array = [[]];
507
+ }
493
508
494
509
if (\count ($ array ) === 1 ) {
495
510
return $ replace ($ str );
0 commit comments