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

@@ -72,7 +72,7 @@ final class ID3_Frame_SYLT extends ID3_Frame
"Chord", "Trivia", "URLs to webpages", "URLs to images");
/** @var integer */
private $_encoding = ID3_Encoding::UTF8;
private $_encoding;
/** @var string */
private $_language = "und";
@@ -99,10 +99,12 @@ final class ID3_Frame_SYLT 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->_language = substr($this->_data, 1, 3);
if ($this->_language == "XXX")
$this->_language = "und";
@@ -110,39 +112,57 @@ final class ID3_Frame_SYLT extends ID3_Frame
$this->_type = Transform::fromUInt8($this->_data[5]);
$this->_data = substr($this->_data, 6);
switch ($this->_encoding) {
switch ($encoding) {
case self::UTF16:
list($this->_description, $this->_data) =
$this->explodeString16($this->_data, 2);
$this->_description = Transform::fromString16($this->_description);
$this->_description = $this->convertString
(Transform::fromString16($this->_description), "utf-16");
break;
case self::UTF16BE:
list($this->_description, $this->_data) =
$this->explodeString16($this->_data, 2);
$this->_description = Transform::fromString16BE($this->_description);
$this->_description = $this->convertString
(Transform::fromString16BE($this->_description), "utf-16be");
break;
case self::UTF8:
list($this->_description, $this->_data) =
$this->explodeString8($this->_data, 2);
$this->_description = $this->convertString
(Transform::fromString8($this->_description), "utf-8");
break;
default:
list($this->_description, $this->_data) =
$this->explodeString8($this->_data, 2);
$this->_description = Transform::fromString8($this->_description);
$this->_description = $this->convertString
(Transform::fromString8($this->_description), "iso-8859-1");
}
while (strlen($this->_data) > 0) {
switch ($this->_encoding) {
switch ($encoding) {
case self::UTF16:
list($syllable, $this->_data) =
$this->explodeString16($this->_data, 2);
$syllable = Transform::fromString16($syllable);
$syllable = $this->convertString
(Transform::fromString16($syllable), "utf-16");
break;
case self::UTF16BE:
list($syllable, $this->_data) =
$this->explodeString16($this->_data, 2);
$syllable = Transform::fromString16BE($syllable);
$syllable = $this->convertString
(Transform::fromString16BE($syllable), "utf-16be");
break;
case self::UTF8:
list($syllable, $this->_data) =
$this->explodeString8($this->_data, 2);
$syllable = $this->convertString
(Transform::fromString8($syllable), "utf-8");
break;
default:
list($syllable, $this->_data) =
$this->explodeString8($this->_data, 2);
$syllable = Transform::fromString8($syllable);
$syllable = $this->convertString
(Transform::fromString8($syllable), "iso-8859-1");
}
$this->_events[Transform::fromUInt32BE(substr($this->_data, 0, 4))] =
$syllable;
@@ -154,6 +174,11 @@ final class ID3_Frame_SYLT extends ID3_Frame
/**
* 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; }
@@ -161,6 +186,12 @@ final class ID3_Frame_SYLT 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.
*/