mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14806 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f7b12afff5
commit
3d0260cc94
3 changed files with 38 additions and 8 deletions
|
@ -1,3 +1,10 @@
|
|||
Mon Dec 31 06:08:34 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* 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@ruby-lang.org>
|
||||
|
||||
* golf_prelude.rb (String#/): define / as split, as association of
|
||||
|
|
|
@ -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_associate(VALUE, rb_encoding*);
|
|||
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);
|
||||
|
|
32
sprintf.c
32
sprintf.c
|
@ -467,18 +467,14 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
|
|||
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 @@ ruby__sfvwrite(register rb_printf_buffer *fp, register struct __suio *uio)
|
|||
}
|
||||
|
||||
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 @@ rb_vsprintf(const char *fmt, va_list ap)
|
|||
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;
|
||||
|
@ -945,6 +942,25 @@ rb_vsprintf(const char *fmt, va_list ap)
|
|||
return result;
|
||||
}
|
||||
|
||||
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, ...)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue