1
0
Fork 0
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:
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. * 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;
} }
} }

View file

@ -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));