You are here

private static function ChartDataCollectorTable::convertEncoding in Charts 5.0.x

Same name and namespace in other branches
  1. 8.4 src/Element/ChartDataCollectorTable.php \Drupal\charts\Element\ChartDataCollectorTable::convertEncoding()

Helper function to detect and convert strings not in UTF-8 to UTF-8.

Parameters

string $data: The string which needs converting.

string $encoding: The encoding of the CSV file.

Return value

string UTF encoded string.

1 call to ChartDataCollectorTable::convertEncoding()
ChartDataCollectorTable::importCsvToTableSubmit in src/Element/ChartDataCollectorTable.php
Submit callback for table csv import operations.

File

src/Element/ChartDataCollectorTable.php, line 709

Class

ChartDataCollectorTable
Provides a chart data collector table form element.

Namespace

Drupal\charts\Element

Code

private static function convertEncoding($data, $encoding) {

  // Converting UTF-8 to UTF-8 will not work.
  if ($encoding == 'UTF-8') {
    return $data;
  }

  // Try convert the data to UTF-8.
  if ($encoded_data = Unicode::convertToUtf8($data, $encoding)) {
    return $encoded_data;
  }

  // Fallback on the input data.
  return $data;
}