nur-sery/nur_src/io/csv/flavours.php

46 lines
1.2 KiB
PHP
Raw Normal View History

2023-12-03 22:10:18 +04:00
<?php
namespace nur\io\csv;
use nur\A;
use nur\ref\ref_csv;
class 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 {
if (array_key_exists(strtolower($flavour), self::MAP)) {
$flavour = self::MAP[strtolower($flavour)];
}
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 A::get(self::ENCODINGS, $flavour);
}
}