]> git.nbdom.net Git - nb.git/commitdiff
Fix bugs
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 6 Apr 2016 21:31:22 +0000 (22:31 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 6 Apr 2016 21:31:22 +0000 (22:31 +0100)
lib/php/benchmark.php
lib/php/db/table.php
lib/php/nb.php
lib/php/out.php
lib/php/page.php

index 47b0202144ccdd85c4402da5113f9340917b99b6..94716afca4f46add71da4722a38221ea3403da13 100755 (executable)
@@ -8,6 +8,7 @@ require(dirname(__FILE__).'/nb.php');
 $_GET['var'] = 'sldkfhlsakhlshglzkdhzfgldznfdznbldzknb';
 $array = array_fill(0,100000,"a");
 $hash = array(); for ($i=0;$i<100000;$i++) $hash[$i] = $i;
+$a = $b = '';
 echo "Start benchmark\n";
 
 /*
@@ -30,6 +31,9 @@ exit;
 #function _isset() { isset($var); } nb::benchmark('_isset',5000000);
 #function _in_array() { in_array(5000,$GLOBALS['array']); } nb::benchmark('_in_array',1000);
 #function _in_hash() { isset($GLOBALS['hash'][5000]); } nb::benchmark('_in_hash',1000);
+function _and() { $a='' and $b=''; } nb::benchmark('_and',9999999);
+function _sig_and() { $a='' and $b=''; } nb::benchmark('_sig_and',9999999);
+nb::benchmark(); exit;
 function _1() { date_default_timezone_set('Europe/London'); } nb::benchmark('_1');
 function _2() { error_reporting(E_ALL | E_STRICT | E_NOTICE); } nb::benchmark('_2');
 function _3() { ini_set('include_path','.'); } nb::benchmark('_3');
index b5ef096b68c9d8164e99350be309c7742eb7d0fa..698d3ac50936f01e113baedb2a04589c1d5d3116 100644 (file)
@@ -594,13 +594,14 @@ Class Table extends nb {
     }
     #debug($fields);
     #bye($this->name);
-    if (!$this->p('action')) echo $this->html_menu();
 
     if (!isset($opt['is_html'])) $opt['is_html'] = preg_match('/^(table|div)$/',$format)
       ? ( $this->p('header')!=="0")
       : false
     ;
 
+    if ($opt['is_html'] and !$this->p('action')) echo $this->html_menu();
+
     # Use the module out when format unknow
     $out_conf = null;
     if ($this->p('out') or !preg_match('/^('.join('|',
index d039f61e0af1f9de74015f25a63b617833c16067..a0580a4cf8d176d9776bda12e8c24673e78f7de0 100644 (file)
@@ -249,7 +249,7 @@ class NB {
 
     if ($function === null) {
       $prev = $_benchmark['.'];
-      echo "Iteration: $limit\n";
+      echo "Results: $limit\n";
       foreach ($_benchmark as $lib => $sec) {
         if ($lib === '.') continue;
         printf("%-30s %s\n",$lib,($sec-$prev));
@@ -262,6 +262,7 @@ class NB {
       $function();
     }
 
+    echo "Completed: $function\n";
     $_benchmark[$function] = microtime(true);
   }
 
index 20605692410788d162680671466efa18df1e0e25..076389a40f607bc889c2894a43152d5114446967 100644 (file)
@@ -1,10 +1,5 @@
 <?php
 require_once(dirname(__FILE__).'/nb.php');
-# NB 07.03.16 define('OUT_BRACKET1','['.NB_EOL);
-# NB 07.03.16 define('OUT_BRACKET2',']');
-# NB 07.03.16 define('OUT_BRACE1','{'.NB_EOL);
-# NB 07.03.16 define('OUT_BRACE2','}');
-# NB 07.03.16 define('OUT_COMA',','.NB_EOL);
 
 Class Out extends Nb {
 
@@ -175,8 +170,8 @@ Class Out extends Nb {
     if (!self::is_hash($row)) return out_yaml($row,$o);
 
     # text
-    foreach ($row as $k => $v) { echo sprintf("%-".(!empty($o['head_max_len']) ? $o['head_max_len']+1 : 10)."s: %s\n",$k,out::escape($v)); }
-    #foreach ($row as $k => $v) { echo "$k: ".out::escape($v)."\n"; }
+    foreach ($row as $k => $v) { echo sprintf("%-".(!empty($o['head_max_len']) ? $o['head_max_len']+1 : 10)."s: %s\n",$k,self::escape($v)); }
+    #foreach ($row as $k => $v) { echo "$k: ".self::escape($v)."\n"; }
 
     return true;
   }
@@ -221,7 +216,7 @@ Class Out extends Nb {
     $head = self::head($conf,$head,$data);
 
     foreach ($data as $row) {
-      if ($count>0) out::concat($conf);
+      if ($count>0) self::concat($conf);
       $count++;
 
       # Transform simple array into hash
@@ -264,7 +259,7 @@ Class Out extends Nb {
     static $replace_flags = null;
 
     $is_scalar = is_scalar($v);
-    $v = out::scalar($v);
+    $v = self::scalar($v);
     if ($v==='') $is_scalar = true;
 
     if ($replace_flags === null) {
@@ -298,7 +293,7 @@ Class Out extends Nb {
     }
 
     $v = htmlspecialchars($v,$replace_flags,strtoupper(self::$charset));
-    if (!$is_scalar) $v = '<pre>'.NB_EOL.$v.NB_EOL.'</pre>';
+    if (!$is_scalar and strpos($type,'html') !== false) $v = '<pre>'.NB_EOL.$v.NB_EOL.'</pre>';
     return $v;
   }
 
@@ -322,7 +317,8 @@ function out_csv(&$row,$o) {
   $values = array();
 
   foreach (array_values($row) as $k=>$v) {
-    $values[] = preg_replace('/zAZA/','',out::scalar($v));
+# NB 06.04.16     $values[] = preg_replace('/zAZA/','',out::scalar($v));
+    $values[] = out::scalar($v);
     #$values[] = preg_replace('/\r?\n/','',out::scalar($v));
   }
 
@@ -367,7 +363,7 @@ function out_tag(&$row,&$o) {
 
     # Inside tag, ex: label
     if (isset($o['tag_key'])) {
-      $v = '<'.$o['tag_key'].'>'.$k.'</'.$o['tag_key'].'>'.$v;
+      $v = '<'.$o['tag_key'].'>'.$k.'</'.preg_replace('/ .*$/','',$o['tag_key']).'>'.$v;
     }
 
     # Tag = o[tag] or key
@@ -386,7 +382,7 @@ function out_tag(&$row,&$o) {
     ;
   }
 
-  if (isset($o['tag_enclose'])) echo (NB_EOL ? '  ' : '').'</'.preg_replace('/  .*$/','',$o['tag_enclose']).'>'.NB_EOL;
+  if (isset($o['tag_enclose'])) echo (NB_EOL ? '  ' : '').'</'.preg_replace('/ .*$/','',$o['tag_enclose']).'>'.NB_EOL;
 }
 
 function out_xml(&$row,$o) {
index 9e8d630e47636bff4803e99596094534e996fffe..d0c02abb998195f12a42c8d50fb9eb45ba1a89e0 100644 (file)
@@ -303,9 +303,8 @@ class Page extends nb {
   public function headers() {
 
     #header('Content-type: ' . self::$content_type);
-               $c = strtoupper ( self::$charset );
-# NB 19.08.15     $this->header('Content-type: ',self::$content_type . ($c ? "; charset=$c" : ""));
-               header('Content-type: '.self::$content_type . ($c ? "; charset=$c" : ""));
+               header('Content-type: '.self::$content_type . (($c = strtoupper ( self::$charset )) ? "; charset=$c" : ""));
+
     if (self::p('download-attachment')) header('Content-Disposition: attachment; filename="'
       . $this->title2filename($this->title,self::$content_type)
     );