From fec2f5b5825a00889ff71d8a2d3083d527f44df1 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Fri, 28 Jan 2005 00:43:39 +0000 Subject: [PATCH] use switch() instead of if else if else if else if else if else :o) --- includes/ParserXML.php | 267 +++++++++++++++++++++-------------------- 1 file changed, 137 insertions(+), 130 deletions(-) diff --git a/includes/ParserXML.php b/includes/ParserXML.php index ff12ca2c6e..760b4049b2 100644 --- a/includes/ParserXML.php +++ b/includes/ParserXML.php @@ -231,148 +231,155 @@ class element { # Fix allowed HTML $old_n = $n; $ext = strtoupper($this->attrs['NAME']); - if ($ext == 'B' || $ext == 'STRONG') - $n = 'BOLD'; - else - if ($ext == 'I' || $ext == 'EM') + + switch($ext) { + case 'B': + case 'STRONG': + $n = 'BOLD'; + break; + case 'I': + case 'EM': $n = 'ITALICS'; - else - if ($ext == 'U') - $n = 'UNDERLINED'; # Hey, virtual wiki tag! ;-) - else - if ($ext == 'S') + break; + case 'U': + $n = 'UNDERLINED'; # Hey, virtual wiki tag! ;-) + break; + case 'S': $n = 'STRIKE'; - else - if ($ext == 'P') - $n = 'PARAGRAPH'; - else - if ($ext == 'TABLE') - $n = 'TABLE'; - else - if ($ext == 'TR') - $n = 'TABLEROW'; - else - if ($ext == 'TD') - $n = 'TABLECELL'; - else - if ($ext == 'TH') - $n = 'TABLEHEAD'; - else - if ($ext == 'CAPTION') - $n = 'CAPTION'; - else - if ($ext == 'NOWIKI') - $n = 'NOWIKI'; - if ($n != $old_n) + break; + case 'P': + $n = 'PARAGRAPH'; + break; + case 'TABLE': + $n = 'TABLE'; + break; + case 'TR': + $n = 'TABLEROW'; + break; + case 'TD': + $n = 'TABLECELL'; + break; + case 'TH': + $n = 'TABLEHEAD'; + break; + case 'CAPTION': + $n = 'CAPTION'; + break; + case 'NOWIKI': + $n = 'NOWIKI'; + break; + } + if ($n != $old_n) { unset ($this->attrs['NAME']); # Cleanup - else - if ($parser->nowiki > 0) - $n = ''; # No 'real' wiki tags allowed in nowiki section - } + } elseif ($parser->nowiki > 0) { + # No 'real' wiki tags allowed in nowiki section + $n = ''; + } + } // $n = 'EXTENSION' - if ($n == 'ARTICLE') - $ret .= $this->sub_makeXHTML($parser); - else - if ($n == 'HEADING') + switch($n) { + case 'ARTICLE': + $ret .= $this->sub_makeXHTML($parser); + break; + case 'HEADING': $ret .= $this->sub_makeXHTML($parser, 'h'.$this->attrs['LEVEL']); - else - if ($n == 'PARAGRAPH') - $ret .= $this->sub_makeXHTML($parser, 'p'); - else - if ($n == 'BOLD') - $ret .= $this->sub_makeXHTML($parser, 'strong'); - else - if ($n == 'ITALICS') - $ret .= $this->sub_makeXHTML($parser, 'em'); - - # These don't exist as wiki markup - else - if ($n == 'UNDERLINED') + break; + case 'PARAGRAPH': + $ret .= $this->sub_makeXHTML($parser, 'p'); + break; + case 'BOLD': + $ret .= $this->sub_makeXHTML($parser, 'strong'); + break; + case 'ITALICS': + $ret .= $this->sub_makeXHTML($parser, 'em'); + break; + + # These don't exist as wiki markup + case 'UNDERLINED': $ret .= $this->sub_makeXHTML($parser, 'u'); - else - if ($n == 'STRIKE') - $ret .= $this->sub_makeXHTML($parser, 'strike'); + break; + case 'STRIKE': + $ret .= $this->sub_makeXHTML($parser, 'strike'); + break; + + # HTML comment + case 'COMMENT': + # Comments are parsed out + $ret .= ''; + break; + + + # Links + case 'LINK': + $ret .= $this->makeInternalLink($parser); + break; + case 'LINKTARGET': + case 'LINKOPTION': + $ret .= $this->sub_makeXHTML($parser); + break; + + case 'TEMPLATE': + $parts = $this->sub_makeXHTML($parser); + $parts = explode('|', $parts); + $title = array_shift($parts); + $ret .= $this->getTemplateXHTML($title, $parts, & $parser); + break; + + case 'TEMPLATEVAR': + $x = $this->sub_makeXHTML($parser); + if (isset ($parser->mCurrentTemplateOptions["{$x}"])) + $ret .= $parser->mCurrentTemplateOptions["{$x}"]; + break; + + # Internal use, not generated by wiki2xml parser + case 'IGNORE': + $ret .= $this->sub_makeXHTML($parser); - # HTML comment - else - if ($n == 'COMMENT') - $ret .= ''; # Comments are parsed out + case 'NOWIKI': + $parser->nowiki++; + $ret .= $this->sub_makeXHTML($parser, ''); + $parser->nowiki--; - # Links - else - if ($n == 'LINK') - $ret .= $this->makeInternalLink($parser); - else - if ($n == 'LINKTARGET') - $ret .= $this->sub_makeXHTML($parser); - else - if ($n == 'LINKOPTION') - $ret .= $this->sub_makeXHTML($parser); - else - if ($n == 'TEMPLATE') { - $parts = $this->sub_makeXHTML($parser); - $parts = explode('|', $parts); - $title = array_shift($parts); - $ret .= $this->getTemplateXHTML($title, $parts, & $parser); - } else - if ($n == 'TEMPLATEVAR') { - $x = $this->sub_makeXHTML($parser); - if (isset ($parser->mCurrentTemplateOptions["{$x}"])) - $ret .= $parser->mCurrentTemplateOptions["{$x}"]; - } else - if ($n == 'IGNORE') # Internal use, not generated by wiki2xml parser - $ret .= $this->sub_makeXHTML($parser); - - else - if ($n == 'NOWIKI') { - $parser->nowiki++; - $ret .= $this->sub_makeXHTML($parser, ''); - $parser->nowiki--; - } - - # Unknown HTML extension - else - if ($n == 'EXTENSION') # This is currently a dummy!!! - { + # Unknown HTML extension + case 'EXTENSION': # This is currently a dummy!!! $ext = $this->attrs['NAME']; $ret .= '<'.$ext.'>'; $ret .= $this->sub_makeXHTML($parser); $ret .= '</'.$ext.'> '; - } + break; - # Table stuff - else - if ($n == 'TABLE') { + + # Table stuff + + case 'TABLE': $ret .= $this->sub_makeXHTML($parser, 'table'); - } else - if ($n == 'TABLEROW') { - $ret .= $this->sub_makeXHTML($parser, 'tr'); - } else - if ($n == 'TABLECELL') { - $ret .= $this->sub_makeXHTML($parser, 'td'); - } else - if ($n == 'TABLEHEAD') { - $ret .= $this->sub_makeXHTML($parser, 'th'); - } else - if ($n == 'CAPTION') { - $ret .= $this->sub_makeXHTML($parser, 'caption'); - } else - if ($n == 'ATTRS') # SPECIAL CASE : returning attributes - { - return $this->getTheseAttrs(); - } - - # Lists - else - if ($n == 'LISTITEM') { + break; + case 'TABLEROW': + $ret .= $this->sub_makeXHTML($parser, 'tr'); + break; + case 'TABLECELL': + $ret .= $this->sub_makeXHTML($parser, 'td'); + break; + case 'TABLEHEAD': + $ret .= $this->sub_makeXHTML($parser, 'th'); + break; + case 'CAPTION': + $ret .= $this->sub_makeXHTML($parser, 'caption'); + break; + case 'ATTRS': # SPECIAL CASE : returning attributes + return $this->getTheseAttrs(); + + + # Lists stuff + case 'LISTITEM': if ($parser->mListType == 'dl') $ret .= $this->sub_makeXHTML($parser, 'dd'); else $ret .= $this->sub_makeXHTML($parser, 'li'); - } else - if ($n == 'LIST') { + break; + case 'LIST': $type = 'ol'; # Default if ($this->attrs['TYPE'] == 'bullet') $type = 'ul'; @@ -383,14 +390,14 @@ class element { $parser->mListType = $type; $ret .= $this->sub_makeXHTML($parser, $type); $parser->mListType = $oldtype; - } - - # Something else entirely - else { - $ret .= '<'.$n.'>'; - $ret .= $this->sub_makeXHTML($parser); - $ret .= '</'.$n.'> '; - } + break; + + # Something else entirely + case default: + $ret .= '<'.$n.'>'; + $ret .= $this->sub_makeXHTML($parser); + $ret .= '</'.$n.'> '; + } // switch($n) $ret = "\n{$ret}\n"; $ret = str_replace("\n\n", "\n", $ret); -- 2.20.1