Changeset View
Changeset View
Standalone View
Standalone View
src/parser/ArcanistCommentRemover.php
| <?php | <?php | ||||
| final class ArcanistCommentRemover extends Phobject { | final class ArcanistCommentRemover extends Phobject { | ||||
| /** | /** | ||||
| * Remove comment lines from a commit message. Strips trailing lines only, | * Remove comment lines from a commit message. Strips trailing lines only, | ||||
| * and requires "#" to appear at the beginning of a line for it to be | * and requires "#" to appear at the beginning of a line for it to be | ||||
| * 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; | |||||
| } | } | ||||
| } | } | ||||