Changeset 29268
- Timestamp:
- 01/30/09 12:30:29 (4 years ago)
- Location:
- lang/ruby/ruwin
- Files:
-
- 3 modified
-
lib/ruwin.rb (modified) (2 diffs)
-
lib/ruwin/edit_field.rb (modified) (6 diffs)
-
test/test_ruwin.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
lang/ruby/ruwin/lib/ruwin.rb
r29247 r29268 90 90 class String 91 91 if VERSION.match /^1\.8/ 92 alias _original_substring [] 93 def [] *args 94 return _original_substring(*args) if args[0].kind_of?(String) || args[0].kind_of?(Regexp) 92 def multibyte_substring *args 93 return self[*args] if args[0].kind_of?(String) || args[0].kind_of?(Regexp) 95 94 96 95 chars = multibyte_chars[*args] … … 102 101 end 103 102 104 def length103 def multibyte_length 105 104 multibyte_chars.size 106 105 end -
lang/ruby/ruwin/lib/ruwin/edit_field.rb
r29230 r29268 33 33 34 34 def physical_substring physical_first, physical_last 35 physical_string [physical_first...physical_last]35 physical_string.multibyte_substring(physical_first...physical_last) 36 36 end 37 37 alias substring physical_substring … … 39 39 40 40 def logical_substring logical_first, logical_last 41 logical_string [logical_first...logical_last]41 logical_string.multibyte_substring(logical_first...logical_last) 42 42 end 43 43 private :logical_substring … … 45 45 46 46 def physical_length 47 physical_string. length47 physical_string.multibyte_length 48 48 end 49 49 alias length physical_length … … 51 51 52 52 def logical_length 53 logical_string. length53 logical_string.multibyte_length 54 54 end 55 55 private :logical_length … … 91 91 def selection_string 92 92 first, last = get_physical_selection 93 physical_string [first...last]93 physical_string.multibyte_substring(first...last) 94 94 end 95 95 … … 192 192 private 193 193 def count_br physical_first, physical_length 194 (string [physical_first, physical_length]+" ").split("\r").size-1194 (string.multibyte_substring(physical_first, physical_length)+" ").split("\r").size-1 195 195 end 196 196 -
lang/ruby/ruwin/test/test_ruwin.rb
r29223 r29268 50 50 51 51 52 def test_string_ length53 assert_equal 3, "ABC". length52 def test_string_multibyte_length 53 assert_equal 3, "ABC".multibyte_length 54 54 end 55 55 56 def test_multibyte_string_ length_utf857 assert_equal 3, NKF.nkf("-Ww", "あいう"). length56 def test_multibyte_string_multibyte_length_utf8 57 assert_equal 3, NKF.nkf("-Ww", "あいう").multibyte_length 58 58 end 59 59 60 def test_multibyte_string_ length_sjis61 assert_equal 3, NKF.nkf("-Ws", "あいう"). length60 def test_multibyte_string_multibyte_length_sjis 61 assert_equal 3, NKF.nkf("-Ws", "あいう").multibyte_length 62 62 end 63 63 64 64 65 65 def test_string_substring 66 assert_equal "BCD", "ABCDE" [1...4]66 assert_equal "BCD", "ABCDE".multibyte_substring(1...4) 67 67 end 68 68 69 69 def test_string_substring_substr 70 assert_equal "BCD", "ABCDE" ["BCD"]70 assert_equal "BCD", "ABCDE".multibyte_substring("BCD") 71 71 end 72 72 73 73 def test_string_substring_regexp 74 assert_equal "BCD", "ABCDE" [/BCD/]74 assert_equal "BCD", "ABCDE".multibyte_substring(/BCD/) 75 75 end 76 76 77 77 def test_string_substring_index 78 assert_equal "B", "ABCDE" [1]78 assert_equal "B", "ABCDE".multibyte_substring(1) 79 79 end 80 80 81 81 def test_multibyte_string_substring_utf8 82 assert_equal NKF.nkf("-Ww", "いうえ"), NKF.nkf("-Ww", "あいうえお") [1...4]82 assert_equal NKF.nkf("-Ww", "いうえ"), NKF.nkf("-Ww", "あいうえお").multibyte_substring(1...4) 83 83 end 84 84 85 85 def test_multibyte_string_substring_usjis 86 assert_equal NKF.nkf("-Ws", "いうえ"), NKF.nkf("-Ws", "あいうえお") [1...4]86 assert_equal NKF.nkf("-Ws", "いうえ"), NKF.nkf("-Ws", "あいうえお").multibyte_substring(1...4) 87 87 end 88 88 end
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)