1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-10 00:42:40 +01:00

(stable) Promote 2018 Week 37

This commit is contained in:
epriestley 2018-09-15 08:18:21 -07:00
commit f5e65a808e
2 changed files with 26 additions and 7 deletions

View file

@ -8,21 +8,25 @@ final class ArcanistCommentRemover extends Phobject {
* considered a comment.
*/
public static function removeComments($body) {
$lines = explode("\n", $body);
$body = rtrim($body);
$lines = phutil_split_lines($body);
$lines = array_reverse($lines);
foreach ($lines as $key => $line) {
if (!strlen($line)) {
unset($lines[$key]);
continue;
}
if ($line[0] == '#') {
if (preg_match('/^#/', $line)) {
unset($lines[$key]);
continue;
}
break;
}
$lines = array_reverse($lines);
return implode("\n", $lines)."\n";
$lines = implode('', $lines);
$lines = rtrim($lines)."\n";
return $lines;
}
}

View file

@ -24,6 +24,21 @@ Here is a list:
The end.
EOTEXT;
$this->assertEqual($expect, ArcanistCommentRemover::removeComments($test));
$test = <<<EOTEXT
Subscribers:
#projectname
# Instructional comments.
EOTEXT;
$expect = <<<EOTEXT
Subscribers:
#projectname
EOTEXT;
$this->assertEqual($expect, ArcanistCommentRemover::removeComments($test));