-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodeconv.php
51 lines (42 loc) · 1.29 KB
/
codeconv.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
/**
* codeconv.php
* Author: Hiroyoshi Kurohara(Microgadget,inc.)
* Author EMail: kurohara@yk.rim.or.jp
* License: GPLv2 or Lator
*/
namespace questionnaire;
class codeconv_filter extends \php_user_filter {
var $tocode;
var $converting;
function doconv(&$out, &$bucket) {
if (strlen($this->converting) > 0) {
$bucket->data = mb_convert_encoding($this->converting, $this->tocode);
stream_bucket_append($out, $bucket);
$this->converting = "";
}
}
function filter($in, $out, &$consumed, $closing) {
while ($bucket = stream_bucket_make_writeable($in)) {
$nlpos = strpos($bucket->data, "\n");
if ($nlpos === FALSE) {
$this->converting = $this->converging . $bucket->data;
} else {
$this->converting = $this->converting . substr($bucket->data, 0, $nlpos + 1);
$this->doconv($out, $bucket);
$this->converting = substr($bucket->data, $nlpos + 1);
}
$consumed += $bucket->datalen;
}
if ($closing) {
$this->doconv($out, $bucket);
}
return PSFS_PASS_ON;
}
function onCreate() {
$this->tocode = str_replace("codeconvto.", "", $this->filtername);
return true;
}
}
stream_filter_register("codeconvto.*", __NAMESPACE__ . "\codeconv_filter")
or die("Failed to register filter");