function DoubleQuote::parse
Overrides PartParser::parse
File
-
vendor/
egulias/ email-validator/ src/ Parser/ DoubleQuote.php, line 16
Class
Namespace
Egulias\EmailValidator\ParserCode
public function parse() : Result {
$validQuotedString = $this->checkDQUOTE();
if ($validQuotedString->isInvalid()) {
return $validQuotedString;
}
$special = [
EmailLexer::S_CR => true,
EmailLexer::S_HTAB => true,
EmailLexer::S_LF => true,
];
$invalid = [
EmailLexer::C_NUL => true,
EmailLexer::S_HTAB => true,
EmailLexer::S_CR => true,
EmailLexer::S_LF => true,
];
$setSpecialsWarning = true;
$this->lexer
->moveNext();
while (!$this->lexer->current
->isA(EmailLexer::S_DQUOTE) && !$this->lexer->current
->isA(EmailLexer::S_EMPTY)) {
if (isset($special[$this->lexer->current->type]) && $setSpecialsWarning) {
$this->warnings[CFWSWithFWS::CODE] = new CFWSWithFWS();
$setSpecialsWarning = false;
}
if ($this->lexer->current
->isA(EmailLexer::S_BACKSLASH) && $this->lexer
->isNextToken(EmailLexer::S_DQUOTE)) {
$this->lexer
->moveNext();
}
$this->lexer
->moveNext();
if (!$this->escaped() && isset($invalid[$this->lexer->current->type])) {
return new InvalidEmail(new ExpectingATEXT("Expecting ATEXT between DQUOTE"), $this->lexer->current->value);
}
}
$prev = $this->lexer
->getPrevious();
if ($prev->isA(EmailLexer::S_BACKSLASH)) {
$validQuotedString = $this->checkDQUOTE();
if ($validQuotedString->isInvalid()) {
return $validQuotedString;
}
}
if (!$this->lexer
->isNextToken(EmailLexer::S_AT) && !$prev->isA(EmailLexer::S_BACKSLASH)) {
return new InvalidEmail(new ExpectingATEXT("Expecting ATEXT between DQUOTE"), $this->lexer->current->value);
}
return new ValidEmail();
}