Simplify uuid_dashify

This commit is contained in:
ruan 2018-09-22 14:39:21 +02:00
parent f35efe70de
commit ac9219e06a
No known key found for this signature in database
GPG Key ID: 0D2EC1C52E469C0B

View File

@ -411,17 +411,15 @@ class Page {
$len = strlen($str); $len = strlen($str);
if ($len !== 32) return $str; if ($len !== 32) return $str;
$newstr = ""; $newstr = "";
$total = 0; // current character (all chars)
$cur = 0; // current position in chunk, resets to 0 when it reaches limit $cur = 0; // current position in chunk, resets to 0 when it reaches limit
$chunk = 0; // current amount of "-" characters, 5 chunks are in a UUID (1-2-3-4-5) $chunk = 0; // current amount of "-" characters, 5 chunks are in a UUID (1-2-3-4-5)
$limit = 8; // maximum amount of characters in the current chunk (8-4-4-4-12) $limit = 8; // maximum amount of characters in the current chunk (8-4-4-4-12)
for ($i = 0; $i < $len; $i++) { for ($i = 0; $i < $len; $i++) {
$chr = $str[$i]; $chr = $str[$i];
$total++;
$newstr .= $chr; $newstr .= $chr;
if (++$cur >= $limit) { if (++$cur >= $limit) {
$cur = 0; $cur = 0;
if ($total < 32) { if ($i < 32) {
$newstr .= '-'; $newstr .= '-';
} }
$chunk++; $chunk++;