You are here

protected function EasyRdf_Serialiser_Ntriples::unicodeCharNo in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/Ntriples.php \EasyRdf_Serialiser_Ntriples::unicodeCharNo()

@ignore

1 call to EasyRdf_Serialiser_Ntriples::unicodeCharNo()
EasyRdf_Serialiser_Ntriples::escapedChar in vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/Ntriples.php
@ignore

File

vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/Ntriples.php, line 74

Class

EasyRdf_Serialiser_Ntriples
Class to serialise an EasyRdf_Graph to N-Triples with no external dependancies.

Code

protected function unicodeCharNo($c) {
  $cUtf = utf8_encode($c);
  $bl = strlen($cUtf);

  /* binary length */
  $r = 0;
  switch ($bl) {
    case 1:

      /* 0####### (0-127) */
      $r = ord($cUtf);
      break;
    case 2:

      /* 110##### 10###### = 192+x 128+x */
      $r = (ord($cUtf[0]) - 192) * 64 + (ord($cUtf[1]) - 128);
      break;
    case 3:

      /* 1110#### 10###### 10###### = 224+x 128+x 128+x */
      $r = (ord($cUtf[0]) - 224) * 4096 + (ord($cUtf[1]) - 128) * 64 + (ord($cUtf[2]) - 128);
      break;
    case 4:

      /* 1111#### 10###### 10###### 10###### = 240+x 128+x 128+x 128+x */
      $r = (ord($cUtf[0]) - 240) * 262144 + (ord($cUtf[1]) - 128) * 4096 + (ord($cUtf[2]) - 128) * 64 + (ord($cUtf[3]) - 128);
      break;
  }
  return $r;
}