]> git.nbdom.net Git - nb.git/commitdiff
Bed
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Sun, 4 Sep 2016 00:49:08 +0000 (01:49 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Sun, 4 Sep 2016 00:49:08 +0000 (01:49 +0100)
lib/php/out.php

index 66884920798d0325e404697620e668a0f02bc798..54cab196c6c4363ce6e216edc03ae246d7aee11b 100644 (file)
@@ -15,6 +15,7 @@ Class Out extends Nb {
         'border' => '_',
         'head' => 'out_human_head',
         'function' => 'out_human',
+        'end' => function($o) { echo $o['line']."\n"; } 
       ],
 
       'sql' => array(),
@@ -250,8 +251,9 @@ Class Out extends Nb {
     if (isset($o['eol'])) echo $o['eol'];
   }
 
-  public static function end($o) {
+  public static function end(&$o) {
     if (isset($o['enclose'])) echo $o['enclose'][1];
+    if (isset($o['end'])) echo $o['end']($o);
   }
 
   public static function rows_get($type,$data,$head=array()) {
@@ -409,16 +411,16 @@ function out_human_head(&$head,&$o) {
   # For no scalar search max length
   $o['fields_max_len'] = [];
 
-  foreach ($o['data'] as $rec) {
-    $i = 0;
+  foreach ($o['data'] as $id=>$rec) {
+    $i = -1;
     foreach ($rec as $k=>$v) {
+      $i++;
       if (!is_scalar($v)) continue;
       if (0
         or empty($o['fields_max_len'][$i])
         or strlen($v) >= $o['fields_max_len'][$i]
-      ) $o['fields_max_len'][$i] = strlen($v);
+      ) $o['fields_max_len'][$i] = mb_strlen($v);
       #echo strlen($v)."\n";
-      $i++;
     }
   }
 
@@ -426,15 +428,15 @@ function out_human_head(&$head,&$o) {
     $head = array_keys($head);
   }
 
-  $i = 0;
+  $i = -1;
   foreach ($head as $k => $v) {
+    $i++;
     if (!is_scalar($v)) continue;
     if (0
       or empty($o['fields_max_len'][$i])
       or strlen($v) >= $o['fields_max_len'][$i]
-    ) $o['fields_max_len'][$i] = strlen($v);
+    ) $o['fields_max_len'][$i] = mb_strlen($v);
     #echo strlen($v)."\n";
-    $i++;
   }
 
   #debug($line);
@@ -460,7 +462,7 @@ function out_human(&$row,$o) {
   $i = 0;
   $values = [];
   foreach (array_values($row) as $k=>$v) {
-    #debug(strlen($v).' == '.$o['fields_max_len'][$i]);
+    #if(mb_strlen($v)!=$o['fields_max_len'][$i]) debug(mb_strlen($v).' == '.$o['fields_max_len'][$i]);
     #debug("%".$o['fields_max_len'][$i]."s");
 
     $values[] = sprintf("%".'-'.$o['fields_max_len'][$i]