protected function EasyRdf_Parser_Turtle::parseQuotedLiteral

Parses a quoted string, optionally followed by a language tag or datatype.

@ignore

Parameters

string $quote The type of quote to use (either ' or "):

1 call to EasyRdf_Parser_Turtle::parseQuotedLiteral()
EasyRdf_Parser_Turtle::parseValue in drupal/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Turtle.php
Parses an RDF value. This method parses uriref, qname, node ID, quoted literal, integer, double and boolean. @ignore

File

drupal/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Turtle.php, line 506

Class

EasyRdf_Parser_Turtle
Class to parse Turtle with no external dependancies.

Code

protected function parseQuotedLiteral($quote) {
  $label = $this
    ->parseQuotedString($quote);

  // Check for presence of a language tag or datatype
  $c = $this
    ->peek();
  if ($c == '@') {
    $this
      ->read();

    // Read language
    $lang = '';
    $c = $this
      ->read();
    if ($c == -1) {
      throw new EasyRdf_Exception("Turtle Parse Error: unexpected end of file while reading language");
    }
    elseif (!self::isLanguageStartChar($c)) {
      throw new EasyRdf_Exception("Turtle Parse Error: expected a letter, found '{$c}'");
    }
    $lang .= $c;
    $c = $this
      ->read();
    while (self::isLanguageChar($c)) {
      $lang .= $c;
      $c = $this
        ->read();
    }
    $this
      ->unread($c);
    return array(
      'type' => 'literal',
      'value' => $label,
      'lang' => $lang,
    );
  }
  elseif ($c == '^') {
    $this
      ->read();

    // next character should be another '^'
    $this
      ->verifyCharacter($this
      ->read(), "^");

    // Read datatype
    $datatype = $this
      ->parseValue();
    if ($datatype['type'] == 'uri') {
      return array(
        'type' => 'literal',
        'value' => $label,
        'datatype' => $datatype['value'],
      );
    }
    else {
      throw new EasyRdf_Exception("Turtle Parse Error: illegal datatype value: {$datatype}");
    }
  }
  else {
    return array(
      'type' => 'literal',
      'value' => $label,
    );
  }
}