コード例 #1
0
ファイル: BasicTest.php プロジェクト: sp-ruben-simon/daff-php
 public function testCSV()
 {
     $txt = "name,age\nPaul,\"7,9\"\n\"Sam\nSpace\",\"\"\"\"\n";
     $tab = harness_Native::table(new _hx_array(array()));
     $csv = new coopy_Csv(null);
     $csv->parseTable($txt, $tab);
     $this->assertEquals(3, $tab->get_height(), _hx_anonymous(array("fileName" => "BasicTest.hx", "lineNumber" => 62, "className" => "harness.BasicTest", "methodName" => "testCSV")));
     $this->assertEquals(2, $tab->get_width(), _hx_anonymous(array("fileName" => "BasicTest.hx", "lineNumber" => 63, "className" => "harness.BasicTest", "methodName" => "testCSV")));
     $this->assertEquals("Paul", $tab->getCell(0, 1), _hx_anonymous(array("fileName" => "BasicTest.hx", "lineNumber" => 64, "className" => "harness.BasicTest", "methodName" => "testCSV")));
     $this->assertEquals("\"", $tab->getCell(1, 2), _hx_anonymous(array("fileName" => "BasicTest.hx", "lineNumber" => 65, "className" => "harness.BasicTest", "methodName" => "testCSV")));
 }
コード例 #2
0
 public function loadTable($name)
 {
     $ext = $this->checkFormat($name);
     if ($ext === "sqlite") {
         $sql = $this->io->openSqliteDatabase($name);
         if ($sql === null) {
             $this->io->writeStderr("! Cannot open database, aborting\n");
             return null;
         }
         $helper = new coopy_SqliteHelper();
         $name1 = "";
         if ($this->flags === null || $this->flags->tables === null || $this->flags->tables->length === 0) {
             $names = $helper->getTableNames($sql);
             if ($names === null) {
                 $this->io->writeStderr("! Cannot find database tables, aborting\n");
                 return null;
             }
             if ($names->length === 0) {
                 $this->io->writeStderr("! No tables in database, aborting\n");
                 return null;
             }
             $name1 = $names[0];
         } else {
             $name1 = $this->flags->tables[0];
             if ($this->flags->tables->length > 1) {
                 $this->io->writeStderr("! Cannot compare more than one table yet\n");
             }
         }
         $tab = new coopy_SqlTable($sql, new coopy_SqlTableName($name1, null), $helper);
         $this->strategy = "sql";
         return $tab;
     }
     $txt = $this->io->getContent($name);
     if ($ext === "ndjson") {
         $t = new coopy_SimpleTable(0, 0);
         $ndjson = new coopy_Ndjson($t);
         $ndjson->parse($txt);
         return $t;
     }
     if ($ext === "json" || $ext === "") {
         try {
             $json = _hx_deref(new haxe_format_JsonParser($txt))->parseRec();
             $this->format_preference = "json";
             $t1 = coopy_Coopy::jsonToTable($json);
             if ($t1 === null) {
                 throw new HException("JSON failed");
             }
             return $t1;
         } catch (Exception $__hx__e) {
             $_ex_ = $__hx__e instanceof HException ? $__hx__e->e : $__hx__e;
             $e = $_ex_;
             if ($ext === "json") {
                 throw new HException($e);
             }
         }
     }
     $this->format_preference = "csv";
     $csv = new coopy_Csv($this->delim_preference);
     $output = new coopy_SimpleTable(0, 0);
     $csv->parseTable($txt, $output);
     if ($output !== null) {
         $output->trimBlank();
     }
     return $output;
 }
コード例 #3
0
ファイル: Coopy.class.php プロジェクト: paulfitz/daff-php
 public function loadTable($name)
 {
     $ext = $this->checkFormat($name);
     if ($ext === "sqlite") {
         $sql = $this->io->openSqliteDatabase($name);
         if ($sql === null) {
             $this->io->writeStderr("! Cannot open database, aborting\n");
             return null;
         }
         $tab = new coopy_SqlTables($sql, $this->flags);
         return $tab;
     }
     $txt = $this->io->getContent($name);
     if ($ext === "ndjson") {
         $t = new coopy_SimpleTable(0, 0);
         $ndjson = new coopy_Ndjson($t);
         $ndjson->parse($txt);
         return $t;
     }
     if ($ext === "json" || $ext === "") {
         try {
             $json = _hx_deref(new haxe_format_JsonParser($txt))->parseRec();
             $this->format_preference = "json";
             $t1 = $this->jsonToTables($json);
             if ($t1 === null) {
                 throw new HException("JSON failed");
             }
             return $t1;
         } catch (Exception $__hx__e) {
             $_ex_ = $__hx__e instanceof HException ? $__hx__e->e : $__hx__e;
             $e = $_ex_;
             if ($ext === "json") {
                 throw new HException($e);
             }
         }
     }
     $this->format_preference = "csv";
     $csv = new coopy_Csv($this->delim_preference);
     $output = new coopy_SimpleTable(0, 0);
     $csv->parseTable($txt, $output);
     if ($output !== null) {
         $output->trimBlank();
     }
     return $output;
 }
コード例 #4
0
ファイル: BasicTest.php プロジェクト: paulfitz/daff-php
 public function testStraySpaceInCsv()
 {
     $csv = new coopy_Csv(null);
     $tab = $csv->makeTable("id,color\n" . "15,red\n" . "13,mauve,,,\n" . "2,green\n");
     $this->assertEquals($tab->get_width(), 2, _hx_anonymous(array("fileName" => "BasicTest.hx", "lineNumber" => 153, "className" => "harness.BasicTest", "methodName" => "testStraySpaceInCsv")));
 }