This repository has been archived by the owner on Mar 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move blockStringValue into a separate file
- Loading branch information
Showing
8 changed files
with
137 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: chris | ||
* Date: 26/02/2018 | ||
* Time: 14.17 | ||
*/ | ||
|
||
namespace Digia\GraphQL\Language\AST\Visitor; | ||
|
||
class AbstractVisitor | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: chris | ||
* Date: 26/02/2018 | ||
* Time: 14.20 | ||
*/ | ||
|
||
namespace Digia\GraphQL\Language\AST\Visitor; | ||
|
||
trait AcceptVisitorTrait | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: chris | ||
* Date: 26/02/2018 | ||
* Time: 14.13 | ||
*/ | ||
|
||
namespace Digia\GraphQL\Language\AST\Visitor; | ||
|
||
interface VisitorInterface | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace Digia\GraphQL\Language; | ||
|
||
interface PrinterInterface | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: chris | ||
* Date: 26/02/2018 | ||
* Time: 14.07 | ||
*/ | ||
|
||
namespace Digia\GraphQL\Language; | ||
|
||
class Printer | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
namespace Digia\GraphQL\Language; | ||
|
||
/** | ||
* Produces the value of a block string from its parsed raw value, similar to | ||
* Coffeescript's block string, Python's docstring trim or Ruby's strip_heredoc. | ||
* This implements the GraphQL spec's BlockStringValue() static algorithm. | ||
* | ||
* @param string $rawString | ||
* @return string | ||
*/ | ||
function blockStringValue(string $rawString): string | ||
{ | ||
$lines = preg_split("/\r\n|[\n\r]/", $rawString); | ||
$lineCount = count($lines); | ||
|
||
$commonIndent = null; | ||
|
||
for ($i = 1; $i < $lineCount; $i++) { | ||
$line = $lines[$i]; | ||
$indent = leadingWhitespace($line); | ||
|
||
if ($indent < mb_strlen($line) && ($commonIndent === null || $indent < $commonIndent)) { | ||
$commonIndent = $indent; | ||
|
||
if ($commonIndent === 0) { | ||
break; | ||
} | ||
} | ||
} | ||
|
||
if ($commonIndent > 0) { | ||
for ($i = 1; $i < $lineCount; $i++) { | ||
$lines[$i] = sliceString($lines[$i], $commonIndent); | ||
} | ||
} | ||
|
||
while (count($lines) > 0 && isBlank($lines[0])) { | ||
array_shift($lines); | ||
} | ||
|
||
while (($lineCount = count($lines)) > 0 && isBlank($lines[$lineCount - 1])) { | ||
array_pop($lines); | ||
} | ||
|
||
return implode("\n", $lines); | ||
} | ||
|
||
/** | ||
* @param string $string | ||
* @return int | ||
*/ | ||
function leadingWhitespace(string $string): int | ||
{ | ||
$i = 0; | ||
$length = mb_strlen($string); | ||
while ($i < $length && ($string[$i] === ' ' || $string[$i] === "\t")) { | ||
$i++; | ||
} | ||
return $i; | ||
} | ||
|
||
/** | ||
* @param string $string | ||
* @return bool | ||
*/ | ||
function isBlank(string $string): bool | ||
{ | ||
return leadingWhitespace($string) === mb_strlen($string); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters