Enable hard enforcement of return typehints by default
[hiphop-php.git] / hphp / runtime / ext / icu / ext_icu_uconverter.php
blobe7ce61dfc1800d0aa0eb3c56dd82db96a17daf53
1 <?hh
2 // @generated by docskel.php
4 <<__NativeData("UConverter")>>
5 class UConverter {
6 /**
7 * Create UConverter object
9 * @param string $destination_encoding -
10 * @param string $source_encoding -
12 * @return -
14 <<__Native>>
15 public function __construct(string $destination_encoding = 'utf-8',
16 string $source_encoding = 'utf-8'): void;
18 /**
19 * Convert string from one charset to another
21 * @param string $str -
22 * @param bool $reverse -
24 * @return string -
26 <<__Native>>
27 public function convert(string $str,
28 bool $reverse = false): mixed;
30 /**
31 * Default "from" callback function
33 * @param int $reason -
34 * @param string $source -
35 * @param string $codePoint -
36 * @param int $error -
38 * @return mixed -
40 public function fromUCallback(int $reason,
41 array $source,
42 int $codePoint,
43 int &$error): mixed {
44 switch ($reason) {
45 case self::REASON_UNASSIGNED:
46 case self::REASON_ILLEGAL:
47 case self::REASON_IRREGULAR:
48 $error = U_ZERO_ERROR;
49 return $this->getDestinationSubstChars();
51 return null;
54 /**
55 * Get the aliases of the given name
57 * @param string $name -
59 * @return array -
61 <<__Native>>
62 public static function getAliases(string $name): mixed;
64 /**
65 * Get the available canonical converter names
67 * @return array -
69 <<__Native>>
70 public static function getAvailable(): array;
72 /**
73 * Get the destination encoding
75 * @return string -
77 <<__Native>>
78 public function getDestinationEncoding(): string;
80 /**
81 * Get the destination converter type
83 * @return int -
85 <<__Native>>
86 public function getDestinationType(): int;
88 /**
89 * Get last error code on the object
91 * @return int -
93 <<__Native>>
94 public function getErrorCode(): int;
96 /**
97 * Get last error message on the object
99 * @return string -
101 <<__Native>>
102 public function getErrorMessage(): string;
105 * Get the source encoding
107 * @return string -
109 <<__Native>>
110 public function getSourceEncoding(): string;
113 * Get the source convertor type
115 * @return int -
117 <<__Native>>
118 public function getSourceType(): int;
121 * Get standard name
123 * @return string
125 <<__Native>>
126 public static function getStandardName(string $name,
127 string $standard): mixed;
130 * Get mime name
132 * @return string
134 public static function getMimeName(string $name): mixed {
135 return self::getStandardName($name, "MIME");
139 * Get standards associated to converter names
141 * @return array -
143 <<__Native>>
144 public static function getStandards(): mixed;
147 * Get substitution chars
149 * @return string -
151 <<__Native>>
152 public function getDestinationSubstChars(): mixed;
155 * Get substitution chars
157 * @return string -
159 <<__Native>>
160 public function getSourceSubstChars(): mixed;
163 * Get substitution chars
165 * @return string -
167 public function getSubstChars(): mixed {
168 // Ambiguous, but mostly PHP compat
169 // since PHP version lacks distinct setters
170 return $this->getSourceSubstChars();
174 * Get string representation of the callback reason
176 * @param int $reason -
178 * @return string -
180 <<__Native>>
181 public static function reasonText(int $reason): mixed;
184 * Set the destination encoding
186 * @param string $encoding -
188 * @return void -
190 <<__Native>>
191 public function setDestinationEncoding(string $encoding): void;
194 * Set the source encoding
196 * @param string $encoding -
198 * @return void -
200 <<__Native>>
201 public function setSourceEncoding(string $encoding): bool;
204 * Set the substitution chars
206 * @param string $chars -
208 * @return void -
210 <<__Native>>
211 public function setDestinationSubstChars(string $chars): bool;
214 * Set the destination substitution chars
216 * @param string $chars -
218 * @return void -
220 <<__Native>>
221 public function setSourceSubstChars(string $chars): bool;
224 * Set the substitution chars
226 * @param string $chars -
228 * @return void -
230 public function setSubstChars(string $chars): bool {
231 return $this->setSourceSubstChars($chars) &&
232 $this->setDestinationSubstChars($chars);
236 * Default "to" callback function
238 * @param int $reason -
239 * @param string $source -
240 * @param string $codeUnits -
241 * @param int $error -
243 * @return mixed -
245 public function toUCallback(int $reason,
246 ?string $source,
247 ?string $codeUnits,
248 int &$error): mixed {
249 switch ($reason) {
250 case self::REASON_UNASSIGNED:
251 case self::REASON_ILLEGAL:
252 case self::REASON_IRREGULAR:
253 $error = U_ZERO_ERROR;
254 return $this->getSourceSubstChars();
256 return null;
260 * Convert string from one charset to another
262 * @param string $str -
263 * @param string $toEncoding -
264 * @param string $fromEncoding -
265 * @param array $options -
267 * @return string -
269 public static function transcode(string $str,
270 string $toEncoding,
271 string $fromEncoding,
272 array $options = null): ?string {
273 $cnv = new UConverter($toEncoding, $fromEncoding);
274 if ((isset($options['from_subst']) &&
275 !$cnv->setSourceSubstChars($options['from_subst'])) ||
276 (isset($options['to_subst']) &&
277 !$cnv->setDestinationSubstChars($options['to_subst']))) {
278 return null;
280 return $cnv->convert($str);