classStrings
final class Strings
Decodes the spelling of a PostgreSQL string constant token into its value.
Rule: PG-LEX-STRING-001. Scope: the SCONST terminal in its four spellings and the BCONST and XCONST terminals. '...' reads a doubled quote as one quote and nothing else, because the profile fixes standard_conforming_strings = on. E'...' additionally reads the backslash escapes of the manual. $tag$...$tag$ is taken literally. U&'...' reads Unicode escapes with the escape character of its UESCAPE clause. Quoted segments separated by whitespace that contains a newline are one constant. An escape string that produces a zero byte or bytes that are not UTF-8 is rejected by the server scanner and is SQL outside the grammar. Source: https://www.postgresql.org/docs/17/sql-syntax-lexical.html#SQL-SYNTAX-CONSTANTS. Termination: one pass over the token text. Status: Implemented.
Methods§
public function decode(string $text): stringDecodes the text of a string constant token.
Parameters
$text | string |
Returns
stringThrows
AnalysisException When the scanner `scan.l` rejects the constant (invalid encoding of an escape string, invalid Unicode escape)Test cases 8
StringsTest::testDecodeJoinsASurrogatePairOfAnEscapeStringcallsStringsTest::testDecodeJoinsSegmentsContinuedOnAnotherLinecallsStringsTest::testDecodeReadsADoubledQuoteOfAStandardStringcallsStringsTest::testDecodeReadsTheEscapesOfAnEscapeStringcallsStringsTest::testDecodeRejectsAZeroByteFromAnEscapecallsStringsTest::testDecodeRejectsBytesThatAreNotUtf8callsStringsTest::testDecodeReplacesTheEscapesOfAUnicodeStringcallsStringsTest::testDecodeTakesADollarQuotedStringLiterallycalls
Called from 2
Calls 11
- function-call
str_starts_withline 42 - function-call
strposline 43 - function-call
substrline 45 - function-call
strlenline 45 - function-call
preg_matchline 47 - method-call Strings::quoted() line 48
- function-call
trimline 49 - method-call UnicodeEscapes::decode() line 51
- new UnicodeEscapes line 51
- function-call
str_containsline 55 - new AnalysisException line 56
public function digits(string $text): stringAnswers the digits written between the quotes of a bit-string or hexadecimal constant token.
Parameters
$text | string |
Returns
stringTest cases 1
Called from 4
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Leaf\Literals::constant() packages/sql-semantics-postgres/src/Lowering/Leaf/Literals.php:189
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Leaf\Literals::constant() packages/sql-semantics-postgres/src/Lowering/Leaf/Literals.php:190
- method-call SqlSemantics\Platform\PostgreSql\Rules\LeafKeys::key() packages/sql-semantics-postgres/src/Rules/LeafKeys.php:67
- method-call SqlSemantics\Platform\PostgreSql\Rules\LeafKeys::key() packages/sql-semantics-postgres/src/Rules/LeafKeys.php:68
Calls 4
- function-call
strposline 73 - static-call Check::invariant() line 74
- function-call
substrline 75 - method-call Strings::continuation() line 76
public function quoted(string $text, int $offset, bool $escapes): array{string, string}Reads the quoted segments that start at an offset and answers the value and the text after them.
Parameters
$text | string | |
$offset | int | |
$escapes | bool |
Returns
array{string, string}Test cases 1
Called from 3
- method-call SqlSemantics\Platform\PostgreSql\Rules\Lexical\Strings::decode() packages/sql-semantics-postgres/src/Rules/Lexical/Strings.php:48
- method-call SqlSemantics\Platform\PostgreSql\Rules\Lexical\Strings::decode() packages/sql-semantics-postgres/src/Rules/Lexical/Strings.php:54
- method-call SqlSemantics\Platform\PostgreSql\Rules\Lexical\Strings::decode() packages/sql-semantics-postgres/src/Rules/Lexical/Strings.php:62
Calls 6
- function-call
strcspnline 97 - function-call
substrline 98 - static-call Check::invariant() line 100
- function-call
strlenline 100 - method-call Strings::escape() line 102
- method-call Strings::continuation() line 114
public function continuation(string $text, int $offset): ?intFinds the quote that continues a constant after whitespace and comments, or null.
Parameters
$text | string | |
$offset | int |
Returns
?intTest cases 1
Called from 2
public function escape(string $text, int $offset): array{string, int}Decodes the backslash escape at an offset of an escape string.
Parameters
$text | string | |
$offset | int |
Returns
array{string, int} The bytes it stands for and the offset after itThrows
AnalysisException When the `xeunicode` rules of the scanner `scan.l` reject the escapeTest cases 2
Called from 1
Calls 9
- function-call
preg_matchline 143 - new AnalysisException line 146
- class-const Strings::SINGLE() line 149
- function-call
strlenline 151 - function-call
chrline 153 - function-call
octdecline 153 - function-call
hexdecline 156 - method-call UnicodeEscapes::encode() line 168
- new UnicodeEscapes line 168
Private surface 1§
Implementation details, listed for orientation only.
private const SINGLE = ['b' => "\x08", 'f' => "\f", 'n' => "\n", 'r' => "\r", 't' => "\t", 'v' => "\v"]Test cases 13§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 13
StringsTest::testContinuationFindsTheNextQuoteAfterANewlinecallsStringsTest::testDecodeJoinsASurrogatePairOfAnEscapeStringcallsStringsTest::testDecodeJoinsSegmentsContinuedOnAnotherLinecallsStringsTest::testDecodeReadsADoubledQuoteOfAStandardStringcallsStringsTest::testDecodeReadsTheEscapesOfAnEscapeStringcallsStringsTest::testDecodeRejectsAZeroByteFromAnEscapecallsStringsTest::testDecodeRejectsBytesThatAreNotUtf8callsStringsTest::testDecodeReplacesTheEscapesOfAUnicodeStringcallsStringsTest::testDecodeTakesADollarQuotedStringLiterallycallsStringsTest::testDigitsAnswersTheTextBetweenTheQuotescallsStringsTest::testEscapeDecodesOneBackslashEscapecallsStringsTest::testEscapeRejectsAnIncompleteUnicodeEscapecallsStringsTest::testQuotedAnswersTheValueAndTheTextAfterItcalls
Relations§
Instantiated in 5
- new SqlSemantics\Platform\PostgreSql\Lowering\Leaf\Literals::stringToken() packages/sql-semantics-postgres/src/Lowering/Leaf/Literals.php:62
- new SqlSemantics\Platform\PostgreSql\Lowering\Leaf\Literals::constant() packages/sql-semantics-postgres/src/Lowering/Leaf/Literals.php:183
- new SqlSemantics\Platform\PostgreSql\Rules\LeafKeys::key() packages/sql-semantics-postgres/src/Rules/LeafKeys.php:66
- new SqlSemantics\Platform\PostgreSql\Rules\LeafKeys::key() packages/sql-semantics-postgres/src/Rules/LeafKeys.php:67
- new SqlSemantics\Platform\PostgreSql\Rules\LeafKeys::key() packages/sql-semantics-postgres/src/Rules/LeafKeys.php:68
Method calls 6
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Leaf\Literals::stringToken() packages/sql-semantics-postgres/src/Lowering/Leaf/Literals.php:62
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Leaf\Literals::constant() packages/sql-semantics-postgres/src/Lowering/Leaf/Literals.php:189
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Leaf\Literals::constant() packages/sql-semantics-postgres/src/Lowering/Leaf/Literals.php:190
- method-call SqlSemantics\Platform\PostgreSql\Rules\LeafKeys::key() packages/sql-semantics-postgres/src/Rules/LeafKeys.php:66
- method-call SqlSemantics\Platform\PostgreSql\Rules\LeafKeys::key() packages/sql-semantics-postgres/src/Rules/LeafKeys.php:67
- method-call SqlSemantics\Platform\PostgreSql\Rules\LeafKeys::key() packages/sql-semantics-postgres/src/Rules/LeafKeys.php:68