diff options
| author | Kenichi Handa | 2008-06-25 02:44:20 +0000 |
|---|---|---|
| committer | Kenichi Handa | 2008-06-25 02:44:20 +0000 |
| commit | 4aa40bb8081a302b266fd6c2c39e1c33d084edd9 (patch) | |
| tree | 3cbde5495cb217d52dbb891a77c2228854f82d17 /src | |
| parent | b4480f1678bbda4bea13cff29d79a13b18f1df9f (diff) | |
| download | emacs-4aa40bb8081a302b266fd6c2c39e1c33d084edd9.tar.gz emacs-4aa40bb8081a302b266fd6c2c39e1c33d084edd9.zip | |
(str_to_unibyte): New function.
Diffstat (limited to 'src')
| -rw-r--r-- | src/character.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/character.c b/src/character.c index 5e2a3590563..387b15a6680 100644 --- a/src/character.c +++ b/src/character.c | |||
| @@ -834,6 +834,38 @@ str_as_unibyte (str, bytes) | |||
| 834 | return (to - str); | 834 | return (to - str); |
| 835 | } | 835 | } |
| 836 | 836 | ||
| 837 | /* Convert eight-bit chars in SRC (in multibyte form) to the | ||
| 838 | corresponding byte and store in DST. CHARS is the number of | ||
| 839 | characters in SRC. The value is the number of bytes stored in DST. | ||
| 840 | Usually, the value is the same as CHARS, but is less than it if SRC | ||
| 841 | contains a non-ASCII, non-eight-bit characater. If ACCEPT_LATIN_1 | ||
| 842 | is nonzero, a Latin-1 character is accepted and converted to a byte | ||
| 843 | of that character code. */ | ||
| 844 | |||
| 845 | EMACS_INT | ||
| 846 | str_to_unibyte (src, dst, chars, accept_latin_1) | ||
| 847 | const unsigned char *src; | ||
| 848 | unsigned char *dst; | ||
| 849 | EMACS_INT chars; | ||
| 850 | int accept_latin_1; | ||
| 851 | { | ||
| 852 | EMACS_INT i; | ||
| 853 | |||
| 854 | for (i = 0; i < chars; i++) | ||
| 855 | { | ||
| 856 | int c = STRING_CHAR_ADVANCE (src); | ||
| 857 | |||
| 858 | if (CHAR_BYTE8_P (c)) | ||
| 859 | c = CHAR_TO_BYTE8 (c); | ||
| 860 | else if (! ASCII_CHAR_P (c) | ||
| 861 | && (! accept_latin_1 || c >= 0x100)) | ||
| 862 | return i; | ||
| 863 | *dst++ = c; | ||
| 864 | } | ||
| 865 | return i; | ||
| 866 | } | ||
| 867 | |||
| 868 | |||
| 837 | int | 869 | int |
| 838 | string_count_byte8 (string) | 870 | string_count_byte8 (string) |
| 839 | Lisp_Object string; | 871 | Lisp_Object string; |