Add support for encoding option

git-svn-id: http://php-reader.googlecode.com/svn/trunk@129 51a70ab9-7547-0410-9469-37e369ee0574
This commit is contained in:
svollbehr
2008-12-28 19:00:44 +00:00
parent b4cae3bf42
commit c97e87fbc6
16 changed files with 602 additions and 276 deletions

View File

@@ -59,7 +59,7 @@ abstract class ID3_Frame_AbstractText extends ID3_Frame
*
* @var integer
*/
protected $_encoding = ID3_Encoding::UTF8;
protected $_encoding;
/**
* The text array.
@@ -78,29 +78,43 @@ abstract class ID3_Frame_AbstractText extends ID3_Frame
{
parent::__construct($reader, $options);
$this->_encoding = $this->getOption("encoding", ID3_Encoding::UTF8);
if ($reader === null)
return;
$this->_encoding = Transform::fromUInt8($this->_data[0]);
$encoding = Transform::fromUInt8($this->_data[0]);
$this->_data = substr($this->_data, 1);
switch ($this->_encoding) {
switch ($encoding) {
case self::UTF16:
$this->_text =
$this->explodeString16(Transform::fromString16($this->_data));
$this->_text = $this->convertString
($this->explodeString16(Transform::fromString16($this->_data)),
"utf-16");
break;
case self::UTF16BE:
$this->_text =
$this->explodeString16(Transform::fromString16BE($this->_data));
$this->_text = $this->convertString
($this->explodeString16(Transform::fromString16BE($this->_data)),
"utf-16be");
break;
case self::UTF8:
$this->_text = $this->convertString
($this->explodeString8(Transform::fromString8($this->_data)), "utf-8");
break;
default:
$this->_text =
$this->explodeString8(Transform::fromString8($this->_data));
$this->_text = $this->convertString
($this->explodeString8(Transform::fromString8($this->_data)),
"iso-8859-1");
}
}
/**
* Returns the text encoding.
*
* All the strings read from a file are automatically converted to the
* character encoding specified with the <var>encoding</var> option. See
* {@link ID3v2} for details. This method returns the original text encoding
* used to write the frame.
*
* @return integer
*/
public function getEncoding() { return $this->_encoding; }
@@ -108,6 +122,12 @@ abstract class ID3_Frame_AbstractText extends ID3_Frame
/**
* Sets the text encoding.
*
* All the string written to the frame are done so using given character
* encoding. No conversions of existing data take place upon the call to this
* method thus all texts must be given in given character encoding.
*
* The default character encoding used to write the frame is UTF-8.
*
* @see ID3_Encoding
* @param integer $encoding The text encoding.
*/