@@ -138,17 +138,18 @@ public function parse(): self
138138 */
139139 protected function parseMultiLines (array $ lines ): array
140140 {
141- $ index = 0 ;
141+ $ index = $ keyWidth = 0 ;
142142 $ rules = $ kvRules = [];
143143
144- $ keyWidth = 16 ; // with an default value.
144+ $ sepChar = ' ' ;
145+ $ sepLen = strlen ($ sepChar );
145146 foreach ($ lines as $ line ) {
146147 $ trimmed = trim ($ line );
147148 if (!$ trimmed ) {
148149 continue ;
149150 }
150151
151- $ nodes = Str::explode ($ trimmed , ' ' , 2 );
152+ $ nodes = Str::explode ($ trimmed , $ sepChar , 2 );
152153 if (!isset ($ nodes [1 ])) {
153154 if ($ index === 0 ) { // invalid first line
154155 continue ;
@@ -159,12 +160,6 @@ protected function parseMultiLines(array $lines): array
159160 continue ;
160161 }
161162
162- // TIP: special - if line indent space len gt keyWidth, is desc message of multi line.
163- if (!trim (substr ($ line , 0 , $ keyWidth ))) {
164- $ rules [$ index - 1 ][1 ] .= "\n" . $ trimmed ; // multi desc message.
165- continue ;
166- }
167-
168163 $ name = trim ($ nodes [0 ], '. ' );
169164 if (!preg_match ('/^[\w ,-]{0,48}$/ ' , $ name )) {
170165 if ($ index === 0 ) { // invalid first line
@@ -176,9 +171,15 @@ protected function parseMultiLines(array $lines): array
176171 continue ;
177172 }
178173
179- $ nameLen = strlen ($ name );
174+ $ nameLen = strlen ($ name ) + $ sepLen ;
180175 $ keyWidth = $ nameLen > $ keyWidth ? $ nameLen : $ keyWidth ;
181176
177+ // TIP: special - if line indent space len gt keyWidth, is desc message of multi line.
178+ if (!trim (substr ($ line , 0 , $ keyWidth ))) {
179+ $ rules [$ index - 1 ][1 ] .= "\n" . $ trimmed ; // multi desc message.
180+ continue ;
181+ }
182+
182183 // append
183184 $ rules [$ index ] = [$ name , $ nodes [1 ]];
184185 $ index ++;
0 commit comments