Commit 650d633d authored by Etienne CHAMPETIER's avatar Etienne CHAMPETIER

ZP-797 WBXML{En,De}coder: use const instead of define for WBXML_* constants.

Released under the Affero GNU General Public License (AGPL) version 3.

also move them inside WBXMLDefs
parent 3caccf58
......@@ -362,79 +362,79 @@ class WBXMLDecoder extends WBXMLDefs {
$byte = ord($byte);
switch($byte) {
case WBXML_SWITCH_PAGE:
case self::WBXML_SWITCH_PAGE:
$this->tagcp = $this->getByte();
break;
case WBXML_END:
case self::WBXML_END:
$element[EN_TYPE] = EN_TYPE_ENDTAG;
return $element;
case WBXML_ENTITY:
case self::WBXML_ENTITY:
$entity = $this->getMBUInt();
$element[EN_TYPE] = EN_TYPE_CONTENT;
$element[EN_CONTENT] = $this->entityToCharset($entity);
return $element;
case WBXML_STR_I:
case self::WBXML_STR_I:
$element[EN_TYPE] = EN_TYPE_CONTENT;
$element[EN_CONTENT] = $this->getTermStr();
return $element;
case WBXML_LITERAL:
case self::WBXML_LITERAL:
$element[EN_TYPE] = EN_TYPE_STARTTAG;
$element[EN_TAG] = $this->getStringTableEntry($this->getMBUInt());
$element[EN_FLAGS] = 0;
return $element;
case WBXML_EXT_I_0:
case WBXML_EXT_I_1:
case WBXML_EXT_I_2:
case self::WBXML_EXT_I_0:
case self::WBXML_EXT_I_1:
case self::WBXML_EXT_I_2:
$this->getTermStr();
// Ignore extensions
continue;
case WBXML_PI:
case self::WBXML_PI:
// Ignore PI
$this->getAttributes();
continue;
case WBXML_LITERAL_C:
case self::WBXML_LITERAL_C:
$element[EN_TYPE] = EN_TYPE_STARTTAG;
$element[EN_TAG] = $this->getStringTableEntry($this->getMBUInt());
$element[EN_FLAGS] = EN_FLAGS_CONTENT;
return $element;
case WBXML_EXT_T_0:
case WBXML_EXT_T_1:
case WBXML_EXT_T_2:
case self::WBXML_EXT_T_0:
case self::WBXML_EXT_T_1:
case self::WBXML_EXT_T_2:
$this->getMBUInt();
// Ingore extensions;
continue;
case WBXML_STR_T:
case self::WBXML_STR_T:
$element[EN_TYPE] = EN_TYPE_CONTENT;
$element[EN_CONTENT] = $this->getStringTableEntry($this->getMBUInt());
return $element;
case WBXML_LITERAL_A:
case self::WBXML_LITERAL_A:
$element[EN_TYPE] = EN_TYPE_STARTTAG;
$element[EN_TAG] = $this->getStringTableEntry($this->getMBUInt());
$element[EN_ATTRIBUTES] = $this->getAttributes();
$element[EN_FLAGS] = EN_FLAGS_ATTRIBUTES;
return $element;
case WBXML_EXT_0:
case WBXML_EXT_1:
case WBXML_EXT_2:
case self::WBXML_EXT_0:
case self::WBXML_EXT_1:
case self::WBXML_EXT_2:
continue;
case WBXML_OPAQUE:
case self::WBXML_OPAQUE:
$length = $this->getMBUInt();
$element[EN_TYPE] = EN_TYPE_CONTENT;
$element[EN_CONTENT] = $this->getOpaque($length);
return $element;
case WBXML_LITERAL_AC:
case self::WBXML_LITERAL_AC:
$element[EN_TYPE] = EN_TYPE_STARTTAG;
$element[EN_TAG] = $this->getStringTableEntry($this->getMBUInt());
$element[EN_ATTRIBUTES] = $this->getAttributes();
......@@ -470,67 +470,67 @@ class WBXMLDecoder extends WBXMLDefs {
break;
switch($byte) {
case WBXML_SWITCH_PAGE:
case self::WBXML_SWITCH_PAGE:
$this->attrcp = $this->getByte();
break;
case WBXML_END:
case self::WBXML_END:
if($attr != "")
$attributes += $this->splitAttribute($attr);
return $attributes;
case WBXML_ENTITY:
case self::WBXML_ENTITY:
$entity = $this->getMBUInt();
$attr .= $this->entityToCharset($entity);
return $attr; /* fmbiete's contribution r1534, ZP-324 */
case WBXML_STR_I:
case self::WBXML_STR_I:
$attr .= $this->getTermStr();
return $attr; /* fmbiete's contribution r1534, ZP-324 */
case WBXML_LITERAL:
case self::WBXML_LITERAL:
if($attr != "")
$attributes += $this->splitAttribute($attr);
$attr = $this->getStringTableEntry($this->getMBUInt());
return $attr; /* fmbiete's contribution r1534, ZP-324 */
case WBXML_EXT_I_0:
case WBXML_EXT_I_1:
case WBXML_EXT_I_2:
case self::WBXML_EXT_I_0:
case self::WBXML_EXT_I_1:
case self::WBXML_EXT_I_2:
$this->getTermStr();
continue;
case WBXML_PI:
case WBXML_LITERAL_C:
case self::WBXML_PI:
case self::WBXML_LITERAL_C:
// Invalid
return false;
case WBXML_EXT_T_0:
case WBXML_EXT_T_1:
case WBXML_EXT_T_2:
case self::WBXML_EXT_T_0:
case self::WBXML_EXT_T_1:
case self::WBXML_EXT_T_2:
$this->getMBUInt();
continue;
case WBXML_STR_T:
case self::WBXML_STR_T:
$attr .= $this->getStringTableEntry($this->getMBUInt());
return $attr; /* fmbiete's contribution r1534, ZP-324 */
case WBXML_LITERAL_A:
case self::WBXML_LITERAL_A:
return false;
case WBXML_EXT_0:
case WBXML_EXT_1:
case WBXML_EXT_2:
case self::WBXML_EXT_0:
case self::WBXML_EXT_1:
case self::WBXML_EXT_2:
continue;
case WBXML_OPAQUE:
case self::WBXML_OPAQUE:
$length = $this->getMBUInt();
$attr .= $this->getOpaque($length);
return $attr; /* fmbiete's contribution r1534, ZP-324 */
case WBXML_LITERAL_AC:
case self::WBXML_LITERAL_AC:
return false;
default:
......
......@@ -42,26 +42,7 @@
************************************************/
define('WBXML_SWITCH_PAGE', 0x00);
define('WBXML_END', 0x01);
define('WBXML_ENTITY', 0x02);
define('WBXML_STR_I', 0x03);
define('WBXML_LITERAL', 0x04);
define('WBXML_EXT_I_0', 0x40);
define('WBXML_EXT_I_1', 0x41);
define('WBXML_EXT_I_2', 0x42);
define('WBXML_PI', 0x43);
define('WBXML_LITERAL_C', 0x44);
define('WBXML_EXT_T_0', 0x80);
define('WBXML_EXT_T_1', 0x81);
define('WBXML_EXT_T_2', 0x82);
define('WBXML_STR_T', 0x83);
define('WBXML_LITERAL_A', 0x84);
define('WBXML_EXT_0', 0xC0);
define('WBXML_EXT_1', 0xC1);
define('WBXML_EXT_2', 0xC2);
define('WBXML_OPAQUE', 0xC3);
define('WBXML_LITERAL_AC', 0xC4);
define('EN_TYPE', 1);
define('EN_TAG', 2);
......@@ -77,6 +58,28 @@ define('EN_FLAGS_CONTENT', 1);
define('EN_FLAGS_ATTRIBUTES', 2);
class WBXMLDefs {
const WBXML_SWITCH_PAGE = 0x00;
const WBXML_END = 0x01;
const WBXML_ENTITY = 0x02;
const WBXML_STR_I = 0x03;
const WBXML_LITERAL = 0x04;
const WBXML_EXT_I_0 = 0x40;
const WBXML_EXT_I_1 = 0x41;
const WBXML_EXT_I_2 = 0x42;
const WBXML_PI = 0x43;
const WBXML_LITERAL_C = 0x44;
const WBXML_EXT_T_0 = 0x80;
const WBXML_EXT_T_1 = 0x81;
const WBXML_EXT_T_2 = 0x82;
const WBXML_STR_T = 0x83;
const WBXML_LITERAL_A = 0x84;
const WBXML_EXT_0 = 0xC0;
const WBXML_EXT_1 = 0xC1;
const WBXML_EXT_2 = 0xC2;
const WBXML_OPAQUE = 0xC3;
const WBXML_LITERAL_AC = 0xC4;
/**
* The WBXML DTDs
*/
......
......@@ -300,7 +300,7 @@ class WBXMLEncoder extends WBXMLDefs {
*/
private function _content($content) {
$this->logContent($content);
$this->outByte(WBXML_STR_I);
$this->outByte(self::WBXML_STR_I);
$this->outTermStr($content);
}
......@@ -339,7 +339,7 @@ class WBXMLEncoder extends WBXMLDefs {
*/
private function _endTag() {
$this->logEndTag();
$this->outByte(WBXML_END);
$this->outByte(self::WBXML_END);
}
/**
......@@ -399,7 +399,7 @@ class WBXMLEncoder extends WBXMLDefs {
* @return
*/
private function outAttributes() {
$this->outByte(WBXML_END);
$this->outByte(self::WBXML_END);
}
/**
......@@ -411,7 +411,7 @@ class WBXMLEncoder extends WBXMLDefs {
* @return
*/
private function outSwitchPage($page) {
$this->outByte(WBXML_SWITCH_PAGE);
$this->outByte(self::WBXML_SWITCH_PAGE);
$this->outByte($page);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment