php_strip_whitespace
Close to zend's. Needed for composer. I can't move the real zend test over since we don't apply zend's calling convention to systemlib (yet).
Esse commit está contido em:
+2
-1
@@ -1,8 +1,9 @@
|
||||
Future (next release):
|
||||
- Implement assert with string arguments
|
||||
- Implement RecursiveArrayIterator
|
||||
- Implement php_strip_whitespace()
|
||||
|
||||
"Tamale" 7/22/2013
|
||||
- Implement RecursiveArrayIterator
|
||||
- Optimize vector-shaped Arrays (arrays with keys in range 0..size-1)
|
||||
- Enable HHBC by default in debug builds
|
||||
- Implement SplObjectStorage::getInfo()
|
||||
|
||||
@@ -227,10 +227,6 @@ bool f_php_check_syntax(CStrRef filename, VRefParam error_message /* = null */)
|
||||
throw NotSupportedException(__func__, "PHP specific");
|
||||
}
|
||||
|
||||
String f_php_strip_whitespace(CStrRef filename) {
|
||||
throw NotSupportedException(__func__, "PHP specific");
|
||||
}
|
||||
|
||||
int64_t f_sleep(int seconds) {
|
||||
IOStatusHelper io("sleep");
|
||||
sleep(seconds);
|
||||
|
||||
@@ -42,7 +42,6 @@ Variant f_highlight_string(CStrRef str, bool ret = false);
|
||||
int64_t f_ignore_user_abort(bool setting = false);
|
||||
Variant f_pack(int _argc, CStrRef format, CArrRef _argv = null_array);
|
||||
bool f_php_check_syntax(CStrRef filename, VRefParam error_message = uninit_null());
|
||||
String f_php_strip_whitespace(CStrRef filename);
|
||||
int64_t f_sleep(int seconds);
|
||||
void f_usleep(int micro_seconds);
|
||||
Variant f_time_nanosleep(int seconds, int nanoseconds);
|
||||
|
||||
@@ -339,24 +339,6 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "php_strip_whitespace",
|
||||
"desc": "Returns the PHP source code in filename with PHP comments and whitespace removed. This may be useful for determining the amount of actual code in your scripts compared with the amount of comments. This is similar to using php -w from the commandline.",
|
||||
"flags": [
|
||||
"HasDocComment"
|
||||
],
|
||||
"return": {
|
||||
"type": "String",
|
||||
"desc": null
|
||||
},
|
||||
"args": [
|
||||
{
|
||||
"name": "filename",
|
||||
"type": "String",
|
||||
"desc": "Path to the PHP file."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "sleep",
|
||||
"flags": [
|
||||
|
||||
@@ -61,6 +61,7 @@ hphp/system/php/dom/DOMException.php
|
||||
hphp/system/php/file_system/Directory.php
|
||||
hphp/system/php/json/JsonSerializable.php
|
||||
hphp/system/php/lang/ErrorException.php
|
||||
hphp/system/php/misc/php_strip_whitespace.php
|
||||
hphp/system/php/pdo/PDOException.php
|
||||
hphp/system/php/redis/Redis.php
|
||||
hphp/system/php/reflection/reflection.php
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
function php_strip_whitespace($file) {
|
||||
$data = file_get_contents($file);
|
||||
if ($data === false) {
|
||||
return "";
|
||||
}
|
||||
|
||||
$tokens = token_get_all($data);
|
||||
$output = '';
|
||||
$prev_space = false;
|
||||
|
||||
for ($i = 0; $i < count($tokens); $i++) {
|
||||
$token = $tokens[$i];
|
||||
|
||||
if (!is_array($token)) {
|
||||
$output .= $token;
|
||||
$prev_space = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
list($type, $string, $line) = $token;
|
||||
switch ($type) {
|
||||
case T_WHITESPACE:
|
||||
if (!$prev_space) {
|
||||
$output .= ' ';
|
||||
$prev_space = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case T_COMMENT:
|
||||
case T_DOC_COMMENT:
|
||||
// don't reset $prev_space since we didn't output anything
|
||||
break;
|
||||
|
||||
case T_END_HEREDOC:
|
||||
$output .= $string;
|
||||
$next_token = $tokens[++$i];
|
||||
if (!is_array($next_token)) {
|
||||
$output .= $next_token;
|
||||
} else if ($next_token[0] != T_WHITESPACE) {
|
||||
$output .= $next_token[1];
|
||||
}
|
||||
$output .= "\n";
|
||||
$prev_space = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
$output .= $string;
|
||||
$prev_space = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
// PHP comment here
|
||||
|
||||
/*
|
||||
* Another PHP comment
|
||||
*/
|
||||
|
||||
echo php_strip_whitespace(__FILE__);
|
||||
// Newlines are considered whitespace, and are removed too:
|
||||
function do_nothing() {
|
||||
};
|
||||
do_nothing();
|
||||
?>
|
||||
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
echo php_strip_whitespace(__FILE__); function do_nothing() { }; do_nothing(); ?>
|
||||
@@ -0,0 +1,5 @@
|
||||
// this comment will not be removed
|
||||
<?php
|
||||
// this comment will be removed
|
||||
var_dump(php_strip_whitespace(__FILE__));
|
||||
?>
|
||||
@@ -0,0 +1,5 @@
|
||||
// this comment will not be removed
|
||||
string(87) "// this comment will not be removed
|
||||
<?php
|
||||
var_dump(php_strip_whitespace(__FILE__)); ?>
|
||||
"
|
||||
Referência em uma Nova Issue
Bloquear um usuário