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

ruby-changes:3313

From: ko1@a...
Date: 31 Dec 2007 06:08:48 +0900
Subject: [ruby-changes:3313] nobu - Ruby:r14806 (trunk): * include/ruby/encoding.h (rb_enc_sprintf, rb_enc_vsprintf): prototyped.

nobu	2007-12-31 06:08:36 +0900 (Mon, 31 Dec 2007)

  New Revision: 14806

  Modified files:
    trunk/ChangeLog
    trunk/include/ruby/encoding.h
    trunk/sprintf.c

  Log:
    * include/ruby/encoding.h (rb_enc_sprintf, rb_enc_vsprintf): prototyped.
    
    * sprintf.c (rb_enc_sprintf, rb_enc_vsprintf): new functions to format
      arguments with encoding.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=14806&r2=14805
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/include/ruby/encoding.h?r1=14806&r2=14805
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/sprintf.c?r1=14806&r2=14805

Index: include/ruby/encoding.h
===================================================================
--- include/ruby/encoding.h	(revision 14805)
+++ include/ruby/encoding.h	(revision 14806)
@@ -13,6 +13,11 @@
 #ifndef RUBY_ENCODING_H
 #define RUBY_ENCODING_H 1
 
+#ifdef HAVE_STDARG_PROTOTYPES
+# include <stdarg.h>
+#else
+# include <varargs.h>
+#endif
 #include "ruby/oniguruma.h"
 
 #define ENCODING_INLINE_MAX 1023
@@ -54,6 +59,8 @@
 void rb_enc_copy(VALUE dst, VALUE src);
 
 VALUE rb_enc_str_new(const char*, long len, rb_encoding*);
+PRINTF_ARGS(VALUE rb_enc_sprintf(rb_encoding *, const char*, ...), 2, 3);
+VALUE rb_enc_vsprintf(rb_encoding *, const char*, va_list);
 long rb_enc_strlen(const char*, const char*, rb_encoding*);
 char* rb_enc_nth(const char*, const char*, int, rb_encoding*);
 VALUE rb_obj_encoding(VALUE);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 14805)
+++ ChangeLog	(revision 14806)
@@ -1,3 +1,10 @@
+Mon Dec 31 06:08:34 2007  Nobuyoshi Nakada  <nobu@r...>
+
+	* include/ruby/encoding.h (rb_enc_sprintf, rb_enc_vsprintf): prototyped.
+
+	* sprintf.c (rb_enc_sprintf, rb_enc_vsprintf): new functions to format
+	  arguments with encoding.
+
 Sun Dec 30 23:48:00 2007  NAKAMURA Usaku  <usa@r...>
 
 	* golf_prelude.rb (String#/): define / as split, as association of
Index: sprintf.c
===================================================================
--- sprintf.c	(revision 14805)
+++ sprintf.c	(revision 14806)
@@ -467,18 +467,14 @@
 		    if (slen < 0) {
 			rb_raise(rb_eArgError, "invalid mbstring sequence");
 		    }
-		}
-		if (flags&FPREC) {
-		    if (prec < slen) {
+		    if ((flags&FPREC) && (prec < slen)) {
 			char *p = rb_enc_nth(RSTRING_PTR(str), RSTRING_END(str),
 					     prec, enc);
 			slen = prec;
 			len = p - RSTRING_PTR(str);
 		    }
-		}
-		/* need to adjust multi-byte string pos */
-		if (flags&FWIDTH) {
-		    if (width > slen) {
+		    /* need to adjust multi-byte string pos */
+		    if ((flags&FWIDTH) && (width > slen)) {
 			width -= slen;
 			if (!(flags&FMINUS)) {
 			    CHECK(width);
@@ -925,7 +921,7 @@
 }
 
 VALUE
-rb_vsprintf(const char *fmt, va_list ap)
+rb_enc_vsprintf(rb_encoding *enc, const char *fmt, va_list ap)
 {
     rb_printf_buffer f;
     VALUE result;
@@ -934,6 +930,7 @@
     f._bf._size = 0;
     f._w = 120;
     result = rb_str_buf_new(f._w);
+    if (enc) rb_enc_associate(result, enc);
     f._bf._base = (unsigned char *)result;
     f._p = (unsigned char *)RSTRING_PTR(result);
     RBASIC(result)->klass = 0;
@@ -946,6 +943,25 @@
 }
 
 VALUE
+rb_enc_sprintf(rb_encoding *enc, const char *format, ...)
+{
+    VALUE result;
+    va_list ap;
+
+    va_start(ap, format);
+    result = rb_enc_vsprintf(enc, format, ap);
+    va_end(ap);
+
+    return result;
+}
+
+VALUE
+rb_vsprintf(const char *fmt, va_list ap)
+{
+    return rb_enc_vsprintf(NULL, fmt, ap);
+}
+
+VALUE
 rb_sprintf(const char *format, ...)
 {
     VALUE result;

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

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