PluginProbe
WPIDE – File Manager & Code Editor / 2.2
WPIDE – File Manager & Code Editor v2.2
3.5.8 3.5.7 2.0.14 2.0.15 2.0.16 2.0.2 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1 2.2 2.3 2.3.1 2.3.2 2.4.0 2.5 2.6 3.0 3.1 3.2 3.3 3.4 All 54 releases
wpide / PHP-Parser / lib / PHPParser / Comment.php

Comment.php in WPIDE – File Manager & Code Editor 2.2, at PHP-Parser/lib/PHPParser/Comment.php

117 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class PHPParser_Comment
4 {
5 protected $text;
6 protected $line;
7
8 /**
9 * Constructs a comment node.
10 *
11 * @param string $text Comment text (including comment delimiters like /*)
12 * @param int $line Line number the comment started on
13 */
14 public function __construct($text, $line = -1) {
15 $this->text = $text;
16 $this->line = $line;
17 }
18
19 /**
20 * Gets the comment text.
21 *
22 * @return string The comment text (including comment delimiters like /*)
23 */
24 public function getText() {
25 return $this->text;
26 }
27
28 /**
29 * Sets the comment text.
30 *
31 * @param string $text The comment text (including comment delimiters like /*)
32 */
33 public function setText($text) {
34 $this->text = $text;
35 }
36
37 /**
38 * Gets the line number the comment started on.
39 *
40 * @return int Line number
41 */
42 public function getLine() {
43 return $this->line;
44 }
45
46 /**
47 * Sets the line number the comment started on.
48 *
49 * @param int $line Line number
50 */
51 public function setLine($line) {
52 $this->line = $line;
53 }
54
55 /**
56 * Gets the comment text.
57 *
58 * @return string The comment text (including comment delimiters like /*)
59 */
60 public function __toString() {
61 return $this->text;
62 }
63
64 /**
65 * Gets the reformatted comment text.
66 *
67 * "Reformatted" here means that we try to clean up the whitespace at the
68 * starts of the lines. This is necessary because we receive the comments
69 * without trailing whitespace on the first line, but with trailing whitespace
70 * on all subsequent lines.
71 *
72 * @return mixed|string
73 */
74 public function getReformattedText() {
75 $text = trim($this->text);
76 if (false === strpos($text, "\n")) {
77 // Single line comments don't need further processing
78 return $text;
79 } elseif (preg_match('((*BSR_ANYCRLF)(*ANYCRLF)^.*(?:\R\s+\*.*)+$)', $text)) {
80 // Multi line comment of the type
81 //
82 // /*
83 // * Some text.
84 // * Some more text.
85 // */
86 //
87 // is handled by replacing the whitespace sequences before the * by a single space
88 return preg_replace('(^\s+\*)m', ' *', $this->text);
89 } elseif (preg_match('(^/\*\*?\s*[\r\n])', $text) && preg_match('(\n(\s*)\*/$)', $text, $matches)) {
90 // Multi line comment of the type
91 //
92 // /*
93 // Some text.
94 // Some more text.
95 // */
96 //
97 // is handled by removing the whitespace sequence on the line before the closing
98 // */ on all lines. So if the last line is " */", then " " is removed at the
99 // start of all lines.
100 return preg_replace('(^' . preg_quote($matches[1]) . ')m', '', $text);
101 } elseif (preg_match('(^/\*\*?\s*(?!\s))', $text, $matches)) {
102 // Multi line comment of the type
103 //
104 // /* Some text.
105 // Some more text.
106 // Even more text. */
107 //
108 // is handled by taking the length of the "/* " segment and leaving only that
109 // many space characters before the lines. Thus in the above example only three
110 // space characters are left at the start of every line.
111 return preg_replace('(^\s*(?= {' . strlen($matches[0]) . '}(?!\s)))m', '', $text);
112 }
113
114 // No idea how to format this comment, so simply return as is
115 return $text;
116 }
117 }