protected function EasyRdf_Parser_Ntriples::unescapeString in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/Ntriples.php \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 vendor/easyrdf/ easyrdf/ lib/ EasyRdf/ Parser/ Ntriples.php 
- Parse an N-Triples document into an EasyRdf_Graph
- EasyRdf_Parser_Ntriples::parseNtriplesObject in vendor/easyrdf/ easyrdf/ lib/ EasyRdf/ Parser/ Ntriples.php 
- @ignore
- EasyRdf_Parser_Ntriples::parseNtriplesSubject in vendor/easyrdf/ easyrdf/ lib/ EasyRdf/ Parser/ Ntriples.php 
- @ignore
- EasyRdf_Parser_Turtle::parseQuotedString in vendor/easyrdf/ easyrdf/ lib/ EasyRdf/ Parser/ Turtle.php 
- Parses a quoted string, which is either a "normal string" or a """long string""". @ignore
- EasyRdf_Parser_Turtle::parseURI in vendor/easyrdf/ easyrdf/ lib/ EasyRdf/ Parser/ Turtle.php 
- Parses a URI / IRI @ignore
File
- vendor/easyrdf/ easyrdf/ lib/ EasyRdf/ Parser/ Ntriples.php, line 54 
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) {
      // 0x80
      $char = chr($no);
    }
    elseif ($no < 2048) {
      // 0x800
      $char = chr(($no >> 6) + 192) . chr(($no & 63) + 128);
    }
    elseif ($no < 65536) {
      // 0x10000
      $char = chr(($no >> 12) + 224) . chr(($no >> 6 & 63) + 128) . chr(($no & 63) + 128);
    }
    elseif ($no < 2097152) {
      // 0x200000
      $char = chr(($no >> 18) + 240) . chr(($no >> 12 & 63) + 128) . chr(($no >> 6 & 63) + 128) . chr(($no & 63) + 128);
    }
    else {
      # FIXME: throw an exception instead?
      $char = '';
    }
    $str = str_replace('\\' . $matches[1] . $matches[2], $char, $str);
  }
  return $str;
}