SimplePie_XML_Declaration_Parser

Parses the XML Declaration.

Defined (1)

The class is defined in the following location(s).

/wp-includes/SimplePie/XML/Declaration/Parser.php  
  1. class SimplePie_XML_Declaration_Parser 
  2. /** 
  3. * XML Version 
  4. * @access public 
  5. * @var string 
  6. */ 
  7. var $version = '1.0'; 
  8.  
  9. /** 
  10. * Encoding 
  11. * @access public 
  12. * @var string 
  13. */ 
  14. var $encoding = 'UTF-8'; 
  15.  
  16. /** 
  17. * Standalone 
  18. * @access public 
  19. * @var bool 
  20. */ 
  21. var $standalone = false; 
  22.  
  23. /** 
  24. * Current state of the state machine 
  25. * @access private 
  26. * @var string 
  27. */ 
  28. var $state = 'before_version_name'; 
  29.  
  30. /** 
  31. * Input data 
  32. * @access private 
  33. * @var string 
  34. */ 
  35. var $data = ''; 
  36.  
  37. /** 
  38. * Input data length (to avoid calling strlen() everytime this is needed) 
  39. * @access private 
  40. * @var int 
  41. */ 
  42. var $data_length = 0; 
  43.  
  44. /** 
  45. * Current position of the pointer 
  46. * @var int 
  47. * @access private 
  48. */ 
  49. var $position = 0; 
  50.  
  51. /** 
  52. * Create an instance of the class with the input data 
  53. * @access public 
  54. * @param string $data Input data 
  55. */ 
  56. public function __construct($data) 
  57. $this->data = $data; 
  58. $this->data_length = strlen($this->data); 
  59.  
  60. /** 
  61. * Parse the input data 
  62. * @access public 
  63. * @return bool true on success, false on failure 
  64. */ 
  65. public function parse() 
  66. while ($this->state && $this->state !== 'emit' && $this->has_data()) 
  67. $state = $this->state; 
  68. $this->$state(); 
  69. $this->data = ''; 
  70. if ($this->state === 'emit') 
  71. return true; 
  72. else 
  73. $this->version = ''; 
  74. $this->encoding = ''; 
  75. $this->standalone = ''; 
  76. return false; 
  77.  
  78. /** 
  79. * Check whether there is data beyond the pointer 
  80. * @access private 
  81. * @return bool true if there is further data, false if not 
  82. */ 
  83. public function has_data() 
  84. return (bool) ($this->position < $this->data_length); 
  85.  
  86. /** 
  87. * Advance past any whitespace 
  88. * @return int Number of whitespace characters passed 
  89. */ 
  90. public function skip_whitespace() 
  91. $whitespace = strspn($this->data, "\x09\x0A\x0D\x20", $this->position); 
  92. $this->position += $whitespace; 
  93. return $whitespace; 
  94.  
  95. /** 
  96. * Read value 
  97. */ 
  98. public function get_value() 
  99. $quote = substr($this->data, $this->position, 1); 
  100. if ($quote === '"' || $quote === "'") 
  101. $this->position++; 
  102. $len = strcspn($this->data, $quote, $this->position); 
  103. if ($this->has_data()) 
  104. $value = substr($this->data, $this->position, $len); 
  105. $this->position += $len + 1; 
  106. return $value; 
  107. return false; 
  108.  
  109. public function before_version_name() 
  110. if ($this->skip_whitespace()) 
  111. $this->state = 'version_name'; 
  112. else 
  113. $this->state = false; 
  114.  
  115. public function version_name() 
  116. if (substr($this->data, $this->position, 7) === 'version') 
  117. $this->position += 7; 
  118. $this->skip_whitespace(); 
  119. $this->state = 'version_equals'; 
  120. else 
  121. $this->state = false; 
  122.  
  123. public function version_equals() 
  124. if (substr($this->data, $this->position, 1) === '=') 
  125. $this->position++; 
  126. $this->skip_whitespace(); 
  127. $this->state = 'version_value'; 
  128. else 
  129. $this->state = false; 
  130.  
  131. public function version_value() 
  132. if ($this->version = $this->get_value()) 
  133. $this->skip_whitespace(); 
  134. if ($this->has_data()) 
  135. $this->state = 'encoding_name'; 
  136. else 
  137. $this->state = 'emit'; 
  138. else 
  139. $this->state = false; 
  140.  
  141. public function encoding_name() 
  142. if (substr($this->data, $this->position, 8) === 'encoding') 
  143. $this->position += 8; 
  144. $this->skip_whitespace(); 
  145. $this->state = 'encoding_equals'; 
  146. else 
  147. $this->state = 'standalone_name'; 
  148.  
  149. public function encoding_equals() 
  150. if (substr($this->data, $this->position, 1) === '=') 
  151. $this->position++; 
  152. $this->skip_whitespace(); 
  153. $this->state = 'encoding_value'; 
  154. else 
  155. $this->state = false; 
  156.  
  157. public function encoding_value() 
  158. if ($this->encoding = $this->get_value()) 
  159. $this->skip_whitespace(); 
  160. if ($this->has_data()) 
  161. $this->state = 'standalone_name'; 
  162. else 
  163. $this->state = 'emit'; 
  164. else 
  165. $this->state = false; 
  166.  
  167. public function standalone_name() 
  168. if (substr($this->data, $this->position, 10) === 'standalone') 
  169. $this->position += 10; 
  170. $this->skip_whitespace(); 
  171. $this->state = 'standalone_equals'; 
  172. else 
  173. $this->state = false; 
  174.  
  175. public function standalone_equals() 
  176. if (substr($this->data, $this->position, 1) === '=') 
  177. $this->position++; 
  178. $this->skip_whitespace(); 
  179. $this->state = 'standalone_value'; 
  180. else 
  181. $this->state = false; 
  182.  
  183. public function standalone_value() 
  184. if ($standalone = $this->get_value()) 
  185. switch ($standalone) 
  186. case 'yes': 
  187. $this->standalone = true; 
  188. break; 
  189.  
  190. case 'no': 
  191. $this->standalone = false; 
  192. break; 
  193.  
  194. default: 
  195. $this->state = false; 
  196. return; 
  197.  
  198. $this->skip_whitespace(); 
  199. if ($this->has_data()) 
  200. $this->state = false; 
  201. else 
  202. $this->state = 'emit'; 
  203. else 
  204. $this->state = false;