Development

Changeset 12974

You must first sign up to be able to contribute.

Changeset 12974

Show
Ignore:
Timestamp:
11/13/08 14:09:32 (5 years ago)
Author:
Carlos.Escribano
Message:

iconv function support added into sfCsvReader and sfCsvWriter classes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfCsvPlugin/lib/sfCsvReader.class.php

    r12970 r12974  
    2626 * } 
    2727 * $csv->close(); 
     28 *  
     29 * 
     30 * --- CHARSET --- 
     31 * $to = 'ISO-8859-1'; 
     32 * $from = 'UTF-8'; 
     33 * $csv->setCharset($to); 
     34 * $csv->setCharset($to, $from);    
    2835 */ 
    2936class sfCsvReader 
     
    4047    $length, 
    4148    $delimiter, 
    42     $enclosure; 
     49    $enclosure, 
     50    $to, 
     51    $from; 
    4352   
    4453  /** 
     
    181190        foreach ($this->header['selected'] as $name) 
    182191        { 
    183           $res[$name] = $line[$this->header['map'][$name]]; 
     192          if ($this->to !== null) 
     193          { 
     194            $res[$name] = $this->encode($line[$this->header['map'][$name]], $this->to, $this->from); 
     195          } 
     196          else 
     197          { 
     198            $res[$name] = $line[$this->header['map'][$name]]; 
     199          } 
    184200        } 
    185201        return $res; 
     
    196212  } 
    197213   
     214  private function encode($str, $to, $from = null) 
     215  { 
     216    if ($from === null) 
     217    { 
     218      $from = mb_detect_encoding($str); 
     219    } 
     220     
     221    if (function_exists('iconv')) 
     222    { 
     223      return iconv($from, $to, $str); 
     224    } 
     225    else 
     226    { 
     227      return mb_convert_encoding($str, $to, $from); 
     228    } 
     229  } 
     230   
     231  public function setCharset($to, $from = null) 
     232  { 
     233    $this->to = $to; 
     234    $this->from = $from; 
     235  } 
     236   
    198237  function __destruct() 
    199238  { 
  • plugins/sfCsvPlugin/lib/sfCsvWriter.class.php

    r12970 r12974  
    103103    } 
    104104     
    105     return mb_convert_encoding($str, $to, $from); 
     105    if (function_exists('iconv')) 
     106    { 
     107      return iconv($from, $to, $str); 
     108    } 
     109    else 
     110    { 
     111      return mb_convert_encoding($str, $to, $from); 
     112    } 
    106113  } 
    107114   
  • plugins/sfCsvPlugin/package.xml

    r12970 r12974  
    1111  <active>yes</active> 
    1212 </lead> 
    13  <date>2008-10-10</date> 
    14  <time>10:37:33</time> 
     13 <date>2008-11-13</date> 
     14 <time>14:05:00</time> 
    1515 <version> 
    16   <release>0.1.0</release> 
    17   <api>0.1.0</api> 
     16  <release>0.1.1</release> 
     17  <api>0.1.1</api> 
    1818 </version> 
    1919 <stability> 
     
    5050 </dependencies> 
    5151 <phprelease /> 
    52  <changelog /> 
     52 <changelog> 
     53  <release> 
     54    <version> 
     55      <release>0.1.1</release> 
     56      <api>0.1.1</api> 
     57    </version> 
     58    <stability> 
     59      <release>beta</release> 
     60      <api>beta</api> 
     61    </stability> 
     62    <license uri="http://www.symfony-project.com/license">MIT license</license> 
     63    <notes> 
     64      * Roman ZajÄ…c added iconv / charset support into `sfCsvReader` class and I ported that iconv improvement to `sfCsvWriter` class `encode` method. 
     65    </notes> 
     66  </release> 
     67 </changelog> 
    5368</package>