diff options
author | Xavier Leroy <xavier.leroy@inria.fr> | 1999-05-15 15:08:11 +0000 |
---|---|---|
committer | Xavier Leroy <xavier.leroy@inria.fr> | 1999-05-15 15:08:11 +0000 |
commit | 2c5ab3494a0eb581f14bb4d0db15aff2c2bfa456 (patch) | |
tree | da9eb8b81b028605f0eef9dac1683b1d41bf31c7 /byterun/str.c | |
parent | 6205ef614e06ef54366ec70c6c2f60cd95dedb54 (diff) | |
download | ocaml-2c5ab3494a0eb581f14bb4d0db15aff2c2bfa456.tar.gz |
Utiliser isprint() plutot que notre emulation faiblarde
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@2366 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'byterun/str.c')
-rw-r--r-- | byterun/str.c | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/byterun/str.c b/byterun/str.c index 04f1aaf791..3370901497 100644 --- a/byterun/str.c +++ b/byterun/str.c @@ -14,10 +14,14 @@ /* Operations on strings */ #include <string.h> +#include <ctype.h> #include "alloc.h" #include "fail.h" #include "mlvalues.h" #include "misc.h" +#ifdef HAS_LOCALE +#include <locale.h> +#endif mlsize_t string_length(value s) { @@ -92,36 +96,31 @@ value fill_string(value s, value offset, value len, value init) /* ML */ return Val_unit; } -static unsigned char printable_chars_ascii[] = { /* 0x20-0x7E */ - 0, 0, 0, 0, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0 -}; -static unsigned char printable_chars_iso[] = { /* 0x20-0x7E 0xA1-0xFF */ - 0, 0, 0, 0, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, - 0, 0, 0, 0, 0xFE, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF -}; - value is_printable(value chr) /* ML */ { int c; - unsigned char * printable_chars; #ifdef _WIN32 - printable_chars = printable_chars_iso; + /* FIXME: is this necessary? Wouldn't isprint() do what we want? */ + static unsigned char printable_chars_iso[] = { /* 0x20-0x7E 0xA1-0xFF */ + 0, 0, 0, 0, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, + 0, 0, 0, 0, 0xFE, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF + }; + c = Int_val(chr); + return Val_bool(printable_chars_iso[c >> 3] & (1 << (c & 7))); #else - static int iso_charset = -1; - if (iso_charset == -1) { - char * lc_ctype = (char *) getenv("LC_CTYPE"); - iso_charset = (lc_ctype != 0 && strcmp(lc_ctype, "iso_8859_1") == 0); +#ifdef HAS_LOCALE + static int locale_is_set = 0; + if (! locale_is_set) { + setlocale(LC_CTYPE, ""); + locale_is_set = 1; } - printable_chars = iso_charset ? printable_chars_iso : printable_chars_ascii; #endif c = Int_val(chr); - return Val_bool(printable_chars[c >> 3] & (1 << (c & 7))); + return Val_bool(isprint(c)); +#endif } value bitvect_test(value bv, value n) /* ML */ |