Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. StringLiteral.php

function StringLiteral::setRaw

Sets node's raw value

Parameters

mixed $raw Raw value:

Return value

$this

Throws

\Exception

Overrides Literal::setRaw

File

vendor/mck89/peast/lib/Peast/Syntax/Node/StringLiteral.php, line 71

Class

StringLiteral
A node that represents a string literal.

Namespace

Peast\Syntax\Node

Code

public function setRaw($raw) {
    if (!is_string($raw) || strlen($raw) < 2) {
        throw new \Exception("Invalid string");
    }
    $startQuote = $raw[0];
    $endQuote = substr($raw, -1);
    if ($startQuote !== "'" && $startQuote !== '"' || $startQuote !== $endQuote) {
        throw new \Exception("Invalid string");
    }
    $this->value = Utils::unquoteLiteralString($raw);
    $this->setFormat($raw[0] === "'" ? self::SINGLE_QUOTED : self::DOUBLE_QUOTED);
    $this->raw = $raw;
    return $this;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal