protected function EasyRdf_Parser_Ntriples::unescapeString

Decodes an encoded N-Triples string. Any \-escape sequences are substituted with their decoded value.

Parameters

string $str An encoded N-Triples string.:

Return value

The unencoded string.

5 calls to EasyRdf_Parser_Ntriples::unescapeString()
EasyRdf_Parser_Ntriples::parse in drupal/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Ntriples.php
Parse an N-Triples document into an EasyRdf_Graph
EasyRdf_Parser_Ntriples::parseNtriplesObject in drupal/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Ntriples.php
@ignore
EasyRdf_Parser_Ntriples::parseNtriplesSubject in drupal/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Ntriples.php
@ignore
EasyRdf_Parser_Turtle::parseQuotedString in drupal/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Turtle.php
Parses a quoted string, which is either a "normal string" or a """long string""".
EasyRdf_Parser_Turtle::parseURI in drupal/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Turtle.php
Parses a URI / IRI @ignore

File

drupal/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Ntriples.php, line 55

Class

EasyRdf_Parser_Ntriples
A pure-php class to parse N-Triples with no dependancies.

Code

protected function unescapeString($str) {
  if (strpos($str, '\\') === false) {
    return $str;
  }
  $mappings = array(
    't' => chr(0x9),
    'b' => chr(0x8),
    'n' => chr(0xa),
    'r' => chr(0xd),
    'f' => chr(0xc),
    '\\"' => chr(0x22),
    '\'' => chr(0x27),
  );
  foreach ($mappings as $in => $out) {
    $str = preg_replace('/\\x5c([' . $in . '])/', $out, $str);
  }
  if (stripos($str, '\\u') === false) {
    return $str;
  }
  while (preg_match('/\\\\(U)([0-9A-F]{8})/', $str, $matches) || preg_match('/\\\\(u)([0-9A-F]{4})/', $str, $matches)) {
    $no = hexdec($matches[2]);
    if ($no < 128) {
      $char = chr($no);
    }
    elseif ($no < 2048) {
      $char = chr(($no >> 6) + 192) . chr(($no & 63) + 128);
    }
    elseif ($no < 65536) {
      $char = chr(($no >> 12) + 224) . chr(($no >> 6 & 63) + 128) . chr(($no & 63) + 128);
    }
    elseif ($no < 2097152) {
      $char = chr(($no >> 18) + 240) . chr(($no >> 12 & 63) + 128) . chr(($no >> 6 & 63) + 128) . chr(($no & 63) + 128);
    }
    else {
      $char = '';
    }
    $str = str_replace('\\' . $matches[1] . $matches[2], $char, $str);
  }
  return $str;
}