Mercurial > emacs
comparison src/search.c @ 17102:82769113e12f
(skip_chars): If enable-multibyte-characters is nil,
don't handle multibyte characters.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Thu, 27 Feb 1997 06:50:46 +0000 |
parents | b14c67f044a6 |
children | 739e41eed8b6 |
comparison
equal
deleted
inserted
replaced
17101:436e2bd4efcc | 17102:82769113e12f |
---|---|
739 int *char_ranges | 739 int *char_ranges |
740 = (int *) alloca (XSTRING (string)->size * (sizeof (int)) * 2); | 740 = (int *) alloca (XSTRING (string)->size * (sizeof (int)) * 2); |
741 int n_char_ranges = 0; | 741 int n_char_ranges = 0; |
742 int negate = 0; | 742 int negate = 0; |
743 register int i; | 743 register int i; |
744 int multibyte = !NILP (current_buffer->enable_multibyte_characters); | |
744 | 745 |
745 CHECK_STRING (string, 0); | 746 CHECK_STRING (string, 0); |
746 | 747 |
747 if (NILP (lim)) | 748 if (NILP (lim)) |
748 XSETINT (lim, forwardp ? ZV : BEGV); | 749 XSETINT (lim, forwardp ? ZV : BEGV); |
772 Otherwise, handle backslashes and ranges specially. */ | 773 Otherwise, handle backslashes and ranges specially. */ |
773 | 774 |
774 while (p != pend) | 775 while (p != pend) |
775 { | 776 { |
776 c = *p; | 777 c = *p; |
777 ch = STRING_CHAR (p, pend - p); | 778 if (multibyte) |
778 p += BYTES_BY_CHAR_HEAD (*p); | 779 { |
780 ch = STRING_CHAR (p, pend - p); | |
781 p += BYTES_BY_CHAR_HEAD (*p); | |
782 } | |
783 else | |
784 { | |
785 ch = c; | |
786 p++; | |
787 } | |
779 if (syntaxp) | 788 if (syntaxp) |
780 fastmap[syntax_spec_code[c]] = 1; | 789 fastmap[syntax_spec_code[c]] = 1; |
781 else | 790 else |
782 { | 791 { |
783 if (c == '\\') | 792 if (c == '\\') |
803 ch2 = STRING_CHAR (p, pend - p); | 812 ch2 = STRING_CHAR (p, pend - p); |
804 if (ch <= ch2) | 813 if (ch <= ch2) |
805 char_ranges[n_char_ranges++] = ch, | 814 char_ranges[n_char_ranges++] = ch, |
806 char_ranges[n_char_ranges++] = ch2; | 815 char_ranges[n_char_ranges++] = ch2; |
807 } | 816 } |
808 p += BYTES_BY_CHAR_HEAD (*p); | 817 p += multibyte ? BYTES_BY_CHAR_HEAD (*p) : 1; |
809 } | 818 } |
810 else | 819 else |
811 { | 820 { |
812 fastmap[c] = 1; | 821 fastmap[c] = 1; |
813 if (!SINGLE_BYTE_CHAR_P (ch)) | 822 if (!SINGLE_BYTE_CHAR_P (ch)) |
823 harmless even if SYNTAXP is 1. */ | 832 harmless even if SYNTAXP is 1. */ |
824 | 833 |
825 if (negate) | 834 if (negate) |
826 for (i = 0; i < sizeof fastmap; i++) | 835 for (i = 0; i < sizeof fastmap; i++) |
827 { | 836 { |
828 if (!BASE_LEADING_CODE_P (i)) | 837 if (!multibyte || !BASE_LEADING_CODE_P (i)) |
829 fastmap[i] ^= 1; | 838 fastmap[i] ^= 1; |
830 else | 839 else |
831 fastmap[i] = 1; | 840 fastmap[i] = 1; |
832 } | 841 } |
833 | 842 |
838 immediate_quit = 1; | 847 immediate_quit = 1; |
839 if (syntaxp) | 848 if (syntaxp) |
840 { | 849 { |
841 if (forwardp) | 850 if (forwardp) |
842 { | 851 { |
843 while (pos < XINT (lim) | 852 if (multibyte) |
844 && fastmap[(int) SYNTAX (FETCH_CHAR (pos))]) | 853 while (pos < XINT (lim) |
845 INC_POS (pos); | 854 && fastmap[(int) SYNTAX (FETCH_CHAR (pos))]) |
855 INC_POS (pos); | |
856 else | |
857 while (pos < XINT (lim) | |
858 && fastmap[(int) SYNTAX (FETCH_BYTE (pos))]) | |
859 pos++; | |
846 } | 860 } |
847 else | 861 else |
848 { | 862 { |
849 while (pos > XINT (lim)) | 863 if (multibyte) |
850 { | 864 while (pos > XINT (lim)) |
851 int savepos = pos; | 865 { |
852 DEC_POS (pos); | 866 int savepos = pos; |
853 if (!fastmap[(int) SYNTAX (FETCH_CHAR (pos))]) | 867 DEC_POS (pos); |
854 { | 868 if (!fastmap[(int) SYNTAX (FETCH_CHAR (pos))]) |
855 pos = savepos; | 869 { |
856 break; | 870 pos = savepos; |
857 } | 871 break; |
858 } | 872 } |
873 } | |
874 else | |
875 while (pos > XINT (lim) | |
876 && fastmap[(int) SYNTAX (FETCH_BYTE (pos - 1))]) | |
877 pos--; | |
859 } | 878 } |
860 } | 879 } |
861 else | 880 else |
862 { | 881 { |
863 if (forwardp) | 882 if (forwardp) |
864 { | 883 { |
865 while (pos < XINT (lim) && fastmap[(c = FETCH_BYTE (pos))]) | 884 if (multibyte) |
866 { | 885 while (pos < XINT (lim) && fastmap[(c = FETCH_BYTE (pos))]) |
867 if (!BASE_LEADING_CODE_P (c)) | 886 { |
868 pos++; | 887 if (!BASE_LEADING_CODE_P (c)) |
869 else if (n_char_ranges) | 888 pos++; |
870 { | 889 else if (n_char_ranges) |
871 /* We much check CHAR_RANGES for a multibyte | 890 { |
872 character. */ | 891 /* We much check CHAR_RANGES for a multibyte |
873 ch = FETCH_MULTIBYTE_CHAR (pos); | 892 character. */ |
874 for (i = 0; i < n_char_ranges; i += 2) | 893 ch = FETCH_MULTIBYTE_CHAR (pos); |
875 if ((ch >= char_ranges[i] && ch <= char_ranges[i + 1])) | 894 for (i = 0; i < n_char_ranges; i += 2) |
895 if ((ch >= char_ranges[i] && ch <= char_ranges[i + 1])) | |
896 break; | |
897 if (!(negate ^ (i < n_char_ranges))) | |
876 break; | 898 break; |
877 if (!(negate ^ (i < n_char_ranges))) | 899 |
878 break; | 900 INC_POS (pos); |
879 | 901 } |
880 INC_POS (pos); | 902 else |
881 } | 903 { |
882 else | 904 if (!negate) break; |
883 { | 905 INC_POS (pos); |
884 if (!negate) break; | 906 } |
885 INC_POS (pos); | 907 } |
886 } | 908 else |
887 } | 909 while (pos < XINT (lim) && fastmap[FETCH_BYTE (pos)]) |
910 pos++; | |
888 } | 911 } |
889 else | 912 else |
890 { | 913 { |
891 while (pos > XINT (lim)) | 914 if (multibyte) |
892 { | 915 while (pos > XINT (lim)) |
893 int savepos = pos; | 916 { |
894 DEC_POS (pos); | 917 int savepos = pos; |
895 if (fastmap[(c = FETCH_BYTE (pos))]) | 918 DEC_POS (pos); |
896 { | 919 if (fastmap[(c = FETCH_BYTE (pos))]) |
897 if (!BASE_LEADING_CODE_P (c)) | 920 { |
898 ; | 921 if (!BASE_LEADING_CODE_P (c)) |
899 else if (n_char_ranges) | 922 ; |
900 { | 923 else if (n_char_ranges) |
901 /* We much check CHAR_RANGES for a multibyte | 924 { |
902 character. */ | 925 /* We much check CHAR_RANGES for a multibyte |
903 ch = FETCH_MULTIBYTE_CHAR (pos); | 926 character. */ |
904 for (i = 0; i < n_char_ranges; i += 2) | 927 ch = FETCH_MULTIBYTE_CHAR (pos); |
905 if (ch >= char_ranges[i] && ch <= char_ranges[i + 1]) | 928 for (i = 0; i < n_char_ranges; i += 2) |
906 break; | 929 if (ch >= char_ranges[i] && ch <= char_ranges[i + 1]) |
907 if (!(negate ^ (i < n_char_ranges))) | 930 break; |
931 if (!(negate ^ (i < n_char_ranges))) | |
932 { | |
933 pos = savepos; | |
934 break; | |
935 } | |
936 } | |
937 else | |
938 if (!negate) | |
908 { | 939 { |
909 pos = savepos; | 940 pos = savepos; |
910 break; | 941 break; |
911 } | 942 } |
912 } | 943 } |
913 else | 944 else |
914 if (!negate) | 945 { |
915 { | 946 pos = savepos; |
916 pos = savepos; | 947 break; |
917 break; | 948 } |
918 } | 949 } |
919 } | 950 else |
920 else | 951 while (pos > XINT (lim) && fastmap[FETCH_BYTE (pos - 1)]) |
921 { | 952 pos--; |
922 pos = savepos; | |
923 break; | |
924 } | |
925 } | |
926 } | 953 } |
927 } | 954 } |
955 if (multibyte | |
956 /* INC_POS or DEC_POS might have moved POS over LIM. */ | |
957 && (forwardp ? (pos > XINT (lim)) : (pos < XINT (lim)))) | |
958 pos = XINT (lim); | |
959 | |
928 SET_PT (pos); | 960 SET_PT (pos); |
929 immediate_quit = 0; | 961 immediate_quit = 0; |
930 | 962 |
931 return make_number (PT - start_point); | 963 return make_number (PT - start_point); |
932 } | 964 } |