Ejemplo n.º 1
0
 /** Format the title by preserving capitalisation */
 function formatTitle($pString, $delimitLeft = '{', $delimitRight = '}')
 {
     $in_maths = false;
     $brace_level = 0;
     $newString = "";
     //print "<div style='font-weight:bold'>" . htmlentities($pString) . "</div>";
     $start = true;
     foreach (preg_split("/[\${}]/", $pString, 0, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_OFFSET_CAPTURE) as $v) {
         // delimiter
         $c = $v[1] > 0 ? $pString[$v[1] - 1] : "";
         // Add the current string unless it is a brace and we are not in math mode
         if ($in_maths && ($c == '}' || $c == '{') || $c == '$') {
             $newString .= $c;
         }
         switch ($c) {
             case '$':
                 $in_maths = !$in_maths;
                 break;
             case '{':
                 $brace_level++;
                 break;
             case '}':
                 $brace_level--;
                 break;
             default:
                 break;
         }
         //print "<div>$brace_level [" . $pString[$v[1]-1] .": $v[1]] " . htmlentities($v[0]) . "</div>";
         if ($in_maths || $brace_level > 0) {
             $newString .= $v[0];
         } else {
             $newString .= $this->_processTitles ? $start ? UTF8::utf8_ucfirst(UTF8::utf8_strtolower($v[0])) : UTF8::utf8_strtolower($v[0]) : $v[0];
         }
         $start = false;
         // Error: return the original string
         if ($brace_level < 0) {
             print "Error while parsing";
             return $pString;
         }
     }
     return $newString;
 }