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

ruby-changes:35543

From: nobu <ko1@a...>
Date: Thu, 18 Sep 2014 23:51:18 +0900 (JST)
Subject: [ruby-changes:35543] nobu:r47625 (trunk): string.c: UTF-8 string function

nobu	2014-09-18 23:51:08 +0900 (Thu, 18 Sep 2014)

  New Revision: 47625

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47625

  Log:
    string.c: UTF-8 string function
    
    * string.c (rb_utf8_str_new, rb_utf8_str_new_cstr): make UTF-8
      string.

  Modified files:
    trunk/include/ruby/intern.h
    trunk/string.c
Index: include/ruby/intern.h
===================================================================
--- include/ruby/intern.h	(revision 47624)
+++ include/ruby/intern.h	(revision 47625)
@@ -707,6 +707,8 @@ VALUE rb_str_buf_new2(const char*); https://github.com/ruby/ruby/blob/trunk/include/ruby/intern.h#L707
 VALUE rb_str_tmp_new(long);
 VALUE rb_usascii_str_new(const char*, long);
 VALUE rb_usascii_str_new_cstr(const char*);
+VALUE rb_utf8_str_new(const char*, long);
+VALUE rb_utf8_str_new_cstr(const char*);
 void rb_str_free(VALUE);
 void rb_str_shared_replace(VALUE, VALUE);
 VALUE rb_str_buf_append(VALUE, VALUE);
@@ -787,6 +789,12 @@ VALUE rb_str_scrub(VALUE, VALUE); https://github.com/ruby/ruby/blob/trunk/include/ruby/intern.h#L789
 	rb_usascii_str_new((str), (long)strlen(str)) : \
 	rb_usascii_str_new_cstr(str);	       \
 })
+#define rb_utf8_str_new_cstr(str) __extension__ ( \
+{						\
+    (__builtin_constant_p(str)) ?		\
+	rb_utf8_str_new((str), (long)strlen(str)) : \
+	rb_utf8_str_new_cstr(str);		\
+})
 #define rb_external_str_new_cstr(str) __extension__ ( \
 {						\
     (__builtin_constant_p(str)) ?		\
Index: string.c
===================================================================
--- string.c	(revision 47624)
+++ string.c	(revision 47625)
@@ -34,6 +34,7 @@ https://github.com/ruby/ruby/blob/trunk/string.c#L34
 #undef rb_str_new_cstr
 #undef rb_tainted_str_new_cstr
 #undef rb_usascii_str_new_cstr
+#undef rb_utf8_str_new_cstr
 #undef rb_enc_str_new_cstr
 #undef rb_external_str_new_cstr
 #undef rb_locale_str_new_cstr
@@ -589,6 +590,14 @@ rb_usascii_str_new(const char *ptr, long https://github.com/ruby/ruby/blob/trunk/string.c#L590
 }
 
 VALUE
+rb_utf8_str_new(const char *ptr, long len)
+{
+    VALUE str = str_new(rb_cString, ptr, len);
+    rb_enc_associate_index(str, rb_utf8_encindex());
+    return str;
+}
+
+VALUE
 rb_enc_str_new(const char *ptr, long len, rb_encoding *enc)
 {
     VALUE str;
@@ -615,6 +624,14 @@ rb_usascii_str_new_cstr(const char *ptr) https://github.com/ruby/ruby/blob/trunk/string.c#L624
     return str;
 }
 
+VALUE
+rb_utf8_str_new_cstr(const char *ptr)
+{
+    VALUE str = rb_str_new_cstr(ptr);
+    rb_enc_associate_index(str, rb_utf8_encindex());
+    return str;
+}
+
 VALUE
 rb_enc_str_new_cstr(const char *ptr, rb_encoding *enc)
 {

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

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