nulib/php/src_file/csv/csv_flavours.php

47 lines
1.3 KiB
PHP

<?php
namespace nulib\file\csv;
use nulib\cl;
use nulib\ref\os\csv\ref_csv;
class csv_flavours {
const MAP = [
"oo" => ref_csv::OO_FLAVOUR,
"ooffice" => ref_csv::OO_FLAVOUR,
ref_csv::OO_NAME => ref_csv::OO_FLAVOUR,
"xl" => ref_csv::XL_FLAVOUR,
"excel" => ref_csv::XL_FLAVOUR,
ref_csv::XL_NAME => ref_csv::XL_FLAVOUR,
];
const ENCODINGS = [
ref_csv::OO_FLAVOUR => ref_csv::OO_ENCODING,
ref_csv::XL_FLAVOUR => ref_csv::XL_ENCODING,
];
static final function verifix(string $flavour): string {
$lflavour = strtolower($flavour);
if (array_key_exists($lflavour, self::MAP)) {
$flavour = self::MAP[$lflavour];
}
if (strlen($flavour) < 1) $flavour .= ",";
if (strlen($flavour) < 2) $flavour .= "\"";
if (strlen($flavour) < 3) $flavour .= "\\";
return $flavour;
}
static final function get_name(string $flavour): string {
if ($flavour == ref_csv::OO_FLAVOUR) return ref_csv::OO_NAME;
elseif ($flavour == ref_csv::XL_FLAVOUR) return ref_csv::XL_NAME;
else return $flavour;
}
static final function get_params(string $flavour): array {
return [$flavour[0], $flavour[1], $flavour[2]];
}
static final function get_encoding(string $flavour): ?string {
return cl::get(self::ENCODINGS, $flavour);
}
}