mirror of
https://we.phorge.it/source/arcanist.git
synced 2025-02-21 11:09:02 +01:00
(stable) Promote 2018 Week 37
This commit is contained in:
commit
f5e65a808e
2 changed files with 26 additions and 7 deletions
|
@ -8,21 +8,25 @@ final class ArcanistCommentRemover extends Phobject {
|
||||||
* considered a comment.
|
* considered a comment.
|
||||||
*/
|
*/
|
||||||
public static function removeComments($body) {
|
public static function removeComments($body) {
|
||||||
$lines = explode("\n", $body);
|
$body = rtrim($body);
|
||||||
|
|
||||||
|
$lines = phutil_split_lines($body);
|
||||||
$lines = array_reverse($lines);
|
$lines = array_reverse($lines);
|
||||||
|
|
||||||
foreach ($lines as $key => $line) {
|
foreach ($lines as $key => $line) {
|
||||||
if (!strlen($line)) {
|
if (preg_match('/^#/', $line)) {
|
||||||
unset($lines[$key]);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if ($line[0] == '#') {
|
|
||||||
unset($lines[$key]);
|
unset($lines[$key]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$lines = array_reverse($lines);
|
$lines = array_reverse($lines);
|
||||||
return implode("\n", $lines)."\n";
|
$lines = implode('', $lines);
|
||||||
|
$lines = rtrim($lines)."\n";
|
||||||
|
|
||||||
|
return $lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,21 @@ Here is a list:
|
||||||
|
|
||||||
The end.
|
The end.
|
||||||
|
|
||||||
|
EOTEXT;
|
||||||
|
|
||||||
|
$this->assertEqual($expect, ArcanistCommentRemover::removeComments($test));
|
||||||
|
|
||||||
|
$test = <<<EOTEXT
|
||||||
|
Subscribers:
|
||||||
|
#projectname
|
||||||
|
|
||||||
|
# Instructional comments.
|
||||||
|
EOTEXT;
|
||||||
|
|
||||||
|
$expect = <<<EOTEXT
|
||||||
|
Subscribers:
|
||||||
|
#projectname
|
||||||
|
|
||||||
EOTEXT;
|
EOTEXT;
|
||||||
|
|
||||||
$this->assertEqual($expect, ArcanistCommentRemover::removeComments($test));
|
$this->assertEqual($expect, ArcanistCommentRemover::removeComments($test));
|
||||||
|
|
Loading…
Add table
Reference in a new issue