Localizing files
[viewsvn.git] / includes / svnlib.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # ViewSVN [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 /**
23 * Command line interface with the SVN commands
24 *
25 * @package ViewSVN
26 */
27
28 /**
29 * Interacts with the command line subsystem to
30 * access SVN information
31 *
32 * @package ViewSVN
33 * @version $Id$
34 */
35 class SVNLib
36 {
37 /**
38 * Path to the SVN binary
39 * @var string
40 */
41 var $svnpath;
42
43 /**
44 * Common command system
45 * @var object
46 */
47 var $common;
48
49 /**
50 * Constructor: validate SVN path
51 *
52 * @param string Path to SVN binary
53 */
54 function SVNLib($svnpath)
55 {
56 global $viewsvn;
57
58 $this->svnpath = $viewsvn->shell->cmd($svnpath);
59
60 $this->common =& new SVNCommon();
61
62 $access = $viewsvn->shell->exec($this->svnpath . ' --version');
63
64 if (!$access)
65 {
66 $viewsvn->trigger->error($viewsvn->lang->string('The SVN binary could not be located'));
67 }
68
69 if (!preg_match('#^svn, version (.*?)\)$#i', trim($access[0])))
70 {
71 $viewsvn->trigger->error($viewsvn->lang->string('The SVN binary does not appear to be valid (it failed our tests)'));
72 }
73 }
74
75 /**
76 * Prepares data for output
77 *
78 * @access public
79 *
80 * @param string Standard data
81 *
82 * @return string Output-ready data
83 */
84 function format($string)
85 {
86 // convert entities
87 $string = htmlspecialchars($string);
88
89 // tabs to 5 spaces
90 $string = str_replace("\t", ' ', $string);
91
92 // spaces to nbsp
93 if (true)
94 {
95 $string = preg_replace('#( +)#e', '$this->format_spaces("\1")', $string);
96 }
97 // no word wrap
98 else
99 {
100 $string = str_replace(' ', '&nbsp;', $string);
101 }
102
103 // convert advanced diff
104 $string = str_replace(array('{@+' . '+}', '{@-' . '-}'), array('<span class="diff_add_bit">', '<span class="diff_del_bit">'), $string);
105 $string = str_replace(array('{/@+' . '+}', '{/@-' . '-}'), '</span>', $string);
106
107 // nl2br
108 $string = nl2br($string);
109
110 return $string;
111 }
112
113 /**
114 * Counts the spaces and replaces two or more ones
115 *
116 * @access private
117 *
118 * @param string Spaced string
119 *
120 * @return string &nbsp;'d string
121 */
122 function format_spaces($thestring)
123 {
124 if (strlen($thestring) >= 2)
125 {
126 $thestring = str_replace(' ', '&nbsp;', $thestring);
127 }
128
129 return $thestring;
130 }
131
132 /**
133 * Executes the SVN binary
134 *
135 * @access private
136 *
137 * @param string Command
138 *
139 * @return array Output
140 */
141 function svn($command)
142 {
143 global $viewsvn;
144
145 $output = $viewsvn->shell->exec($this->svnpath . ' ' . $command . ' 2>&1');
146
147 // make sure that we keep escaped chars
148 //$output = str_replace(array('\t', '\n', '\r'), array('\\\t', '\\\n', '\\\r'), $output);
149 //$output = preg_replace('#\\\(.)#', '\\\\\\\\' . '\1', $output);
150 $output = str_replace('\\', '\\\\', $output);
151
152 $temp = implode("\n", $output);
153 if (strpos($temp, '(apr' . '_err=') !== false)
154 {
155 $viewsvn->trigger->error(nl2br($temp));
156 }
157 return $output;
158 }
159
160 /**
161 * SVN Wrapper: standard command system
162 *
163 * @access private
164 *
165 * @param string SVN command
166 * @param string Repository
167 * @param string Path
168 * @param integer Revision
169 *
170 * @return array Lines of output
171 */
172 function std($command, $repos, $path, $revision)
173 {
174 global $viewsvn;
175
176 $revision = $this->rev($revision);
177 $repospath = $viewsvn->repos->fetch_path($repos, false);
178
179 return $this->svn($command . ' ' . $repospath . $path . '@' . $revision);
180 }
181
182 /**
183 * SVN Wrapper: blame
184 *
185 * @access protected
186 *
187 * @param string Repository
188 * @param string Path
189 * @param integer Revision
190 *
191 * @return array Lines of blame output
192 */
193 function blame($repos, $path, $revision)
194 {
195 return $this->std('blame', $repos, $path, $revision);
196 }
197
198 /**
199 * SVN Wrapper: cat
200 *
201 * @access protected
202 *
203 * @param string Repository
204 * @param string Path
205 * @param integer Revision
206 *
207 * @return array Lines of cat output
208 */
209 function cat($repos, $path, $revision)
210 {
211 return $this->std('cat', $repos, $path, $revision);
212 }
213
214 /**
215 * SVN Wrapper: diff
216 *
217 * @access protected
218 *
219 * @param string Repository
220 * @param string Path
221 * @param integer Lower revision
222 * @param integer Higher revision
223 *
224 * @return array Lines of diff output
225 */
226 function diff($repos, $path, $lorev, $hirev)
227 {
228 global $viewsvn;
229
230 $hirev = $this->rev($hirev);
231 $lorev = $this->rev($lorev);
232 if ($lorev == 'HEAD')
233 {
234 $lorev = 1;
235 }
236
237 if (is_integer($hirev) AND is_integer($lorev))
238 {
239 if ($lorev > $hirev)
240 {
241 $lorev = $hirev - 1;
242 }
243 if ($lorev == $hirev)
244 {
245 $lorev = 0;
246 }
247 }
248
249 $repospath = $viewsvn->repos->fetch_path($repos, false);
250
251 return $this->svn('diff -r' . $lorev . ':' . $hirev . ' ' . $repospath . $path);
252 }
253
254 /**
255 * SVN Wrapper: log
256 *
257 * @access protected
258 *
259 * @param string Repository
260 * @param string Path
261 * @param integer Lower revision
262 * @param integer Higher revision
263 *
264 * @return array Lines of log output
265 */
266 function log($repos, $path, $lorev, $hirev)
267 {
268 global $viewsvn;
269
270 $hirev = $this->rev($hirev);
271 $lorev = $this->rev($hirev);
272 if ($lorev == 'HEAD')
273 {
274 $lorev = 0;
275 }
276
277 if (is_integer($hirev) AND is_integer($lorev))
278 {
279 if ($lorev > $hirev)
280 {
281 $lorev = $hirev - 1;
282 }
283 if ($lorev == $hirev)
284 {
285 $lorev = 0;
286 }
287 }
288
289 $repospath = $viewsvn->repos->fetch_path($repos, false);
290
291 return $this->svn('log -v -r' . $hirev . ':' . $lorev . ' ' . $repospath . $path);
292 }
293
294 /**
295 * SVN Wrapper: ls (list)
296 *
297 * @access protected
298 *
299 * @param string Repository
300 * @param string Path
301 * @param integer Revision
302 *
303 * @return array Lines of list output
304 */
305 function ls($repos, $path, $revision)
306 {
307 return $this->std('list', $repos, $path, $revision);
308 }
309
310 /**
311 * Generates a clean revision number
312 *
313 * @access public
314 *
315 * @param integer Revision number
316 *
317 * @return mixed Cleaned revision or HEAD
318 */
319 function rev($revision)
320 {
321 if (($revision = intval($revision)) < 1)
322 {
323 $revision = 'HEAD';
324 }
325 return $revision;
326 }
327 }
328
329 /**
330 * Commonly executed SVN commands that return data
331 * used in many parts of the system
332 *
333 * @package ViewSVN
334 * @version $Id$
335 */
336 class SVNCommon
337 {
338 /**
339 * Registry object
340 * @var object
341 */
342 var $registry;
343
344 /**
345 * List of revisions
346 * @var array
347 */
348 var $revisions;
349
350 /**
351 * List of logs
352 * @var array
353 */
354 var $logs;
355
356 /**
357 * Constructor: bind with registry
358 */
359 function SVNCommon()
360 {
361 global $viewsvn;
362
363 $this->registry =& $viewsvn;
364 }
365
366 /**
367 * Checks to see if the given universal path is
368 * a directory
369 *
370 * @access public
371 *
372 * @param string Universal path
373 *
374 * @return bool Directory or not
375 */
376 function isdir($path)
377 {
378 $output = $this->registry->svn->std('info', $this->registry->paths->fetch_repos($path), $this->registry->paths->fetch_path($path), $this->registry->paths->fetch_rev_num());
379
380 foreach ($output AS $line)
381 {
382 if (preg_match('#^Node Kind: (.*)#', $line, $matches))
383 {
384 if (trim(strtolower($matches[1])) == 'directory')
385 {
386 return true;
387 }
388 }
389 }
390
391 return false;
392 }
393
394 /**
395 * Get a list of revisions for a path
396 *
397 * @access public
398 *
399 * @param string Universal path
400 *
401 * @return array Key revisions
402 */
403 function fetch_revs($path)
404 {
405 if (!isset($this->revisions["$path"]))
406 {
407 $log = $this->fetch_logs($path);
408
409 $revs = array_keys($log);
410
411 $this->revisions["$path"] = array(
412 'HEAD' => $revs[0],
413 'START' => $revs[ count($revs) - 1 ],
414 'revs' => $revs
415 );
416 }
417
418 return $this->revisions["$path"];
419 }
420
421 /**
422 * Gets the revision that is marked as HEAD
423 *
424 * @access public
425 *
426 * @param string Universal path
427 *
428 * @return integer Revision
429 */
430 function fetch_head_rev($path)
431 {
432 $revs = $this->fetch_revs($path);
433 return $revs['HEAD'];
434 }
435
436 /**
437 * Returns the previous revision to the one given
438 *
439 * @access public
440 *
441 * @param string Universal path
442 * @param integer Arbitrary revision
443 *
444 * @return integer Previous revision (-1 if none)
445 */
446 function fetch_prev_rev($path, $current)
447 {
448 global $viewsvn;
449
450 $revs = $this->fetch_revs($path);
451
452 if ($current == 'HEAD')
453 {
454 $current = $this->fetch_head_rev($path);
455 }
456
457 $index = array_search($current, $revs['revs']);
458 if ($current === false)
459 {
460 $message->trigger->error(sprintf($viewsvn->lang->string('Revision r%1$s is not in path %2$s'), $current, $path));
461 }
462
463 if (isset($revs['revs'][ $index + 1 ]))
464 {
465 return $revs['revs'][ $index + 1 ];
466 }
467 else
468 {
469 return -1;
470 }
471 }
472
473 /**
474 * Get a list of logs
475 *
476 * @access public
477 *
478 * @param string Universal path
479 *
480 * @return array Log data
481 */
482 function fetch_logs($path)
483 {
484 if (!isset($this->logs["$path"]))
485 {
486 $log = new SVNLog($this->registry->paths->fetch_repos($path), $this->registry->paths->fetch_path($path), 0, $this->registry->paths->fetch_rev_num());
487
488 $this->logs["$path"] = $log->fetch();
489 }
490
491 return $this->logs["$path"];
492 }
493
494 /**
495 * Returns a given log entry for a path
496 * and revision
497 *
498 * @access public
499 *
500 * @param string Universal path
501 * @param integer Arbitrary revision
502 *
503 * @return array Log entry
504 */
505 function fetch_log($path, $rev)
506 {
507 $logs = $this->fetch_logs($path);
508
509 $rev = $this->registry->svn->rev($rev);
510 if ($rev == 'HEAD')
511 {
512 $rev = $this->fetch_head_rev($path);
513 }
514
515 if (isset($logs["$rev"]))
516 {
517 return $logs["$rev"];
518 }
519 else
520 {
521 $keys = array_keys($logs);
522 sort($keys);
523
524 for ($i = 0; $i < count($keys); $i++)
525 {
526 if ($rev > $keys["$i"] AND $rev < $keys[ $i + 1 ])
527 {
528 return $logs["$keys[$i]"];
529 }
530 }
531
532 return null;
533 }
534 }
535
536 /**
537 * Prints the file changed list
538 *
539 * @access public
540 *
541 * @public array List of file changes
542 * @public string The repository
543 * @public integer Current revision
544 *
545 * @return string Processed HTML
546 */
547 function construct_file_changes($changes, $repos, $revision)
548 {
549 global $viewsvn;
550
551 $files = '';
552
553 foreach ($changes AS $file)
554 {
555 switch ($file['action'])
556 {
557 case 'A':
558 $class = 'file_add';
559 $tooltip = $viewsvn->lang->string('Added');
560 break;
561 case 'D':
562 $class = 'file_delete';
563 $tooltip = $viewsvn->lang->string('Deleted');
564 break;
565 case 'M':
566 $class = 'file_modify';
567 $tooltip = $viewsvn->lang->string('Modified');
568 break;
569 case 'R':
570 $class = 'file_replace';
571 $tooltip = $viewsvn->lang->string('Replaced');
572 break;
573 }
574
575 $show['from'] = (bool)$file['from'];
576
577 if ($file['from'])
578 {
579 $class = 'file_move';
580 $tooltip = 'Moved/Copied';
581 preg_match('#(.*):([0-9]+)#', $file['from'], $matches);
582 $link['from'] = $viewsvn->paths->out('view.php' . $viewsvn->paths->fetch_rev_str(false, $matches[2]), $repos . $matches[1]);
583 }
584
585 $link['file'] = $viewsvn->paths->out('view.php' . $viewsvn->paths->fetch_rev_str(false, $revision), $repos . $file['file']);
586
587 eval('$files .= "' . $viewsvn->template->fetch('file_change') . '";');
588 }
589
590 return $files;
591 }
592 }
593
594 /**
595 * Annotation/blame system; constructs an array
596 * that is ready for output
597 *
598 * @package ViewSVN
599 * @version $Id$
600 */
601 class SVNBlame
602 {
603 /**
604 * Array of blame information
605 * @var array
606 */
607 var $blame = array();
608
609 /**
610 * Raw "svn blame" output
611 * @var array
612 */
613 var $rawoutput;
614
615 /**
616 * Constructor: create blame and store data
617 *
618 * @param string Repository
619 * @param string Path
620 * @param integer Revision
621 */
622 function SVNBlame($repos, $path, $revision)
623 {
624 global $viewsvn;
625
626 $this->rawoutput = $viewsvn->svn->blame($repos, $path, $revision);
627 $this->process();
628 }
629
630 /**
631 * Returns blame for display
632 *
633 * @access public
634 *
635 * @return array Blame data
636 */
637 function fetch()
638 {
639 return $this->blame;
640 }
641
642 /**
643 * Parses the blame data
644 *
645 * @access private
646 */
647 function process()
648 {
649 $lineno = 1;
650
651 foreach ($this->rawoutput AS $line)
652 {
653 if (preg_match('#^\s+([0-9]+)\s+([\w\.\-_]+)\s(.*)$#', $line, $matches))
654 {
655 $this->blame[] = array(
656 'rev' => $matches[1],
657 'author' => $matches[2],
658 'line' => $matches[3],
659 'lineno' => $lineno++
660 );
661 }
662 // a blank line
663 else if (preg_match('#^\s+([0-9]+)\s+([\w\.\-_]+)$#', $line, $matches))
664 {
665 $this->blame[] = array(
666 'rev' => $matches[1],
667 'author' => $matches[2],
668 'line' => '',
669 'lineno' => $lineno++
670 );
671 }
672 }
673 }
674 }
675
676 /**
677 * Log management system; creates a complex list
678 * of SVN log information
679 *
680 * @package ViewSVN
681 * @version $Id$
682 */
683 class SVNLog
684 {
685 /**
686 * Array of logs
687 * @var array
688 */
689 var $logs = array();
690
691 /**
692 * Raw "svn log" output
693 * @var array
694 */
695 var $rawoutput;
696
697 /**
698 * Constructor: create log store for the given file
699 *
700 * @param string Repository
701 * @param string Path
702 * @param integer Lower revision
703 * @param integer Higher revision
704 */
705 function SVNLog($repos, $path, $lorev, $hirev)
706 {
707 global $viewsvn;
708
709 $this->rawoutput = $viewsvn->svn->log($repos, $path, $lorev, $hirev);
710 $this->process();
711 }
712
713 /**
714 * Returns logs for display
715 *
716 * @access public
717 *
718 * @return array Log data
719 */
720 function fetch()
721 {
722 return $this->logs;
723 }
724
725 /**
726 * Splits up the raw output into a usable log
727 *
728 * @access private
729 */
730 function process()
731 {
732 $lastrev = 0;
733
734 for ($i = 1; $i <= count($this->rawoutput) - 1; $i++)
735 {
736 $line = $this->rawoutput["$i"];
737
738 if (preg_match('#^r([0-9]*) \| (.*?) \| (....-..-.. ..:..:..) ([0-9\-]*) \((.*?)\) \| ([0-9]*) lines?$#', $line, $matches))
739 {
740 if (isset($this->logs["$lastrev"]))
741 {
742 $this->logs["$lastrev"]['message'] = $this->strip_last_line($this->logs["$lastrev"]['message']);
743 }
744
745 $this->logs["$matches[1]"] = array(
746 'rev' => $matches[1],
747 'author' => $matches[2],
748 'date' => $matches[3],
749 'timezone' => $matches[4],
750 'lines' => $matches[6],
751 'message' => ''
752 );
753
754 $lastrev = $matches[1];
755 }
756 else if (preg_match('#^\s+([ADMR])\s(.*)#', $line, $matches))
757 {
758 if (preg_match('#(.*) \(from (.*?)\)$#', $matches[2], $amatches))
759 {
760 $matches[2] = $amatches[1];
761 }
762
763 $this->logs["$lastrev"]['files'][] = array(
764 'action' => $matches[1],
765 'file' => trim($matches[2]),
766 'from' => (isset($amatches[2]) ? $amatches[2] : '')
767 );
768 }
769 else
770 {
771 if (trim($line) != 'Changed paths:')
772 {
773 $this->logs["$lastrev"]['message'] .= $line . "\n";
774 }
775 }
776 }
777
778 if (isset($this->logs["$lastrev"]))
779 {
780 $this->logs["$lastrev"]['message'] = $this->strip_last_line($this->logs["$lastrev"]['message']);
781 }
782 }
783
784 /**
785 * Trims the last dash line off a message
786 *
787 * @access private
788 *
789 * @param string Message with annoying-ass line
790 *
791 * @return string Clean string
792 */
793 function strip_last_line($string)
794 {
795 return trim(preg_replace("#\n(.*?)\n$#", '', $string));
796 }
797 }
798
799 /**
800 * Diff system; constructs a diff array that
801 * is ready for output
802 *
803 * @package ViewSVN
804 */
805 class SVNDiff
806 {
807 /**
808 * Array of diff information
809 * @var array
810 */
811 var $diff = array();
812
813 /**
814 * Raw "svn diff" output
815 * @var array
816 */
817 var $rawoutput;
818
819 /**
820 * Constructor: create and store diff data
821 *
822 * @param string Repository
823 * @param string Path
824 * @param integer Lower revision
825 * @param integer Higher revision
826 */
827 function SVNDiff($repos, $path, $lorev, $hirev)
828 {
829 global $viewsvn;
830
831 $this->rawoutput = $viewsvn->svn->diff($repos, $path, $lorev, $hirev);
832 $this->process();
833 }
834
835 /**
836 * Returns diffs for display
837 *
838 * @access public
839 *
840 * @return array Diff data
841 */
842 function fetch()
843 {
844 return $this->diff;
845 }
846
847 /**
848 * Processes and prepares diff data
849 *
850 * @access private
851 */
852 function process()
853 {
854 $chunk = 0;
855 $indexcounter = null;
856
857 $delstack = array();
858
859 foreach ($this->rawoutput AS $line)
860 {
861 if (preg_match('#^@@ \-([0-9]*),([0-9]*) \+([0-9]*),([0-9]*) @@$#', $line, $bits))
862 {
863 $delstack = array();
864 $this->diff["$index"][ ++$chunk ]['hunk'] = array('old' => array('line' => $bits[1], 'count' => $bits[2]), 'new' => array('line' => $bits[3], 'count' => $bits[4]));
865 $lines['old'] = $this->diff["$index"]["$chunk"]['hunk']['old']['line'] - 1;
866 $lines['new'] = $this->diff["$index"]["$chunk"]['hunk']['new']['line'] - 1;
867 continue;
868 }
869
870 if ($indexcounter <= 3 AND $indexcounter !== null)
871 {
872 //echo $line . "\n";
873 $indexcounter++;
874 continue;
875 }
876 else if ($indexcounter == 3)
877 {
878 $indexcounter = null;
879 //echo "\n\n\n";
880 continue;
881 }
882
883 if (preg_match('#^([\+\- ])(.*)#', $line, $matches))
884 {
885 $act = $matches[1];
886 $content = $matches[2];
887
888 if ($act == ' ')
889 {
890 $this->diff["$index"]["$chunk"][] = array(
891 'line' => $content,
892 'act' => '',
893 'oldlineno' => ++$lines['old'],
894 'newlineno' => ++$lines['new']
895 );
896
897 $delstack = array();
898 }
899 else if ($act == '+')
900 {
901 // potential line delta
902 if (count($delstack) > 0)
903 {
904 $lastline = array_shift($delstack);
905
906 if ($delta = @$this->fetch_diff_extent($lastline['line'], $content))
907 {
908 // create two sets of ends for the two contents
909 $delta['endo'] = strlen($lastline['line']) - $delta['end'];
910 $delta['endn'] = strlen($content) - $delta['end'];
911
912 $diffo = $delta['endo'] - $delta['start'];
913 $diffn = $delta['endn'] - $delta['start'];
914
915 if (strlen($lastline['line']) > $delta['endo'] - $diffo)
916 {
917 $removed = substr($lastline['line'], $delta['start'], $diffo);
918 $this->diff["$index"]["$chunk"]["$lastline[INDEX]"]['line'] = substr_replace($lastline['line'], '{@-' . '-}' . $removed . '{/@-' . '-}', $delta['start'], $diffo);
919 }
920
921 if (strlen($content) > $delta['endn'] - $diffn)
922 {
923 $added = substr($content, $delta['start'], $diffn);
924 $content = substr_replace($content, '{@+' . '+}' . $added . '{/@+' . '+}', $delta['start'], $diffn);
925 }
926 }
927 }
928
929 $this->diff["$index"]["$chunk"][] = array(
930 'line' => $content,
931 'act' => '+',
932 'oldlineno' => '',
933 'newlineno' => ++$lines['new']
934 );
935 }
936 else if ($act == '-')
937 {
938 $this->diff["$index"]["$chunk"][] = $thearray = array(
939 'line' => $content,
940 'act' => '-',
941 'oldlineno' => ++$lines['old'],
942 'newlineno' => ''
943 );
944
945 $key = count($this->diff["$index"]["$chunk"]) - 2;
946 $thearray['INDEX'] = $key;
947
948 array_push($delstack, $thearray);
949 }
950 }
951 // whitespace lines
952 else
953 {
954 if (preg_match('#^Index: (.*?)$#', $line, $matches))
955 {
956 $index = $matches[1];
957 $indexcounter = 1;
958 $chunk = 0;
959 continue;
960 }
961
962 $this->diff["$index"]["$chunk"][] = array(
963 'line' => '',
964 'act' => '',
965 'oldlineno' => ++$lines['old'],
966 'newlineno' => ++$lines['new']
967 );
968
969 $delstack = array();
970 }
971 }
972 }
973
974 /**
975 * Returns the amount of change that occured
976 * between two lines
977 *
978 * @access private
979 *
980 * @param string Old line
981 * @param string New line
982 *
983 * @return array Difference of positions
984 */
985 function fetch_diff_extent($old, $new)
986 {
987 $start = 0;
988 $min = min(strlen($old), strlen($new));
989
990 for ($start = 0; $start < $min; $start++)
991 {
992 if ($old{"$start"} != $new{"$start"})
993 {
994 break;
995 }
996 }
997
998 $max = max(strlen($old), strlen($new));
999
1000 for ($end = 0; $end < $min; $end++)
1001 {
1002 $oldpos = strlen($old) - $end;
1003 $newpos = strlen($new) - $end;
1004
1005 if ($old{"$oldpos"} != $new{"$newpos"})
1006 {
1007 break;
1008 }
1009 }
1010
1011 $end--;
1012
1013 if ($start == 0 AND $end == $max)
1014 {
1015 return false;
1016 }
1017
1018 return array('start' => $start, 'end' => $end);
1019 }
1020 }
1021
1022 /*=====================================================================*\
1023 || ###################################################################
1024 || # $HeadURL$
1025 || # $Id$
1026 || ###################################################################
1027 \*=====================================================================*/
1028 ?>