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:
commit
f5e65a808e
2 changed files with 26 additions and 7 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Reference in a new issue