aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard M. Stallman1997-08-16 16:24:14 +0000
committerRichard M. Stallman1997-08-16 16:24:14 +0000
commit046b1f0395e6878e52ce549b37b6b808a1329fd2 (patch)
treec58b101af4e95ae954164df0f39123299e77d043 /src
parent0c57d6fdaea1a9412a485b21ab5fcc3b505edbc3 (diff)
downloademacs-046b1f0395e6878e52ce549b37b6b808a1329fd2.tar.gz
emacs-046b1f0395e6878e52ce549b37b6b808a1329fd2.zip
Many doc fixes.
(Fcount_chars_region): New function. (min, max): New macros.
Diffstat (limited to 'src')
-rw-r--r--src/charset.c77
1 files changed, 68 insertions, 9 deletions
diff --git a/src/charset.c b/src/charset.c
index 7e605dada1b..905efee017a 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -92,6 +92,9 @@ int n_cmpchars;
92unsigned char *_fetch_multibyte_char_p; 92unsigned char *_fetch_multibyte_char_p;
93int _fetch_multibyte_char_len; 93int _fetch_multibyte_char_len;
94 94
95#define min(X, Y) ((X) < (Y) ? (X) : (Y))
96#define max(X, Y) ((X) > (Y) ? (X) : (Y))
97
95/* Set STR a pointer to the multi-byte form of the character C. If C 98/* Set STR a pointer to the multi-byte form of the character C. If C
96 is not a composite character, the multi-byte form is set in WORKBUF 99 is not a composite character, the multi-byte form is set in WORKBUF
97 and STR points WORKBUF. The caller should allocate at least 4-byte 100 and STR points WORKBUF. The caller should allocate at least 4-byte
@@ -831,9 +834,9 @@ strwidth (str, len)
831DEFUN ("string-width", Fstring_width, Sstring_width, 1, 1, 0, 834DEFUN ("string-width", Fstring_width, Sstring_width, 1, 1, 0,
832 "Return width of STRING when displayed in the current buffer.\n\ 835 "Return width of STRING when displayed in the current buffer.\n\
833Width is measured by how many columns it occupies on the screen.\n\ 836Width is measured by how many columns it occupies on the screen.\n\
834When calculating width of a multi-byte character in STRING,\n\ 837When calculating width of a multibyte character in STRING,\n\
835 only the base leading-code is considered and the validity of\n\ 838only the base leading-code is considered; the validity of\n\
836 the following bytes are not checked.") 839the following bytes is not checked.")
837 (str) 840 (str)
838 Lisp_Object str; 841 Lisp_Object str;
839{ 842{
@@ -860,7 +863,11 @@ The returned value is 0 for left-to-right and 1 for right-to-left.")
860} 863}
861 864
862DEFUN ("chars-in-string", Fchars_in_string, Schars_in_string, 1, 1, 0, 865DEFUN ("chars-in-string", Fchars_in_string, Schars_in_string, 1, 1, 0,
863 "Return number of characters in STRING.") 866 "Return number of characters in STRING.\n\
867When using multibyte characters, this is not the necessarily same as\n\
868the length of STRING; the length counts a multibyte characters as\n\
869several bytes, but this function counts a multibyte character as one\n\
870character.")
864 (str) 871 (str)
865 Lisp_Object str; 872 Lisp_Object str;
866{ 873{
@@ -888,14 +895,65 @@ DEFUN ("chars-in-string", Fchars_in_string, Schars_in_string, 1, 1, 0,
888 return val; 895 return val;
889} 896}
890 897
898DEFUN ("count-chars-region", Fcount_chars_region, Scount_chars_region, 2, 2, 0,
899 "Return number of characters between BEG and END.\n\
900When using multibyte characters, this is not the necessarily same as\n\
901(- END BEG); that subtraction gives you the number of bytes, which\n\
902may be more than the number of characters.")
903 (beg, end)
904 Lisp_Object beg, end;
905{
906 int from, to, stop;
907 Lisp_Object val;
908 int chars = 0;
909 unsigned char *p, *endp;
910
911 validate_region (&beg, &end);
912
913 from = min (XFASTINT (beg), XFASTINT (end));
914 stop = to = max (XFASTINT (beg), XFASTINT (end));
915 p = POS_ADDR (from);
916 endp = POS_ADDR (stop);
917
918 if (from < GPT && GPT < to)
919 stop = GPT;
920
921 while (1)
922 {
923 if (p == endp)
924 {
925 if (stop == GPT)
926 {
927 p = POS_ADDR (stop);
928 stop = to;
929 endp = POS_ADDR (stop);
930 }
931 else
932 break;
933 }
934
935 if (*p == LEADING_CODE_COMPOSITION)
936 {
937 p++;
938 while (p < endp && ! CHAR_HEAD_P (p)) p++;
939 }
940 else
941 p += BYTES_BY_CHAR_HEAD (*p);
942
943 chars++;
944 }
945
946 return make_number (chars);
947}
948
891DEFUN ("char-boundary-p", Fchar_boundary_p, Schar_boundary_p, 1, 1, 0, 949DEFUN ("char-boundary-p", Fchar_boundary_p, Schar_boundary_p, 1, 1, 0,
892 "Return non-nil value if POS is at character boundary of multibyte form.\n\ 950 "Return non-nil value if POS is at character boundary of multibyte form.\n\
893The return value is:\n\ 951When the value is non-nil, it contains some additional information:\n\
894 0 if POS is at an ASCII character or at the end of range,\n\ 952 0 if POS is at an ASCII character or at the end of range,\n\
895 1 if POS is at a head of 2-byte length multi-byte form,\n\ 953 1 if POS is before a 2-byte length multi-byte form,\n\
896 2 if POS is at a head of 3-byte length multi-byte form,\n\ 954 2 if POS is before a 3-byte length multi-byte form,\n\
897 3 if POS is at a head of 4-byte length multi-byte form,\n\ 955 3 if POS is before a 4-byte length multi-byte form,\n\
898 4 if POS is at a head of multi-byte form of a composite character.\n\ 956 4 if POS is before a composite character.\n\
899If POS is out of range or not at character boundary, return NIL.") 957If POS is out of range or not at character boundary, return NIL.")
900 (pos) 958 (pos)
901 Lisp_Object pos; 959 Lisp_Object pos;
@@ -1496,6 +1554,7 @@ syms_of_charset ()
1496 defsubr (&Sstring_width); 1554 defsubr (&Sstring_width);
1497 defsubr (&Schar_direction); 1555 defsubr (&Schar_direction);
1498 defsubr (&Schars_in_string); 1556 defsubr (&Schars_in_string);
1557 defsubr (&Scount_chars_region);
1499 defsubr (&Schar_boundary_p); 1558 defsubr (&Schar_boundary_p);
1500 defsubr (&Sconcat_chars); 1559 defsubr (&Sconcat_chars);
1501 defsubr (&Scmpcharp); 1560 defsubr (&Scmpcharp);