Skip to content

Commit a7f3613

Browse files
committed
up: add new string util method Str.shellQuotesToLine()
1 parent aa7b587 commit a7f3613

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/Str/StringHelper.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
use DateTime;
1313
use Exception;
14-
use JetBrains\PhpStorm\Pure;
1514
use Stringable;
1615
use Toolkit\Stdlib\Str\Traits\StringCaseHelperTrait;
1716
use Toolkit\Stdlib\Str\Traits\StringCheckHelperTrait;
@@ -435,6 +434,19 @@ public static function shellQuotes(array $args): array
435434
return $newArgs;
436435
}
437436

437+
/**
438+
* @param array $args
439+
* @param string $prefix
440+
*
441+
* @return string
442+
*/
443+
public static function shellQuotesToLine(array $args, string $prefix = ''): string
444+
{
445+
$args = self::shellQuotes($args);
446+
447+
return ($prefix ? $prefix . ' ': '') . implode(' ', $args);
448+
}
449+
438450
/**
439451
* @param string $arg
440452
*
@@ -449,6 +461,6 @@ public static function shellQuote(string $arg): string
449461
$quote = '"';
450462
}
451463

452-
return $quote ? $arg : "$quote$arg$quote";
464+
return $quote ? "$quote$arg$quote" : $arg;
453465
}
454466
}

0 commit comments

Comments
 (0)