Skip to content

Commit

Permalink
intern.h: rb_str_new_literal
Browse files Browse the repository at this point in the history
* include/ruby/intern.h (rb_str_new_literal): make ruby string
  from literal C-string.  incorporated from mruby.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47640 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Sep 19, 2014
1 parent abac848 commit eb0e3fe
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.EXT
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ rb_str_new_cstr(const char *ptr) ::
Creates a new Ruby string from a C string. This is equivalent to
rb_str_new(ptr, strlen(ptr)).

rb_str_new_literal(const char *ptr) ::

Creates a new Ruby string from a C string literal.

rb_tainted_str_new(const char *ptr, long len) ::

Creates a new tainted Ruby string. Strings from external data
Expand Down Expand Up @@ -226,16 +230,31 @@ rb_enc_str_new_cstr(const char *ptr, rb_encoding *enc) ::

Creates a new Ruby string with the specified encoding.

rb_enc_str_new_literal(const char *ptr) ::

Creates a new Ruby string from a C string literal with the specified
encoding.

rb_usascii_str_new(const char *ptr, long len) ::
rb_usascii_str_new_cstr(const char *ptr) ::

Creates a new Ruby string with encoding US-ASCII.

rb_usascii_str_new_literal(const char *ptr) ::

Creates a new Ruby string from a C string literal with encoding
US-ASCII.

rb_utf8_str_new(const char *ptr, long len) ::
rb_utf8_str_new_cstr(const char *ptr) ::

Creates a new Ruby string with encoding UTF-8.

rb_utf8_str_new_literal(const char *ptr) ::

Creates a new Ruby string from a C string literal with encoding
UTF-8.

rb_str_resize(VALUE str, long len) ::

Resizes Ruby string to len bytes. If str is not modifiable, this
Expand Down
16 changes: 16 additions & 0 deletions README.EXT.ja
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ rb_str_new_cstr(const char *ptr)
Cの文字列からRubyの文字列を生成する.この関数の機能は
rb_str_new(ptr, strlen(ptr))と同等である.

rb_str_new_literal(const char *ptr)

Cのリテラル文字列からRubyの文字列を生成する.

rb_tainted_str_new(const char *ptr, long len)

汚染マークが付加された新しいRubyの文字列を生成する.外部
Expand Down Expand Up @@ -252,16 +256,28 @@ rb_enc_str_new_cstr(const char *ptr, rb_encoding *enc)

指定されたエンコーディングでRubyの文字列を生成する.

rb_enc_str_new_literal(const char *ptr)

Cのリテラル文字列から指定されたエンコーディングでRubyの文字列を生成する.

rb_usascii_str_new(const char *ptr, long len)
rb_usascii_str_new_cstr(const char *ptr)

エンコーディングがUS-ASCIIのRubyの文字列を生成する.

rb_usascii_str_new_literal(const char *ptr)

Cのリテラル文字列からエンコーディングがUS-ASCIIのRubyの文字列を生成する.

rb_utf8_str_new(const char *ptr, long len)
rb_utf8_str_new_cstr(const char *ptr)

エンコーディングがUTF-8のRubyの文字列を生成する.

rb_usascii_str_new_literal(const char *ptr)

Cのリテラル文字列からエンコーディングがUTF-8のRubyの文字列を生成する.

rb_str_resize(VALUE str, long len)

Rubyの文字列のサイズをlenバイトに変更する.strの長さは前
Expand Down
4 changes: 4 additions & 0 deletions include/ruby/intern.h
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,10 @@ VALUE rb_str_scrub(VALUE, VALUE);
rb_utf8_str_new_static((str), (long)strlen(str)) : \
rb_utf8_str_new_cstr(str); \
})
#define rb_str_new_literal(str) rb_str_new_static((str), sizeof(str)-1)
#define rb_usascii_str_new_literal(str) rb_usascii_str_new_static((str), sizeof(str)-1)
#define rb_utf8_str_new_literal(str) rb_utf8_str_new_static((str), sizeof(str)-1)
#define rb_enc_str_new_literal(str, enc) rb_enc_str_new_static((str), sizeof(str)-1, (enc))
#define rb_external_str_new_cstr(str) __extension__ ( \
{ \
(__builtin_constant_p(str)) ? \
Expand Down

0 comments on commit eb0e3fe

Please sign in to comment.