[前][次][番号順一覧][スレッド一覧]

ruby-changes:3336

From: ko1@a...
Date: 1 Jan 2008 21:24:27 +0900
Subject: [ruby-changes:3336] akr - Ruby:r14829 (trunk): * include/ruby/encoding.h (rb_isascii): defined.

akr	2008-01-01 21:24:04 +0900 (Tue, 01 Jan 2008)

  New Revision: 14829

  Modified files:
    trunk/ChangeLog
    trunk/dir.c
    trunk/encoding.c
    trunk/ext/readline/readline.c
    trunk/file.c
    trunk/hash.c
    trunk/include/ruby/encoding.h
    trunk/include/ruby/ruby.h
    trunk/include/ruby/st.h
    trunk/process.c
    trunk/ruby.c
    trunk/st.c
    trunk/time.c
    trunk/transcode.c

  Log:
    * include/ruby/encoding.h (rb_isascii): defined.
      (rb_isalnum): ditto.
      (rb_isalpha): ditto.
      (rb_isblank): ditto.
      (rb_iscntrl): ditto.
      (rb_isdigit): ditto.
      (rb_isgraph): ditto.
      (rb_islower): ditto.
      (rb_isprint): ditto.
      (rb_ispunct): ditto.
      (rb_isspace): ditto.
      (rb_isupper): ditto.
      (rb_isxdigit): ditto.
      (rb_tolower): ditto.
      (rb_toupper): ditto.
    
    * include/ruby/st.h (st_strcasecmp): declared.
      (st_strncasecmp): ditto.
    
    * st.c (type_strcasehash): use st_strcasecmp instead of strcasecmp.
      (st_strcasecmp): defined.
      (st_strncasecmp): ditto.
    
    * include/ruby/ruby.h: include include/ruby/encoding.h.
      (ISASCII): use rb_isascii.
      (ISPRINT): use rb_isprint.
      (ISSPACE): use rb_isspace.
      (ISUPPER): use rb_isupper.
      (ISLOWER): use rb_islower.
      (ISALNUM): use rb_isalnum.
      (ISALPHA): use rb_isalpha.
      (ISDIGIT): use rb_isdigit.
      (ISXDIGIT): use rb_isxdigit.
      (TOUPPER): defined.
      (TOLOWER): ditto.
      (STRCASECMP): ditto.
      (STRNCASECMP): ditto.
    
    * dir.c, encoding.c, file.c, hash.c, process.c, ruby.c, time.c,
      transcode.c, ext/readline/readline.c: use locale insensitive
      functions.  [ruby-core:14662]


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/time.c?r1=14829&r2=14828&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/include/ruby/ruby.h?r1=14829&r2=14828&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/hash.c?r1=14829&r2=14828&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/file.c?r1=14829&r2=14828&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ruby.c?r1=14829&r2=14828&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/include/ruby/st.h?r1=14829&r2=14828&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=14829&r2=14828&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/transcode.c?r1=14829&r2=14828&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/include/ruby/encoding.h?r1=14829&r2=14828&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ext/readline/readline.c?r1=14829&r2=14828&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/encoding.c?r1=14829&r2=14828&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/dir.c?r1=14829&r2=14828&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/process.c?r1=14829&r2=14828&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/st.c?r1=14829&r2=14828&diff_format=u

Index: encoding.c
===================================================================
--- encoding.c	(revision 14828)
+++ encoding.c	(revision 14829)
@@ -173,7 +173,7 @@
 
     if (index >= 0) {
 	rb_encoding *oldenc = rb_enc_from_index(index);
-	if (strcasecmp(name, rb_enc_name(oldenc))) {
+	if (STRCASECMP(name, rb_enc_name(oldenc))) {
 	    st_data_t key = (st_data_t)name, alias;
 	    st_delete(enc_table_alias, &key, &alias);
 	    index = enc_register(name, encoding);
@@ -341,7 +341,7 @@
 	    if (i < ENCODING_INLINE_MAX - 1) i = ENCODING_INLINE_MAX - 1;
 	    continue;
 	}
-	if (strcasecmp(name, enc_table[i].name) == 0) {
+	if (STRCASECMP(name, enc_table[i].name) == 0) {
 	    return i;
 	}
     }
@@ -368,7 +368,7 @@
 	char *s = RSTRING_PTR(enclib) + 4, *e = RSTRING_END(enclib);
 	while (s < e) {
 	    if (!ISALNUM(*s)) *s = '_';
-	    else if (ISUPPER(*s)) *s = tolower(*s);
+	    else if (ISUPPER(*s)) *s = TOLOWER(*s);
 	    ++s;
 	}
 	OBJ_FREEZE(enclib);
Index: time.c
===================================================================
--- time.c	(revision 14828)
+++ time.c	(revision 14829)
@@ -419,7 +419,7 @@
 	    tm->tm_mon = -1;
 	    for (i=0; i<12; i++) {
 		if (RSTRING_LEN(s) == 3 &&
-		    strcasecmp(months[i], RSTRING_PTR(v[1])) == 0) {
+		    STRCASECMP(months[i], RSTRING_PTR(v[1])) == 0) {
 		    tm->tm_mon = i;
 		    break;
 		}
Index: include/ruby/ruby.h
===================================================================
--- include/ruby/ruby.h	(revision 14828)
+++ include/ruby/ruby.h	(revision 14829)
@@ -63,20 +63,6 @@
 
 #include "defines.h"
 
-/* need to include <ctype.h> to use these macros */
-#ifndef ISPRINT
-#define ISASCII(c) isascii((int)(unsigned char)(c))
-#undef ISPRINT
-#define ISPRINT(c) (ISASCII(c) && isprint((int)(unsigned char)(c)))
-#define ISSPACE(c) (ISASCII(c) && isspace((int)(unsigned char)(c)))
-#define ISUPPER(c) (ISASCII(c) && isupper((int)(unsigned char)(c)))
-#define ISLOWER(c) (ISASCII(c) && islower((int)(unsigned char)(c)))
-#define ISALNUM(c) (ISASCII(c) && isalnum((int)(unsigned char)(c)))
-#define ISALPHA(c) (ISASCII(c) && isalpha((int)(unsigned char)(c)))
-#define ISDIGIT(c) (ISASCII(c) && isdigit((int)(unsigned char)(c)))
-#define ISXDIGIT(c) (ISASCII(c) && isxdigit((int)(unsigned char)(c)))
-#endif
-
 #if defined(HAVE_ALLOCA_H)
 #include <alloca.h>
 #else
@@ -982,4 +968,22 @@
 }  /* extern "C" { */
 #endif
 
+#include "encoding.h"
+#ifndef ISPRINT
+#define ISASCII(c) rb_isascii((int)(unsigned char)(c))
+#undef ISPRINT
+#define ISPRINT(c) (ISASCII(c) && rb_isprint((int)(unsigned char)(c)))
+#define ISSPACE(c) (ISASCII(c) && rb_isspace((int)(unsigned char)(c)))
+#define ISUPPER(c) (ISASCII(c) && rb_isupper((int)(unsigned char)(c)))
+#define ISLOWER(c) (ISASCII(c) && rb_islower((int)(unsigned char)(c)))
+#define ISALNUM(c) (ISASCII(c) && rb_isalnum((int)(unsigned char)(c)))
+#define ISALPHA(c) (ISASCII(c) && rb_isalpha((int)(unsigned char)(c)))
+#define ISDIGIT(c) (ISASCII(c) && rb_isdigit((int)(unsigned char)(c)))
+#define ISXDIGIT(c) (ISASCII(c) && rb_isxdigit((int)(unsigned char)(c)))
+#endif
+#define TOUPPER(c) (rb_toupper((int)(unsigned char)(c)))
+#define TOLOWER(c) (rb_tolower((int)(unsigned char)(c)))
+#define STRCASECMP(s1, s2) (st_strcasecmp(s1, s2))
+#define STRNCASECMP(s1, s2, n) (st_strncasecmp(s1, s2, n))
+
 #endif /* RUBY_H */
Index: include/ruby/encoding.h
===================================================================
--- include/ruby/encoding.h	(revision 14828)
+++ include/ruby/encoding.h	(revision 14829)
@@ -136,4 +136,20 @@
 void rb_enc_set_default_external(VALUE encoding);
 VALUE rb_locale_charmap(VALUE klass);
 
+#define rb_isascii(c) ONIGENC_IS_CODE_ASCII(c)
+#define rb_isalnum(c) ONIGENC_IS_CODE_ALNUM(ONIG_ENCODING_ASCII, c)
+#define rb_isalpha(c) ONIGENC_IS_CODE_ALPHA(ONIG_ENCODING_ASCII, c)
+#define rb_isblank(c) ONIGENC_IS_CODE_BLANK(ONIG_ENCODING_ASCII, c)
+#define rb_iscntrl(c) ONIGENC_IS_CODE_CNTRL(ONIG_ENCODING_ASCII, c)
+#define rb_isdigit(c) ONIGENC_IS_CODE_DIGIT(ONIG_ENCODING_ASCII, c)
+#define rb_isgraph(c) ONIGENC_IS_CODE_GRAPH(ONIG_ENCODING_ASCII, c)
+#define rb_islower(c) ONIGENC_IS_CODE_LOWER(ONIG_ENCODING_ASCII, c)
+#define rb_isprint(c) ONIGENC_IS_CODE_PRINT(ONIG_ENCODING_ASCII, c)
+#define rb_ispunct(c) ONIGENC_IS_CODE_PUNCT(ONIG_ENCODING_ASCII, c)
+#define rb_isspace(c) ONIGENC_IS_CODE_SPACE(ONIG_ENCODING_ASCII, c)
+#define rb_isupper(c) ONIGENC_IS_CODE_UPPER(ONIG_ENCODING_ASCII, c)
+#define rb_isxdigit(c) ONIGENC_IS_CODE_XDIGIT(ONIG_ENCODING_ASCII, c)
+#define rb_tolower(c) rb_enc_tolower(c, ONIG_ENCODING_ASCII)
+#define rb_toupper(c) rb_enc_toupper(c, ONIG_ENCODING_ASCII)
+
 #endif /* RUBY_ENCODING_H */
Index: include/ruby/st.h
===================================================================
--- include/ruby/st.h	(revision 14828)
+++ include/ruby/st.h	(revision 14829)
@@ -87,6 +87,8 @@
 st_table *st_copy(st_table *);
 int st_numcmp(st_data_t, st_data_t);
 int st_numhash(st_data_t);
+int st_strcasecmp(const char *s1, const char *s2);
+int st_strncasecmp(const char *s1, const char *s2, size_t n);
 
 #if defined(__cplusplus)
 #if 0
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 14828)
+++ ChangeLog	(revision 14829)
@@ -1,3 +1,47 @@
+Tue Jan  1 21:11:33 2008  Tanaka Akira  <akr@f...>
+
+	* include/ruby/encoding.h (rb_isascii): defined.
+	  (rb_isalnum): ditto.
+	  (rb_isalpha): ditto.
+	  (rb_isblank): ditto.
+	  (rb_iscntrl): ditto.
+	  (rb_isdigit): ditto.
+	  (rb_isgraph): ditto.
+	  (rb_islower): ditto.
+	  (rb_isprint): ditto.
+	  (rb_ispunct): ditto.
+	  (rb_isspace): ditto.
+	  (rb_isupper): ditto.
+	  (rb_isxdigit): ditto.
+	  (rb_tolower): ditto.
+	  (rb_toupper): ditto.
+
+	* include/ruby/st.h (st_strcasecmp): declared.
+	  (st_strncasecmp): ditto.
+
+	* st.c (type_strcasehash): use st_strcasecmp instead of strcasecmp.
+	  (st_strcasecmp): defined.
+	  (st_strncasecmp): ditto.
+
+	* include/ruby/ruby.h: include include/ruby/encoding.h.
+	  (ISASCII): use rb_isascii.
+	  (ISPRINT): use rb_isprint.
+	  (ISSPACE): use rb_isspace.
+	  (ISUPPER): use rb_isupper.
+	  (ISLOWER): use rb_islower.
+	  (ISALNUM): use rb_isalnum.
+	  (ISALPHA): use rb_isalpha.
+	  (ISDIGIT): use rb_isdigit.
+	  (ISXDIGIT): use rb_isxdigit.
+	  (TOUPPER): defined.
+	  (TOLOWER): ditto.
+	  (STRCASECMP): ditto.
+	  (STRNCASECMP): ditto.
+
+	* dir.c, encoding.c, file.c, hash.c, process.c, ruby.c, time.c,
+	  transcode.c, ext/readline/readline.c: use locale insensitive
+	  functions.  [ruby-core:14662]
+
 Tue Jan  1 17:50:47 2008  Nobuyoshi Nakada  <nobu@r...>
 
 	* io.c (rb_io_mode_enc): encoding spec is not allowed in binary mode.
Index: st.c
===================================================================
--- st.c	(revision 14828)
+++ st.c	(revision 14829)
@@ -54,7 +54,7 @@
 
 static int strcasehash(const char *);
 static const struct st_hash_type type_strcasehash = {
-    strcasecmp,
+    st_strcasecmp,
     strcasehash,
 };
 
@@ -861,6 +861,60 @@
     return hval;
 }
 
+int
+st_strcasecmp(const char *s1, const char *s2)
+{
+    unsigned int c1, c2;
+
+    while (1) {
+        c1 = (unsigned char)*s1++;
+        c2 = (unsigned char)*s2++;
+        if (!c1) break;
+        if (!c2) break;
+        if ((unsigned int)(c1 - 'A') <= ('Z' - 'A')) c1 += 'a' - 'A';
+        if ((unsigned int)(c2 - 'A') <= ('Z' - 'A')) c2 += 'a' - 'A';
+        if (c1 != c2) {
+            if (c1 > c2)
+                return 1;
+            else
+                return -1;
+        }
+    }
+    if (c1 != '\0')
+        return 1;
+    if (c2 != '\0')
+        return -1;
+    return 0;
+}
+
+int
+st_strncasecmp(const char *s1, const char *s2, size_t n)
+{
+    unsigned int c1, c2;
+
+    while (n--) {
+        c1 = (unsigned char)*s1++;
+        c2 = (unsigned char)*s2++;
+        if (!c1) break;
+        if (!c2) break;
+        if ((unsigned int)(c1 - 'A') <= ('Z' - 'A')) c1 += 'a' - 'A';
+        if ((unsigned int)(c2 - 'A') <= ('Z' - 'A')) c2 += 'a' - 'A';
+        if (c1 != c2) {
+            if (c1 > c2)
+                return 1;
+            else
+                return -1;
+        }
+    }
+    if (n == 0)
+        return 0;
+    if (c1 != '\0')
+        return 1;
+    if (c2 != '\0')
+        return -1;
+    return 0;
+}
+
 static int
 strcasehash(register const char *string)
 {
Index: dir.c
===================================================================
--- dir.c	(revision 14828)
+++ dir.c	(revision 14829)
@@ -88,7 +88,7 @@
 #define FNM_NOMATCH	1
 #define FNM_ERROR	2
 
-#define downcase(c) (nocase && ISUPPER(c) ? tolower(c) : (c))
+#define downcase(c) (nocase && ISUPPER(c) ? TOLOWER(c) : (c))
 #define compare(c1, c2) (((unsigned char)(c1)) - ((unsigned char)(c2)))
 
 /* caution: in case *p == '\0'
Index: process.c
===================================================================
--- process.c	(revision 14828)
+++ process.c	(revision 14829)
@@ -990,7 +990,7 @@
 #endif
 	char *extension;
 
-	if ((extension = strrchr(prog, '.')) != NULL && strcasecmp(extension, ".bat") == 0) {
+	if ((extension = strrchr(prog, '.')) != NULL && STRCASECMP(extension, ".bat") == 0) {
 	    char **new_argv;
 	    char *p;
 	    int n;
@@ -1128,7 +1128,7 @@
 	return -1;
 
 #if defined(__human68k__)
-    if ((extension = strrchr(prog, '.')) != NULL && strcasecmp(extension, ".bat") == 0) {
+    if ((extension = strrchr(prog, '.')) != NULL && STRCASECMP(extension, ".bat") == 0) {
 	char **new_argv;
 	char *p;
 	int n;
Index: ext/readline/readline.c
===================================================================
--- ext/readline/readline.c	(revision 14828)
+++ ext/readline/readline.c	(revision 14829)
@@ -8,7 +8,6 @@
 #include "ruby/config.h"
 #include <errno.h>
 #include <stdio.h>
-#include <ctype.h>
 #include <string.h>
 #ifdef HAVE_READLINE_READLINE_H
 #include <readline/readline.h>
@@ -30,8 +29,6 @@
 
 static VALUE mReadline;
 
-#define TOLOWER(c) (isupper(c) ? tolower(c) : c)
-
 #define COMPLETION_PROC "completion_proc"
 #define COMPLETION_CASE_FOLD "completion_case_fold"
 static ID completion_proc, completion_case_fold;
Index: hash.c
===================================================================
--- hash.c	(revision 14828)
+++ hash.c	(revision 14829)
@@ -1781,7 +1781,7 @@
 
 	ruby_setenv(nam, 0);
 #ifdef ENV_IGNORECASE
-	if (strcasecmp(nam, PATH_ENV) == 0)
+	if (STRCASECMP(nam, PATH_ENV) == 0)
 #else
 	if (strcmp(nam, PATH_ENV) == 0)
 #endif
@@ -1817,7 +1817,7 @@
     env = getenv(nam);
     if (env) {
 #ifdef ENV_IGNORECASE
-	if (strcasecmp(nam, PATH_ENV) == 0 && !rb_env_path_tainted())
+	if (STRCASECMP(nam, PATH_ENV) == 0 && !rb_env_path_tainted())
 #else
 	if (strcmp(nam, PATH_ENV) == 0 && !rb_env_path_tainted())
 #endif
@@ -1859,7 +1859,7 @@
 	return if_none;
     }
 #ifdef ENV_IGNORECASE
-    if (strcasecmp(nam, PATH_ENV) == 0 && !rb_env_path_tainted())
+    if (STRCASECMP(nam, PATH_ENV) == 0 && !rb_env_path_tainted())
 #else
     if (strcmp(nam, PATH_ENV) == 0 && !rb_env_path_tainted())
 #endif
@@ -1893,7 +1893,7 @@
     for (i = 0; env[i]; i++) {
 	if (
 #ifdef ENV_IGNORECASE
-	    strncasecmp(env[i],nam,len) == 0
+	    STRNCASECMP(env[i],nam,len) == 0
 #else
 	    memcmp(env[i],nam,len) == 0
 #endif
@@ -2014,7 +2014,7 @@
 
     ruby_setenv(name, value);
 #ifdef ENV_IGNORECASE
-    if (strcasecmp(name, PATH_ENV) == 0) {
+    if (STRCASECMP(name, PATH_ENV) == 0) {
 #else
     if (strcmp(name, PATH_ENV) == 0) {
 #endif
Index: ruby.c
===================================================================
--- ruby.c	(revision 14828)
+++ ruby.c	(revision 14829)
@@ -184,7 +184,7 @@
 	    notfound = 1;
 	}
     }
-    if (!newp || l < oldl || strncasecmp(oldp, s, oldl) != 0) {
+    if (!newp || l < oldl || STRNCASECMP(oldp, s, oldl) != 0) {
 	return rb_str_new(s, l);
     }
     ret = rb_str_new(0, l + newl - oldl);
@@ -345,7 +345,7 @@
     p = strrchr(libpath, '/');
     if (p) {
 	*p = 0;
-	if (p - libpath > 3 && !strcasecmp(p - 4, "/bin")) {
+	if (p - libpath > 3 && !STRCASECMP(p - 4, "/bin")) {
 	    p -= 4;
 	    *p = 0;
 	}
@@ -1039,7 +1039,7 @@
 #if defined DOSISH || defined __CYGWIN__
 	{
 	    const char *ext = strrchr(fname, '.');
-	    if (ext && strcasecmp(ext, ".exe") == 0)
+	    if (ext && STRCASECMP(ext, ".exe") == 0)
 		mode |= O_BINARY;
 	}
 #endif
Index: file.c
===================================================================
--- file.c	(revision 14828)
+++ file.c	(revision 14829)
@@ -2532,10 +2532,6 @@
     buflen = RSTRING_LEN(result),\
     pend = p + buflen)
 
-#if !defined(TOLOWER)
-#define TOLOWER(c) (ISUPPER(c) ? tolower(c) : (c))
-#endif
-
 static int is_absolute_path(const char*);
 
 static VALUE
Index: transcode.c
===================================================================
--- transcode.c	(revision 14828)
+++ transcode.c	(revision 14829)
@@ -110,7 +110,7 @@
     rb_declare_transcoder("ISO-2022-JP", "UTF-8", "japanese");
 }
 
-#define encoding_equal(enc1, enc2) (strcasecmp(enc1, enc2) == 0)
+#define encoding_equal(enc1, enc2) (STRCASECMP(enc1, enc2) == 0)
 
 static rb_transcoder *
 transcode_dispatch(const char* from_encoding, const char* to_encoding)
@@ -297,7 +297,7 @@
 	    return to_encidx;
 	}
     }
-    if (strcasecmp(from_e, to_e) == 0) {
+    if (STRCASECMP(from_e, to_e) == 0) {
 	return -1;
     }
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml

[前][次][番号順一覧][スレッド一覧]