[Groonga-commit] ranguba/rroonga at f22a8ef [master] Support Normalizer.normalize("")

Back to archive index

Kouhei Sutou null+****@clear*****
Sun Mar 22 17:47:31 JST 2015


Kouhei Sutou	2015-03-22 17:47:31 +0900 (Sun, 22 Mar 2015)

  New Revision: f22a8efb850eb334502f5f147131b863c96cae74
  https://github.com/ranguba/rroonga/commit/f22a8efb850eb334502f5f147131b863c96cae74

  Message:
    Support Normalizer.normalize("")
    
    GitHub: fix #55
    
    Reported by Tasuku SUENAGA. Thanks!!!

  Modified files:
    ext/groonga/rb-grn-normalizer.c
    test/test-normalizer.rb

  Modified: ext/groonga/rb-grn-normalizer.c (+8 -1)
===================================================================
--- ext/groonga/rb-grn-normalizer.c    2015-03-22 17:45:45 +0900 (c4138f7)
+++ ext/groonga/rb-grn-normalizer.c    2015-03-22 17:47:31 +0900 (948e3ce)
@@ -1,6 +1,6 @@
 /* -*- coding: utf-8; mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /*
-  Copyright (C) 2012  Kouhei Sutou <kou �� clear-code.com>
+  Copyright (C) 2012-2015  Kouhei Sutou <kou �� clear-code.com>
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -73,6 +73,10 @@ rb_grn_normalizer_s_normalize (int argc, VALUE *argv, VALUE klass)
 
     context = rb_grn_context_ensure(&rb_context);
     rb_encoded_string = rb_grn_context_rb_string_encode(context, rb_string);
+    if (RSTRING_LEN(rb_encoded_string) == 0) {
+        return rb_grn_context_rb_string_new(context, "", 0);
+    }
+
     if (NIL_P(rb_remove_blank_p)) {
         rb_remove_blank_p = Qtrue;
     }
@@ -91,6 +95,9 @@ rb_grn_normalizer_s_normalize (int argc, VALUE *argv, VALUE klass)
                                  normalizer,
                                  flags);
     rb_grn_context_check(context, argv[0]);
+    if (!grn_string) {
+        return Qnil;
+    }
     grn_string_get_normalized(context, grn_string,
                               &normalized_string, &normalized_string_length,
                               NULL);

  Modified: test/test-normalizer.rb (+4 -0)
===================================================================
--- test/test-normalizer.rb    2015-03-22 17:45:45 +0900 (3224023)
+++ test/test-normalizer.rb    2015-03-22 17:47:31 +0900 (e8aeb90)
@@ -50,5 +50,9 @@ class NormalizerTest < Test::Unit::TestCase
     def test_tilda
       assert_equal("~~~", Groonga::Normalizer.normalize("~~〜"))
     end
+
+    def test_empty
+      assert_equal("", Groonga::Normalizer.normalize(""))
+    end
   end
 end
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index