tre-ruby 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/ext/tre/tre.c +20 -8
- data/lib/tre-ruby.rb +2 -1
- data/test/test_tre-ruby.rb +47 -1
- metadata +11 -11
    
        data/VERSION
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            0.1. | 
| 1 | 
            +
            0.1.1
         | 
    
        data/ext/tre/tre.c
    CHANGED
    
    | @@ -1,4 +1,5 @@ | |
| 1 1 | 
             
            #include "ruby.h"
         | 
| 2 | 
            +
            #include "ruby/version.h"
         | 
| 2 3 | 
             
            #include "tre/tre.h"
         | 
| 3 4 |  | 
| 4 5 | 
             
            VALUE mTRE;
         | 
| @@ -81,6 +82,14 @@ tre_compile_regex(regex_t* preg, VALUE pattern, VALUE ignore_case, VALUE multi_l | |
| 81 82 | 
             
            	}
         | 
| 82 83 | 
             
            }
         | 
| 83 84 |  | 
| 85 | 
            +
            #if RUBY_VERSION_MAJOR == 1 && RUBY_VERSION_MINOR == 8
         | 
| 86 | 
            +
            	#define CHAR_LENGTH(string)       RSTRING_LEN(string)
         | 
| 87 | 
            +
            	#define BYTE_TO_CHAR(string, bo)  bo
         | 
| 88 | 
            +
            #else
         | 
| 89 | 
            +
            	#define CHAR_LENGTH(string)       NUM2LONG( rb_str_length(string) ) 
         | 
| 90 | 
            +
            	#define BYTE_TO_CHAR(string, bo)  rb_str_sublen(string, bo)
         | 
| 91 | 
            +
            #endif
         | 
| 92 | 
            +
             | 
| 84 93 | 
             
            static VALUE
         | 
| 85 94 | 
             
            tre_traverse(VALUE pattern, VALUE string, long char_offset, VALUE params,
         | 
| 86 95 | 
             
            		VALUE ignore_case, VALUE multi_line, int num_captures, VALUE repeat) {
         | 
| @@ -107,18 +116,19 @@ tre_traverse(VALUE pattern, VALUE string, long char_offset, VALUE params, | |
| 107 116 |  | 
| 108 117 | 
             
            	while (1) {
         | 
| 109 118 | 
             
            		// Get substring to start with
         | 
| 110 | 
            -
            		long  | 
| 111 | 
            -
            		if ( | 
| 112 | 
            -
            		string = rb_str_substr(string, char_offset,  | 
| 119 | 
            +
            		long char_len = CHAR_LENGTH(string) - char_offset;
         | 
| 120 | 
            +
            		if (char_len <= 0) break;
         | 
| 121 | 
            +
            		string = rb_str_substr(string, char_offset, char_len);
         | 
| 113 122 |  | 
| 114 | 
            -
            		int result = tre_reganexec(&preg, StringValuePtr(string),  | 
| 123 | 
            +
            		int result = tre_reganexec(&preg, StringValuePtr(string), 
         | 
| 124 | 
            +
            											RSTRING_LEN(string), &match, aparams, 0);
         | 
| 115 125 |  | 
| 116 126 | 
             
            		if (result == REG_NOMATCH) break;
         | 
| 117 127 |  | 
| 118 128 | 
             
            		// Fill in array with ranges
         | 
| 119 129 | 
             
            		VALUE subarr;
         | 
| 120 130 | 
             
            		if (match.nmatch == 1) 
         | 
| 121 | 
            -
            			subarr = arr;	//  | 
| 131 | 
            +
            			subarr = arr;	// Faking.. kind of.
         | 
| 122 132 | 
             
            		else {
         | 
| 123 133 | 
             
            			subarr = rb_ary_new();
         | 
| 124 134 | 
             
            			// rb_global_variable(&subarr);
         | 
| @@ -126,12 +136,14 @@ tre_traverse(VALUE pattern, VALUE string, long char_offset, VALUE params, | |
| 126 136 |  | 
| 127 137 | 
             
            		unsigned int i;
         | 
| 128 138 | 
             
            		for (i = 0; i < match.nmatch; ++i)
         | 
| 139 | 
            +
            			// No match
         | 
| 129 140 | 
             
            			if (match.pmatch[i].rm_so == -1)
         | 
| 130 141 | 
             
            				rb_ary_push(subarr, Qnil);
         | 
| 142 | 
            +
            			// Match => Range
         | 
| 131 143 | 
             
            			else {
         | 
| 132 144 | 
             
            				VALUE range = rb_range_new(
         | 
| 133 | 
            -
            						LONG2NUM( char_offset_acc +  | 
| 134 | 
            -
            						LONG2NUM( char_offset_acc +  | 
| 145 | 
            +
            						LONG2NUM( char_offset_acc + BYTE_TO_CHAR(string, match.pmatch[i].rm_so) ),
         | 
| 146 | 
            +
            						LONG2NUM( char_offset_acc + BYTE_TO_CHAR(string, match.pmatch[i].rm_eo) ),
         | 
| 135 147 | 
             
            						1);
         | 
| 136 148 | 
             
            				// rb_global_variable(&range);
         | 
| 137 149 |  | 
| @@ -143,7 +155,7 @@ tre_traverse(VALUE pattern, VALUE string, long char_offset, VALUE params, | |
| 143 155 | 
             
            		if (repeat == Qfalse)
         | 
| 144 156 | 
             
            			break;
         | 
| 145 157 | 
             
            		else {
         | 
| 146 | 
            -
            			char_offset =  | 
| 158 | 
            +
            			char_offset = BYTE_TO_CHAR(string, match.pmatch[0].rm_eo);
         | 
| 147 159 | 
             
            			if (char_offset == 0) char_offset = 1; // Weird case
         | 
| 148 160 | 
             
            			char_offset_acc += char_offset;
         | 
| 149 161 | 
             
            		}
         | 
    
        data/lib/tre-ruby.rb
    CHANGED
    
    | @@ -160,7 +160,8 @@ private | |
| 160 160 | 
             
            			opts &= ~Regexp::MULTILINE
         | 
| 161 161 | 
             
            			ret[:ignore_case] = (opts & Regexp::IGNORECASE) > 0
         | 
| 162 162 | 
             
            			opts &= ~Regexp::IGNORECASE
         | 
| 163 | 
            -
            			opts &= ~Regexp::FIXEDENCODING  | 
| 163 | 
            +
            			opts &= ~Regexp::FIXEDENCODING if 
         | 
| 164 | 
            +
            					Regexp.constants.map { |c| c.to_s }.include? "FIXEDENCODING"
         | 
| 164 165 | 
             
            			raise ArgumentError.new("Unsupported Regexp flag provided") if opts > 0
         | 
| 165 166 |  | 
| 166 167 | 
             
            			# Pessimistic estimation of the number of captures
         | 
    
        data/test/test_tre-ruby.rb
    CHANGED
    
    | @@ -76,7 +76,7 @@ class TestTRE < Test::Unit::TestCase | |
| 76 76 | 
             
            		assert_equal nil, TWISTER.aindex(/toult/i, 0, params)
         | 
| 77 77 |  | 
| 78 78 | 
             
            		# Frozen: cannot modify
         | 
| 79 | 
            -
            		assert_raise(RuntimeError) { params.max_err = 2 }
         | 
| 79 | 
            +
            		assert_raise(RUBY_VERSION =~ /^1.8/ ? TypeError : RuntimeError) { params.max_err = 2 }
         | 
| 80 80 |  | 
| 81 81 | 
             
            		# Warm AParams
         | 
| 82 82 | 
             
            		params = TRE::AParams.new
         | 
| @@ -176,6 +176,52 @@ class TestTRE < Test::Unit::TestCase | |
| 176 176 | 
             
            		assert_not_equal copy, TWISTER
         | 
| 177 177 | 
             
            	end
         | 
| 178 178 |  | 
| 179 | 
            +
            	def test_multibyte
         | 
| 180 | 
            +
            		$KCODE = 'u' if RUBY_VERSION =~ /^1.8/
         | 
| 181 | 
            +
            		lyric = "
         | 
| 182 | 
            +
            			사랑을 한다는 말은 못했어
         | 
| 183 | 
            +
            			어쨌거나 지금은 너무 늦어버렸어
         | 
| 184 | 
            +
            			그때 나는 무얼 하고 있었나
         | 
| 185 | 
            +
            			그 미소는 너무 아름다웠어
         | 
| 186 | 
            +
            			난 정말 그대 그대만을 좋아헀어
         | 
| 187 | 
            +
            			나에게 이런 슬픔 안겨 주는 그대여
         | 
| 188 | 
            +
            			제발 이별만은 말 하지 말아요
         | 
| 189 | 
            +
            			나에겐 오직 그대만이 전부였잖아
         | 
| 190 | 
            +
            			오 그대여 가지 마세요
         | 
| 191 | 
            +
            			나를 정말 떠나 가나요
         | 
| 192 | 
            +
            			오 그대여 가지 마세요
         | 
| 193 | 
            +
            			나는 지금 울잖아요
         | 
| 194 | 
            +
            			난 알아요
         | 
| 195 | 
            +
            			이 밤이 흐르면 YO!
         | 
| 196 | 
            +
            			그대 떠나는 모습 뒤로 하고
         | 
| 197 | 
            +
            			마지막 키스에 슬픈 마음
         | 
| 198 | 
            +
            			정말 떠나는가
         | 
| 199 | 
            +
            			사랑을 하고 싶어 너의 모든 향기
         | 
| 200 | 
            +
            			내 몸 속에 젖어 있는 너의 많은 숨결
         | 
| 201 | 
            +
            			그 미소 그 눈물 그 알 수 없는 마음 그대 마음
         | 
| 202 | 
            +
            			그리고 또 마음 그대 마음
         | 
| 203 | 
            +
            			그 어렵다는 편지는 쓰지 않아도 돼
         | 
| 204 | 
            +
            			너의 진실한 모습을 바라보고 있어요
         | 
| 205 | 
            +
            			아직도 마음속엔 내가 있나요
         | 
| 206 | 
            +
            			나는 그대의 영원한
         | 
| 207 | 
            +
            			난 정말 그대 그대만을 좋아했어
         | 
| 208 | 
            +
            			나에게 이런 슬픔 안겨주는 그대여
         | 
| 209 | 
            +
            			오 그대여 가지 마세요
         | 
| 210 | 
            +
            			나를 정말 떠나 가나요
         | 
| 211 | 
            +
            			오 그대여 가지 마세요
         | 
| 212 | 
            +
            			나는 지금 울잖아요
         | 
| 213 | 
            +
            			오 그대여 가지 마세요
         | 
| 214 | 
            +
            			나를 정말 떠나 가나요
         | 
| 215 | 
            +
            			오 그대여 가지 마세요
         | 
| 216 | 
            +
            			나는 지금 울잖아요"
         | 
| 217 | 
            +
            		srch = "오 그대여 가지 마세요"
         | 
| 218 | 
            +
            		assert_equal 6,
         | 
| 219 | 
            +
            			lyric.extend(TRE).ascan_r(/#{srch}/i, TRE.fuzziness(0)).length
         | 
| 220 | 
            +
            		assert_equal 6,
         | 
| 221 | 
            +
            			lyric.extend(TRE).ascan(/#{srch}/i, TRE.fuzziness(0)).length
         | 
| 222 | 
            +
            		assert lyric.extend(TRE).ascan(/#{srch}/i, TRE.fuzziness(0)).all? { |e| e == srch }
         | 
| 223 | 
            +
            	end
         | 
| 224 | 
            +
             | 
| 179 225 | 
             
            	TWISTER = TREString.new <<-EOF
         | 
| 180 226 | 
             
            		She sells sea shells by the sea shore.
         | 
| 181 227 | 
             
            		The shells she sells are surely seashells.
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: tre-ruby
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.1. | 
| 4 | 
            +
              version: 0.1.1
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| @@ -9,11 +9,11 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2011-04- | 
| 12 | 
            +
            date: 2011-04-20 00:00:00.000000000Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: bundler
         | 
| 16 | 
            -
              requirement: & | 
| 16 | 
            +
              requirement: &2156453820 !ruby/object:Gem::Requirement
         | 
| 17 17 | 
             
                none: false
         | 
| 18 18 | 
             
                requirements:
         | 
| 19 19 | 
             
                - - ~>
         | 
| @@ -21,10 +21,10 @@ dependencies: | |
| 21 21 | 
             
                    version: 1.0.0
         | 
| 22 22 | 
             
              type: :development
         | 
| 23 23 | 
             
              prerelease: false
         | 
| 24 | 
            -
              version_requirements: * | 
| 24 | 
            +
              version_requirements: *2156453820
         | 
| 25 25 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 26 26 | 
             
              name: jeweler
         | 
| 27 | 
            -
              requirement: & | 
| 27 | 
            +
              requirement: &2156452860 !ruby/object:Gem::Requirement
         | 
| 28 28 | 
             
                none: false
         | 
| 29 29 | 
             
                requirements:
         | 
| 30 30 | 
             
                - - ~>
         | 
| @@ -32,10 +32,10 @@ dependencies: | |
| 32 32 | 
             
                    version: 1.5.2
         | 
| 33 33 | 
             
              type: :development
         | 
| 34 34 | 
             
              prerelease: false
         | 
| 35 | 
            -
              version_requirements: * | 
| 35 | 
            +
              version_requirements: *2156452860
         | 
| 36 36 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 37 37 | 
             
              name: rcov
         | 
| 38 | 
            -
              requirement: & | 
| 38 | 
            +
              requirement: &2156451820 !ruby/object:Gem::Requirement
         | 
| 39 39 | 
             
                none: false
         | 
| 40 40 | 
             
                requirements:
         | 
| 41 41 | 
             
                - - ! '>='
         | 
| @@ -43,10 +43,10 @@ dependencies: | |
| 43 43 | 
             
                    version: '0'
         | 
| 44 44 | 
             
              type: :development
         | 
| 45 45 | 
             
              prerelease: false
         | 
| 46 | 
            -
              version_requirements: * | 
| 46 | 
            +
              version_requirements: *2156451820
         | 
| 47 47 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 48 48 | 
             
              name: rake-compiler
         | 
| 49 | 
            -
              requirement: & | 
| 49 | 
            +
              requirement: &2156450920 !ruby/object:Gem::Requirement
         | 
| 50 50 | 
             
                none: false
         | 
| 51 51 | 
             
                requirements:
         | 
| 52 52 | 
             
                - - ! '>='
         | 
| @@ -54,7 +54,7 @@ dependencies: | |
| 54 54 | 
             
                    version: 0.7.7
         | 
| 55 55 | 
             
              type: :development
         | 
| 56 56 | 
             
              prerelease: false
         | 
| 57 | 
            -
              version_requirements: * | 
| 57 | 
            +
              version_requirements: *2156450920
         | 
| 58 58 | 
             
            description: Ruby binding for TRE library. Provides interface for approximate regular
         | 
| 59 59 | 
             
              expression matching.
         | 
| 60 60 | 
             
            email: junegunn.c@gmail.com
         | 
| @@ -91,7 +91,7 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 91 91 | 
             
                  version: '0'
         | 
| 92 92 | 
             
                  segments:
         | 
| 93 93 | 
             
                  - 0
         | 
| 94 | 
            -
                  hash: - | 
| 94 | 
            +
                  hash: -2151247154818609627
         | 
| 95 95 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 96 96 | 
             
              none: false
         | 
| 97 97 | 
             
              requirements:
         |