aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGerd Moellmann1999-07-28 18:05:44 +0000
committerGerd Moellmann1999-07-28 18:05:44 +0000
commit4fdb80f2a251701594cc1663d8f293f5ea6835ae (patch)
tree54bdae0695462b2b6a9dbae200475bace7a7580a /src
parent492bd7587de29d4a79f65181a8657c0d38bab2eb (diff)
downloademacs-4fdb80f2a251701594cc1663d8f293f5ea6835ae.tar.gz
emacs-4fdb80f2a251701594cc1663d8f293f5ea6835ae.zip
(string_char_and_length): New. Use it everywhere
instead of STRING_CHAR_AND_LENGTH in xdisp.c.
Diffstat (limited to 'src')
-rw-r--r--src/xdisp.c50
1 files changed, 38 insertions, 12 deletions
diff --git a/src/xdisp.c b/src/xdisp.c
index 21c4400145b..099d37a515e 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -598,6 +598,7 @@ enum move_it_result
598 598
599/* Function prototypes. */ 599/* Function prototypes. */
600 600
601static int string_char_and_length P_ ((unsigned char *, int, int *));
601static struct text_pos display_prop_end P_ ((struct it *, Lisp_Object, 602static struct text_pos display_prop_end P_ ((struct it *, Lisp_Object,
602 struct text_pos)); 603 struct text_pos));
603static int compute_window_start_on_continuation_line P_ ((struct window *)); 604static int compute_window_start_on_continuation_line P_ ((struct window *));
@@ -860,6 +861,31 @@ window_box_edges (w, area, top_left_x, top_left_y,
860 Utilities 861 Utilities
861 ***********************************************************************/ 862 ***********************************************************************/
862 863
864/* Return the next character from STR which is MAXLEN bytes long.
865 Return in *LEN the length of the character. This is like
866 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
867 we find one, we return a `?', but with the length of the illegal
868 character. */
869
870static INLINE int
871string_char_and_length (str, max_len, len)
872 unsigned char *str;
873 int max_len, *len;
874{
875 int c;
876
877 c = STRING_CHAR_AND_LENGTH (str, maxlen, *len);
878 if (!CHAR_VALID_P (c, 1))
879 /* We may not change the length here because other places in Emacs
880 don't use this function, i.e. they silently accept illegal
881 characters. */
882 c = '?';
883
884 return c;
885}
886
887
888
863/* Given a position POS containing a valid character and byte position 889/* Given a position POS containing a valid character and byte position
864 in STRING, return the position NCHARS ahead (NCHARS >= 0). */ 890 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
865 891
@@ -879,7 +905,7 @@ string_pos_nchars_ahead (pos, string, nchars)
879 905
880 while (nchars--) 906 while (nchars--)
881 { 907 {
882 STRING_CHAR_AND_LENGTH (p, rest, len); 908 string_char_and_length (p, rest, &len);
883 p += len, rest -= len; 909 p += len, rest -= len;
884 xassert (rest >= 0); 910 xassert (rest >= 0);
885 CHARPOS (pos) += 1; 911 CHARPOS (pos) += 1;
@@ -931,7 +957,7 @@ c_string_pos (charpos, s, multibyte_p)
931 SET_TEXT_POS (pos, 0, 0); 957 SET_TEXT_POS (pos, 0, 0);
932 while (charpos--) 958 while (charpos--)
933 { 959 {
934 STRING_CHAR_AND_LENGTH (s, rest, len); 960 string_char_and_length (s, rest, &len);
935 s += len, rest -= len; 961 s += len, rest -= len;
936 xassert (rest >= 0); 962 xassert (rest >= 0);
937 CHARPOS (pos) += 1; 963 CHARPOS (pos) += 1;
@@ -962,7 +988,7 @@ number_of_chars (s, multibyte_p)
962 988
963 for (nchars = 0; rest > 0; ++nchars) 989 for (nchars = 0; rest > 0; ++nchars)
964 { 990 {
965 STRING_CHAR_AND_LENGTH (p, rest, len); 991 string_char_and_length (p, rest, &len);
966 rest -= len, p += len; 992 rest -= len, p += len;
967 } 993 }
968 } 994 }
@@ -1009,7 +1035,7 @@ charset_at_position (pos)
1009 int maxlen = ((BYTEPOS (pos) >= GPT_BYTE ? ZV_BYTE : GPT_BYTE) 1035 int maxlen = ((BYTEPOS (pos) >= GPT_BYTE ? ZV_BYTE : GPT_BYTE)
1010 - BYTEPOS (pos)); 1036 - BYTEPOS (pos));
1011 int len; 1037 int len;
1012 c = STRING_CHAR_AND_LENGTH (p, maxlen, len); 1038 c = string_char_and_length (p, maxlen, &len);
1013 } 1039 }
1014 else 1040 else
1015 c = *p; 1041 c = *p;
@@ -1955,7 +1981,7 @@ face_before_or_after_it_pos (it, before_p)
1955 int rest = STRING_BYTES (XSTRING (it->string)) - BYTEPOS (pos); 1981 int rest = STRING_BYTES (XSTRING (it->string)) - BYTEPOS (pos);
1956 int c, len, charset; 1982 int c, len, charset;
1957 1983
1958 c = STRING_CHAR_AND_LENGTH (p, rest, len); 1984 c = string_char_and_length (p, rest, &len);
1959 charset = CHAR_CHARSET (c); 1985 charset = CHAR_CHARSET (c);
1960 if (charset != CHARSET_ASCII) 1986 if (charset != CHARSET_ASCII)
1961 face_id = FACE_FOR_CHARSET (it->f, face_id, charset); 1987 face_id = FACE_FOR_CHARSET (it->f, face_id, charset);
@@ -3599,7 +3625,7 @@ next_element_from_string (it)
3599 - IT_STRING_BYTEPOS (*it)); 3625 - IT_STRING_BYTEPOS (*it));
3600 unsigned char *s = (XSTRING (it->string)->data 3626 unsigned char *s = (XSTRING (it->string)->data
3601 + IT_STRING_BYTEPOS (*it)); 3627 + IT_STRING_BYTEPOS (*it));
3602 it->c = STRING_CHAR_AND_LENGTH (s, remaining, it->len); 3628 it->c = string_char_and_length (s, remaining, &it->len);
3603 } 3629 }
3604 else 3630 else
3605 { 3631 {
@@ -3630,7 +3656,7 @@ next_element_from_string (it)
3630 - IT_STRING_BYTEPOS (*it)); 3656 - IT_STRING_BYTEPOS (*it));
3631 unsigned char *s = (XSTRING (it->string)->data 3657 unsigned char *s = (XSTRING (it->string)->data
3632 + IT_STRING_BYTEPOS (*it)); 3658 + IT_STRING_BYTEPOS (*it));
3633 it->c = STRING_CHAR_AND_LENGTH (s, maxlen, it->len); 3659 it->c = string_char_and_length (s, maxlen, &it->len);
3634 } 3660 }
3635 else 3661 else
3636 { 3662 {
@@ -3688,8 +3714,8 @@ next_element_from_c_string (it)
3688 performance problem because there is no noticeable performance 3714 performance problem because there is no noticeable performance
3689 difference between Emacs running in unibyte or multibyte mode. */ 3715 difference between Emacs running in unibyte or multibyte mode. */
3690 int maxlen = strlen (it->s) - IT_BYTEPOS (*it); 3716 int maxlen = strlen (it->s) - IT_BYTEPOS (*it);
3691 it->c = STRING_CHAR_AND_LENGTH (it->s + IT_BYTEPOS (*it), 3717 it->c = string_char_and_length (it->s + IT_BYTEPOS (*it),
3692 maxlen, it->len); 3718 maxlen, &it->len);
3693 } 3719 }
3694 else 3720 else
3695 it->c = it->s[IT_BYTEPOS (*it)], it->len = 1; 3721 it->c = it->s[IT_BYTEPOS (*it)], it->len = 1;
@@ -3826,7 +3852,7 @@ next_element_from_buffer (it)
3826 { 3852 {
3827 int maxlen = ((IT_BYTEPOS (*it) >= GPT_BYTE ? ZV_BYTE : GPT_BYTE) 3853 int maxlen = ((IT_BYTEPOS (*it) >= GPT_BYTE ? ZV_BYTE : GPT_BYTE)
3828 - IT_BYTEPOS (*it)); 3854 - IT_BYTEPOS (*it));
3829 it->c = STRING_CHAR_AND_LENGTH (p, maxlen, it->len); 3855 it->c = string_char_and_length (p, maxlen, &it->len);
3830 } 3856 }
3831 else 3857 else
3832 it->c = *p, it->len = 1; 3858 it->c = *p, it->len = 1;
@@ -4604,7 +4630,7 @@ message_dolog (m, len, nlflag, multibyte)
4604 for the *Message* buffer. */ 4630 for the *Message* buffer. */
4605 for (i = 0; i < len; i += nbytes) 4631 for (i = 0; i < len; i += nbytes)
4606 { 4632 {
4607 c = STRING_CHAR_AND_LENGTH (m + i, len - i, nbytes); 4633 c = string_char_and_length (m + i, len - i, &nbytes);
4608 work[0] = (SINGLE_BYTE_CHAR_P (c) 4634 work[0] = (SINGLE_BYTE_CHAR_P (c)
4609 ? c 4635 ? c
4610 : multibyte_char_to_unibyte (c, Qnil)); 4636 : multibyte_char_to_unibyte (c, Qnil));
@@ -9773,7 +9799,7 @@ get_overlay_arrow_glyph_row (w)
9773 9799
9774 /* Get the next character. */ 9800 /* Get the next character. */
9775 if (multibyte_p) 9801 if (multibyte_p)
9776 it.c = STRING_CHAR_AND_LENGTH (p, arrow_len, it.len); 9802 it.c = string_char_and_length (p, arrow_len, &it.len);
9777 else 9803 else
9778 it.c = *p, it.len = 1; 9804 it.c = *p, it.len = 1;
9779 p += it.len; 9805 p += it.len;