mirror of
https://github.com/parsecsv/parsecsv-for-php.git
synced 2026-02-19 08:36:39 +00:00
Added support for mb_convert_encoding() instead of iconv()
See issue #109 at GitHub
This commit is contained in:
@@ -220,6 +220,16 @@ class parseCSV {
|
|||||||
*/
|
*/
|
||||||
public $output_encoding = 'ISO-8859-1';
|
public $output_encoding = 'ISO-8859-1';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to use mb_convert_encoding() instead of iconv().
|
||||||
|
*
|
||||||
|
* The former is platform-independent whereas the latter is the traditional
|
||||||
|
* default go-to solution.
|
||||||
|
*
|
||||||
|
* @var bool (if false, iconv() is used)
|
||||||
|
*/
|
||||||
|
public $use_mb_convert_encoding = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Linefeed
|
* Linefeed
|
||||||
* Line feed characters used by unparse, save, and output methods
|
* Line feed characters used by unparse, save, and output methods
|
||||||
@@ -817,7 +827,9 @@ class parseCSV {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($this->convert_encoding && $this->input_encoding !== $this->output_encoding) {
|
if ($this->convert_encoding && $this->input_encoding !== $this->output_encoding) {
|
||||||
$data = iconv($this->input_encoding, $this->output_encoding, $data);
|
$data = $this->use_mb_convert_encoding ?
|
||||||
|
mb_convert_encoding($data, $this->output_encoding, $this->input_encoding) :
|
||||||
|
iconv($this->input_encoding, $this->output_encoding, $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (substr($data, -1) != "\n") {
|
if (substr($data, -1) != "\n") {
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ class worthless_properties_Test extends PHPUnit\Framework\TestCase {
|
|||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
public function test_propertiesCount() {
|
public function test_propertiesCount() {
|
||||||
$this->assertCount(27, $this->properties);
|
$this->assertCount(28, $this->properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -79,7 +79,7 @@ class worthless_properties_Test extends PHPUnit\Framework\TestCase {
|
|||||||
*/
|
*/
|
||||||
public function test_property_names() {
|
public function test_property_names() {
|
||||||
//set our expected properties name(s)
|
//set our expected properties name(s)
|
||||||
$names = array(
|
$expected_names = array(
|
||||||
'heading',
|
'heading',
|
||||||
'fields',
|
'fields',
|
||||||
'sort_by',
|
'sort_by',
|
||||||
@@ -97,6 +97,7 @@ class worthless_properties_Test extends PHPUnit\Framework\TestCase {
|
|||||||
'convert_encoding',
|
'convert_encoding',
|
||||||
'input_encoding',
|
'input_encoding',
|
||||||
'output_encoding',
|
'output_encoding',
|
||||||
|
'use_mb_convert_encoding',
|
||||||
'linefeed',
|
'linefeed',
|
||||||
'output_delimiter',
|
'output_delimiter',
|
||||||
'output_filename',
|
'output_filename',
|
||||||
@@ -109,19 +110,13 @@ class worthless_properties_Test extends PHPUnit\Framework\TestCase {
|
|||||||
'data'
|
'data'
|
||||||
);
|
);
|
||||||
|
|
||||||
//find our real properties
|
// Find our real properties
|
||||||
$real_properties = [];
|
$real_properties = array_map(function (ReflectionProperty $property) {
|
||||||
for ($a = 0; $a < count($this->properties); $a++) {
|
return $property->getName();
|
||||||
$real_properties[] = $this->properties[$a]->getName();
|
}, $this->properties);
|
||||||
}
|
|
||||||
|
|
||||||
//lets make sure our expected matches the number of real properties
|
// Lets make sure our expected matches the number of real properties
|
||||||
$this->assertCount(count($names), $this->properties);
|
$this->assertEquals($expected_names, $real_properties);
|
||||||
|
|
||||||
//lets loop through our expected to make sure they exists
|
|
||||||
for ($a = 0; $a < count($names); $a++) {
|
|
||||||
$this->assertTrue(in_array($names[$a], $real_properties));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user