fem = $fem; $this->le = $le; $this->du = $du; $this->au = $au; $this->w = $spec; } /** * retourner le mot sans article * * @param bool|int $amount nombre du nom, avec l'équivalence false===0 et * true===2. à partir de 2, le mot est ecrit au pluriel * @param bool|string $fem genre du nom avec lequel accorder les adjectifs, * avec l'équivalence false==="M" et true==="F" */ function w($amount=1, bool $upper1=false, $fem=false): string { if ($amount === true) $amount = 2; elseif ($amount === false) $amount = 0; $amount = abs($amount); $w = $this->w; # marque du nombre if ($amount <= 1) { $w = preg_replace('/#[sx]/', "", $w); } else { $w = preg_replace('/#([sx])/', "$1", $w); } # marque du genre if ($fem === "f" || $fem === "F") $fem = true; elseif ($fem === "m" || $fem === "M") $fem = false; $repl = $fem? "$1": ""; $w = preg_replace('/#([e])/', $repl, $w); # mise en majuscule if ($upper1) { if (strpos($w, "^") === false) { # uniquement la première lettre $w = txt::upper1($w); } else { # toutes les lettres qui suivent les occurences de ^ $w = preg_replace_callback('/\^([[:alpha:]])/u', function ($ms) { return mb_strtoupper($ms[1]); }, $w); } } return $w; } /** * retourner le mot sans article avec la première lettre en majuscule. * alias pour $this->w($amount, true, $fem) * * @param bool|int $amount */ function u($amount=1, $fem=false): string { return $this->w($amount, true, $fem); } /** * retourner l'adjectif accordé avec le genre spécifié. * alias pour $this->w($amount, false, $fem) * * @param bool|int $amount */ function a($fem=false, $amount=1): string { return $this->w($amount, false, $fem); } /** retourner le mot sans article et avec la quantité */ function q(int $amount=1, $fem=false): string { return $amount." ".$this->w($amount, $fem); } /** retourner le mot avec l'article indéfini et la quantité */ function un(int $amount=1, $fem=false): string { $abs_amount = abs($amount); if ($abs_amount == 0) { $aucun = $this->fem? "aucune ": "aucun "; return $aucun.$this->w($amount, $fem); } elseif ($abs_amount == 1) { $un = $this->fem? "une ": "un "; return $un.$this->w($amount, $fem); } else { return "les $amount ".$this->w($amount, $fem); } } function le(int $amount=1, $fem=false): string { $abs_amount = abs($amount); if ($abs_amount == 0) { $le = $this->fem? "la 0 ": "le 0 "; return $le.$this->w($amount, $fem); } elseif ($abs_amount == 1) { return $this->le.$this->w($amount, $fem); } else { return "les $amount ".$this->w($amount, $fem); } } function du(int $amount=1, $fem=false): string { $abs_amount = abs($amount); if ($abs_amount == 0) { $du = $this->fem? "de la 0 ": "du 0 "; return $du.$this->w($amount, $fem); } elseif ($abs_amount == 1) { return $this->du.$this->w($amount, $fem); } else { return "des $amount ".$this->w($amount, $fem); } } function au(int $amount=1, $fem=false): string { $abs_amount = abs($amount); if ($abs_amount == 0) { $au = $this->fem? "à la 0 ": "au 0 "; return $au.$this->w($amount, $fem); } elseif ($abs_amount == 1) { return $this->au.$this->w($amount, $fem); } else { return "aux $amount ".$this->w($amount, $fem); } } }