\n"; } } function formatparse($s) { // function formatparse($s); $returnval = array(); $bold = false; $underline = false; $fg = -1; // INVISIBLE SANDWICH $bg = -1; $curpos = 0; unset($arrid); if (is_array($s)) { $dbt = debug_backtrace(); $aaah = ''; foreach ($dbt as $dbt_) { $aaah .= '< '.($dbt_['filename']).'\'s '.$dbt_['function'].':'.$dbt_['line']; } logmsg('Array to string conversion. '.$aaah, DEBUG_DEBUG, 1); } for ($i = 0; $i < strlen($s); $i++) { $curchar = $s{$i}; switch ($curchar) { case bold: if ($bold = !$bold) { if (!isset($curpos)) $curpos = $i; } else { unset($curpos); } unset($arrid); break; case underline: if ($underline = !$underline) { if (!isset($curpos)) $curpos = $i; } else { unset($curpos); } unset($arrid); break; case color: if (preg_match('/(\d\d?)?(?:,(\d\d?)?)?/', $s, $colormatch, 0, $i+1) and strlen($colormatch[0]) and $colormatch[0] !== ',') { if (!isset($curpos)) $curpos = $i; if (isset($colormatch[1]) and !empty($colormatch[1])) { $fg = intval($colormatch[1]); } if (isset($colormatch[2]) and !empty($colormatch[2])) { $bg = intval($colormatch[2]); } $i += strlen($colormatch[0]); } else { unset($curpos); $fg = -1; $bg = -1; } unset($arrid); break; case noformat: $bold = false; $underline = false; $fg = -1; // INVISIBLE SANDWICH $bg = -1; unset($arrid); unset($curchar); break; default: if (!isset($arrid)) {$returnval[$arrid = count($returnval)] = array('', 0, $bold, $underline, $fg, $bg);} $returnval[$arrid][0] .= $curchar; break; } } //$returnval = array($s, $returnval); return $returnval; } function formatparse_cat() { //function formatparse_cat(..); $returnval = array(); foreach (func_get_args() as $s) { if (is_formatparse($s)) foreach ($s as $t) $returnval[] = $t; elseif (is_string($s)) $returnval[] = formatparse($s); else { logmsg('argument not a formatparse', DEBUG_WARNING); return false; } } return $returnval; } function formatparse_substr($s, $start) { // function formatparse_substr($s, $start, $len); $argc = count($argv = func_get_args()); if ($argc >= 3) $len = $argv[1]; if ($start < 0 or !isset($len) or !is_int($len) or $len < 0) { $slen = strlen(formatparse_toplain($s)); if ($start < 0) if (($start += $slen) < 0) {logmsg('$start underflow!', DEBUG_ERROR); return false;} if (!isset($len) or !is_int($len)) $len = $slen-$start; elseif ($len < 0) if (($len += $slen) < 0) {logmsg('$len underflow!', DEBUG_ERROR); return false;} } $modfp_substr_debug = 0; if (!is_formatparse($s)) {logmsg('argument not a formatparse', DEBUG_WARNING); return false;} $a = $s;//[1]; $a_ = array(); $curpos = 0; unset($nextpos); $end = $start+$len; $bold = $underline = false; $fg = $bg = -1; logmsg($start.','.$len.','.$end, DEBUG_DEBUG, $modfp_substr_debug); foreach ($a as $c) { if (isset($nextpos)) $curpos = $nextpos; $nextpos = $curpos+strlen($c[0]); logmsg('-- '.$curpos.','.$nextpos.' '.$c[0], DEBUG_DEBUG, $modfp_substr_debug); if ($start >= $nextpos) continue; $a_[$id = count($a_)] = $c; if ($start > $curpos) $a_[$id][0] = substr($a_[$id][0], $start-$curpos); if ($end < $nextpos) $a_[$id][0] = substr($a_[$id][0], 0, $end-$nextpos); } //$returnval = array($s_, $a_); logmsg('- '.formatparse_toirc($a_), DEBUG_DEBUG, $modfp_substr_debug); return $a_; } function formatparse_toplain($s) { // function formatparse_toplain($s); if (!is_formatparse($s)) {logmsg('argument not a formatparse', DEBUG_WARNING); return false;} $a = $s;//[1]; $returnval = ''; foreach ($a as $s) $returnval .= $s[0]; return $returnval; } function formatparse_toirc($s) { // function formatparse_toirc($s); if (!is_formatparse($s)) {logmsg('argument not a formatparse', DEBUG_WARNING); return false;} $a = $s;//[1]; $returnval = ''; $bold = $underline = false; $fg = $bg = -1; foreach ($a as $s) { if ($bold != $s[2]) { $bold = $s[2]; $returnval .= bold; } if ($underline != $s[3]) { $underline = $s[3]; $returnval .= underline; } if ($fg != $s[4]) { $fg = $s[4]; if ($fg == -1) { if ($bg > -1) { $returnval .= color.','.str_pad($bg, 2, '0', STR_PAD_LEFT); } else $returnval .= color; } else { $returnval .= color.str_pad($fg, 2, '0', STR_PAD_LEFT); } } if ($bg != $s[5]) { $bg = $s[5]; if ($bg == -1) { $returnval .= color; if ($fg > -1) { $returnval .= color.str_pad($fg, 2, '0', STR_PAD_LEFT); } } else { $returnval .= color; if ($fg > -1) { $returnval .= color.str_pad($fg, 2, '0', STR_PAD_LEFT); } $returnval .= ','.str_pad($bg, 2, '0', STR_PAD_LEFT); } } $returnval .= $s[0]; } return $returnval; } function formatparse_export($s) { // function formatparse_export($s); // This is rather ded, needs to be updated to conform with current formatparse structure. if (!is_formatparse($s)) {logmsg('argument not a formatparse', DEBUG_WARNING); return false;} $a = $s; $output = '<'.'?xml version="1.0"?'.'>
| '.$a[$i][0].' | '; } $output .= '