aboutsummaryrefslogtreecommitdiffstats
path: root/ext/nkf/nkf.c
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-03-27 13:28:15 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-03-27 13:28:15 +0000
commitbb1e80fd4efe138b0083e6aea7b26a23bddda2f7 (patch)
tree8e26253276b8c2a0d4f260fef00c2e2a470addb8 /ext/nkf/nkf.c
parent15c3ddd0ff4a866fc4850b67eb673bedf6611c1d (diff)
downloadruby-bb1e80fd4efe138b0083e6aea7b26a23bddda2f7.tar.gz
* ext/nkf/nkf-utf8/{nkf.c, utf8tbl.c, config.h}: imported nkf 2.0.6.
* Add --ic / --oc option and mapping tables. * Add fallback option. * Add --no-best-fit-chars option. * Fix some bugs. * ext/nkf/nkf.c (nkf_split_options): added for parse option string. * ext/nkf/lib/kconv.rb (Kconv.to*): add -m0. Note that Kconv.to* still imply -X. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@10055 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/nkf/nkf.c')
-rw-r--r--ext/nkf/nkf.c52
1 files changed, 51 insertions, 1 deletions
diff --git a/ext/nkf/nkf.c b/ext/nkf/nkf.c
index f03a858c64..8eb92b6cd6 100644
--- a/ext/nkf/nkf.c
+++ b/ext/nkf/nkf.c
@@ -78,6 +78,54 @@ rb_nkf_putchar(c)
#include "nkf-utf8/utf8tbl.c"
#include "nkf-utf8/nkf.c"
+int nkf_split_options(arg)
+ const char* arg;
+{
+ int count = 0;
+ char option[256];
+ int i = 0, j = 0;
+ int is_escaped = FALSE;
+ int is_single_quoted = FALSE;
+ int is_double_quoted = FALSE;
+ for(i = 0; arg[i]; i++){
+ if(j == 255){
+ return -1;
+ }else if(is_single_quoted){
+ if(arg[i] == '\''){
+ is_single_quoted = FALSE;
+ }else{
+ option[j++] = arg[i];
+ }
+ }else if(is_escaped){
+ is_escaped = FALSE;
+ option[j++] = arg[i];
+ }else if(arg[i] == '\\'){
+ is_escaped = TRUE;
+ }else if(is_double_quoted){
+ if(arg[i] == '"'){
+ is_double_quoted = FALSE;
+ }else{
+ option[j++] = arg[i];
+ }
+ }else if(arg[i] == '\''){
+ is_single_quoted = TRUE;
+ }else if(arg[i] == '"'){
+ is_double_quoted = TRUE;
+ }else if(arg[i] == ' '){
+ option[j] = '\0';
+ options(option);
+ j = 0;
+ }else{
+ option[j++] = arg[i];
+ }
+ }
+ if(j){
+ option[j] = '\0';
+ options(option);
+ }
+ return count;
+}
+
/*
* call-seq:
* NKF.nkf(opt, str) -> string
@@ -104,7 +152,7 @@ rb_nkf_kconv(obj, opt, src)
StringValue(opt);
opt_ptr = RSTRING(opt)->ptr;
opt_end = opt_ptr + RSTRING(opt)->len;
- options(opt_ptr);
+ nkf_split_options(opt_ptr);
incsize = INCSIZE;
@@ -565,7 +613,9 @@ rb_nkf_guess2(obj, src)
void
Init_nkf()
{
+ /* hoge */
VALUE mKconv = rb_define_module("NKF");
+ /* hoge */
rb_define_module_function(mKconv, "nkf", rb_nkf_kconv, 2);
rb_define_module_function(mKconv, "guess1", rb_nkf_guess1, 1);