@@ -196,16 +196,11 @@ private function getDiffBufferElement($diff, $i, $newChunk, $buffer)
196
196
*/
197
197
public function diffToArray ($ from , $ to , LongestCommonSubsequence $ lcs = null )
198
198
{
199
- preg_match_all ( ' (\r\n|\r|\n) ' , $ from , $ fromMatches );
200
- preg_match_all ( ' (\r\n|\r|\n) ' , $ to , $ toMatches );
199
+ $ fromMatches = $ this -> getNewLineMatches ( $ from );
200
+ $ toMatches = $ this -> getNewLineMatches ( $ to );
201
201
202
- if (is_string ($ from )) {
203
- $ from = preg_split ('(\r\n|\r|\n) ' , $ from );
204
- }
205
-
206
- if (is_string ($ to )) {
207
- $ to = preg_split ('(\r\n|\r|\n) ' , $ to );
208
- }
202
+ $ from = $ this ->splitStringByLines ($ from );
203
+ $ to = $ this ->splitStringByLines ($ to );
209
204
210
205
$ start = array ();
211
206
$ end = array ();
@@ -287,6 +282,31 @@ public function diffToArray($from, $to, LongestCommonSubsequence $lcs = null)
287
282
return $ diff ;
288
283
}
289
284
285
+ /**
286
+ * @param $string
287
+ *
288
+ * @return mixed
289
+ */
290
+ private function getNewLineMatches ($ string ) {
291
+ preg_match_all ('(\r\n|\r|\n) ' , $ string , $ stringMatches );
292
+ return $ stringMatches ;
293
+
294
+ }
295
+
296
+ /**
297
+ * Checks if input is string, if so it will split it line-by-life.
298
+ * @param $input
299
+ *
300
+ * @return array
301
+ */
302
+ private function splitStringByLines ($ input ) {
303
+ if (is_string ($ input )) {
304
+ return preg_split ('(\r\n|\r|\n) ' , $ input );
305
+ }
306
+
307
+ return $ input ;
308
+ }
309
+
290
310
/**
291
311
* @param array $from
292
312
* @param array $to
0 commit comments