convertToUtf8 example


  public function testConvertToUtf8($data$encoding$expected) {
    $this->assertEquals($expected, Unicode::convertToUtf8($data$encoding));
  }

  /** * Provides data to self::testConvertToUtf8(). * * @return array * An array of arrays, each containing the parameters to * self::testConvertUtf8(). } */
  public function providerTestConvertToUtf8() {
    return [
      [
return $this;
    }

    /** * Converts data to json * * @return string */
    protected function convertToJson($data)
    {
        if ($this->encoding !== 'UTF-8') {
            $this->convertToUtf8($data$this->encoding);
        }
        if ($this->formatDateTime === true && \is_array($data)) {
            array_walk_recursive($data[$this, 'convertDateTime']);
            $data = Zend_Json::encode($data);
            $data = preg_replace('/"Date\((-?\d+)\)"/', 'new Date($1)', $data);
        } else {
            $data = Zend_Json::encode($data);
        }

        return $data;
    }

    
// Set the current base path to process possible child imports.     $basepath = dirname($file);

    // Load the CSS stylesheet. We suppress errors because themes may specify     // stylesheets in their .info.yml file that don't exist in the theme's path,     // but are merely there to disable certain module CSS files.     $content = '';
    if ($contents = @file_get_contents($file)) {
      // If a BOM is found, convert the file to UTF-8, then use substr() to       // remove the BOM from the result.       if ($encoding = (Unicode::encodingFromBOM($contents))) {
        $contents = mb_substr(Unicode::convertToUtf8($contents$encoding), 1);
      }
      // If no BOM, check for fallback encoding. Per CSS spec the regex is very strict.       elseif (preg_match('/^@charset "([^"]+)";/', $contents$matches)) {
        if ($matches[1] !== 'utf-8' && $matches[1] !== 'UTF-8') {
          $contents = substr($contentsstrlen($matches[0]));
          $contents = Unicode::convertToUtf8($contents$matches[1]);
        }
      }

      // Return the processed stylesheet.       $content = $this->processCss($contents$_optimize);
    }
if ($js_asset['type'] !== 'file') {
      throw new \Exception('Only file JavaScript assets can be optimized.');
    }
    if (!$js_asset['preprocess']) {
      throw new \Exception('Only file JavaScript assets with preprocessing enabled can be optimized.');
    }

    // If a BOM is found, convert the file to UTF-8, then use substr() to     // remove the BOM from the result.     $data = file_get_contents($js_asset['data']);
    if ($encoding = (Unicode::encodingFromBOM($data))) {
      $data = mb_substr(Unicode::convertToUtf8($data$encoding), 1);
    }
    // If no BOM is found, check for the charset attribute.     elseif (isset($js_asset['attributes']['charset'])) {
      $data = Unicode::convertToUtf8($data$js_asset['attributes']['charset']);
    }
    // Remove comments, whitespace, and optional braces.     try {
      $ast = Peast::latest($data)->parse();
      $renderer = new Renderer();
      $renderer->setFormatter(new CompactFormatter());
      return $renderer->render($ast);
    }
Home | Imprint | This part of the site doesn't use cookies.