aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1994-12-04 21:07:03 +0000
committerRichard M. Stallman1994-12-04 21:07:03 +0000
commitd8638d30b5f071693be7defe793a6c96fc05d705 (patch)
tree0bfb34d18e92a9195c40d6cace2c16b3b003d738
parent3fc86d4befc3c3c01f09940db8756cc0c9d581ce (diff)
downloademacs-d8638d30b5f071693be7defe793a6c96fc05d705.tar.gz
emacs-d8638d30b5f071693be7defe793a6c96fc05d705.zip
(compare_string_intervals): New function.
-rw-r--r--src/intervals.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/intervals.c b/src/intervals.c
index 25fb6e741cf..f7560fb6b7a 100644
--- a/src/intervals.c
+++ b/src/intervals.c
@@ -53,6 +53,8 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
53 53
54#define TMEM(sym, set) (CONSP (set) ? ! NILP (Fmemq (sym, set)) : ! NILP (set)) 54#define TMEM(sym, set) (CONSP (set) ? ! NILP (Fmemq (sym, set)) : ! NILP (set))
55 55
56#define min(x, y) ((x) < (y) ? (x) : (y))
57
56Lisp_Object merge_properties_sticky (); 58Lisp_Object merge_properties_sticky ();
57 59
58/* Utility functions for intervals. */ 60/* Utility functions for intervals. */
@@ -2036,5 +2038,44 @@ copy_intervals_to_string (string, buffer, position, length)
2036 interval_copy->parent = (INTERVAL) string; 2038 interval_copy->parent = (INTERVAL) string;
2037 XSTRING (string)->intervals = interval_copy; 2039 XSTRING (string)->intervals = interval_copy;
2038} 2040}
2041
2042/* Return 1 if string S1 and S2 have identical properties; 0 otherwise.
2043 Assume they have identical characters. */
2044
2045int
2046compare_string_intervals (s1, s2)
2047 Lisp_Object s1, s2;
2048{
2049 INTERVAL i1, i2;
2050 int pos = 1;
2051 int end = XSTRING (s1)->size + 1;
2052
2053 /* We specify 1 as position because the interval functions
2054 always use positions starting at 1. */
2055 i1 = find_interval (XSTRING (s1)->intervals, 1);
2056 i2 = find_interval (XSTRING (s2)->intervals, 1);
2057
2058 while (pos < end)
2059 {
2060 /* Determine how far we can go before we reach the end of I1 or I2. */
2061 int len1 = (i1 != 0 ? INTERVAL_LAST_POS (i1) : end) - pos;
2062 int len2 = (i2 != 0 ? INTERVAL_LAST_POS (i2) : end) - pos;
2063 int distance = min (len1, len2);
2064
2065 /* If we ever find a mismatch between the strings,
2066 they differ. */
2067 if (! intervals_equal (i1, i2))
2068 return 0;
2069
2070 /* Advance POS till the end of the shorter interval,
2071 and advance one or both interval pointers for the new position. */
2072 pos += distance;
2073 if (len1 == distance)
2074 i1 = next_interval (i1);
2075 if (len2 == distance)
2076 i2 = next_interval (i2);
2077 }
2078 return 1;
2079}
2039 2080
2040#endif /* USE_TEXT_PROPERTIES */ 2081#endif /* USE_TEXT_PROPERTIES */