string_case_pl 0.0.6 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -1
- data/lib/string_case_pl.rb +4 -17
- data/lib/string_cmp_pl.rb +77 -0
- data/string_case_pl.gemspec +5 -6
- data/test/test_character_case_change.rb +8 -97
- data/test/test_comparison.rb +107 -0
- data/test/test_helper.rb +1 -0
- metadata +13 -6
data/Rakefile
CHANGED
data/lib/string_case_pl.rb
CHANGED
@@ -14,11 +14,11 @@ class String
|
|
14
14
|
PL_WINDOWS_1250_LOWER = PL_UTF_8_LOWER.encode(WINDOWS_CP1250_ENCODING)
|
15
15
|
PL_WINDOWS_1250_UPPER = PL_UTF_8_UPPER.encode(WINDOWS_CP1250_ENCODING)
|
16
16
|
|
17
|
-
alias old_downcase_wo_pl downcase
|
18
|
-
alias old_upcase_wo_pl upcase
|
17
|
+
alias old_downcase_wo_pl downcase
|
18
|
+
alias old_upcase_wo_pl upcase
|
19
19
|
alias old_capitalize_wo_pl capitalize
|
20
20
|
|
21
|
-
def downcase
|
21
|
+
def downcase
|
22
22
|
case self.encoding.name
|
23
23
|
when UTF_8_ENCODING
|
24
24
|
self.tr!(PL_UTF_8_UPPER,PL_UTF_8_LOWER)
|
@@ -30,13 +30,7 @@ class String
|
|
30
30
|
self.old_downcase_wo_pl
|
31
31
|
end
|
32
32
|
|
33
|
-
def
|
34
|
-
str = self.dup
|
35
|
-
str.downcase!
|
36
|
-
str
|
37
|
-
end
|
38
|
-
|
39
|
-
def upcase!
|
33
|
+
def upcase
|
40
34
|
case self.encoding.name
|
41
35
|
when UTF_8_ENCODING
|
42
36
|
self.tr!(PL_UTF_8_LOWER, PL_UTF_8_UPPER)
|
@@ -48,12 +42,6 @@ class String
|
|
48
42
|
self.old_upcase_wo_pl
|
49
43
|
end
|
50
44
|
|
51
|
-
def upcase
|
52
|
-
str = self.dup
|
53
|
-
str.upcase!
|
54
|
-
str
|
55
|
-
end
|
56
|
-
|
57
45
|
def capitalize
|
58
46
|
s = self.dup
|
59
47
|
s[0] = s[0].upcase
|
@@ -68,4 +56,3 @@ class String
|
|
68
56
|
end
|
69
57
|
|
70
58
|
end
|
71
|
-
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'string_case_pl'
|
3
|
+
|
4
|
+
class String
|
5
|
+
PL_LETTER_ORDER = {}
|
6
|
+
|
7
|
+
("AĄBCĆDEĘFGHIJKLŁMNŃOÓPQRSŚTUVWXYZŹŻ" +
|
8
|
+
"aąbcćdeęfghijklłmnńoópqrsśtuvwxyzźż").force_encoding(UTF_8_ENCODING).
|
9
|
+
each_char.with_index do |char,index|
|
10
|
+
PL_LETTER_ORDER[char] = index
|
11
|
+
end
|
12
|
+
|
13
|
+
alias old_cmp_wo_pl <=>
|
14
|
+
|
15
|
+
def <=>(other)
|
16
|
+
if !other.is_a?(String)
|
17
|
+
old_cmp_wo_pl(other)
|
18
|
+
elsif self.encoding.name != UTF_8_ENCODING ||
|
19
|
+
other.encoding.name != UTF_8_ENCODING
|
20
|
+
case self.encoding.name
|
21
|
+
when UTF_8_ENCODING
|
22
|
+
case other.encoding.name
|
23
|
+
when ISO_8859_2_ENCODING,WINDOWS_CP1250_ENCODING
|
24
|
+
self.<=>(other.encode(UTF_8_ENCODING))
|
25
|
+
else
|
26
|
+
old_cmp_wo_pl(other)
|
27
|
+
end
|
28
|
+
when ISO_8859_2_ENCODING
|
29
|
+
case other.encoding.name
|
30
|
+
when UTF_8_ENCODING
|
31
|
+
self.encode(UTF_8_ENCODING) <=> other
|
32
|
+
when ISO_8859_2_ENCODING,WINDOWS_CP1250_ENCODING
|
33
|
+
self.encode(UTF_8_ENCODING) <=> other.encode(UTF_8_ENCODING)
|
34
|
+
else
|
35
|
+
old_cmp_wo_pl(other)
|
36
|
+
end
|
37
|
+
when WINDOWS_CP1250_ENCODING
|
38
|
+
case other.encoding.name
|
39
|
+
when UTF_8_ENCODING
|
40
|
+
self.encode(UTF_8_ENCODING) <=> other
|
41
|
+
when ISO_8859_2_ENCODING,WINDOWS_CP1250_ENCODING
|
42
|
+
self.encode(UTF_8_ENCODING) <=> other.encode(UTF_8_ENCODING)
|
43
|
+
else
|
44
|
+
old_cmp_wo_pl(other)
|
45
|
+
end
|
46
|
+
else
|
47
|
+
old_cmp_wo_pl(other)
|
48
|
+
end
|
49
|
+
else
|
50
|
+
self.each_char.with_index do |char,index|
|
51
|
+
position1 = PL_LETTER_ORDER[char]
|
52
|
+
position2 = PL_LETTER_ORDER[other[index]]
|
53
|
+
if position1 && position2
|
54
|
+
if position1 != position2
|
55
|
+
return (position1 < position2 ? -1 : 1)
|
56
|
+
end
|
57
|
+
else
|
58
|
+
if other[index]
|
59
|
+
if char.old_cmp_wo_pl(other[index]) != 0
|
60
|
+
return char.old_cmp_wo_pl(other[index])
|
61
|
+
end
|
62
|
+
else
|
63
|
+
return 1
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
# all equal, compare length
|
68
|
+
if self.length == other.length
|
69
|
+
return 0
|
70
|
+
elsif self.length < other.length
|
71
|
+
return -1
|
72
|
+
else
|
73
|
+
return 1
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
data/string_case_pl.gemspec
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "string_case_pl"
|
3
|
-
s.version = "0.0
|
4
|
-
s.
|
5
|
-
s.date = "2011-08-02"
|
3
|
+
s.version = "0.1.0"
|
4
|
+
s.date = "2011-01-11"
|
6
5
|
s.summary = "Additional support for Polish encodings in Ruby 1.9"
|
7
6
|
s.email = "apohllo@o2.pl"
|
8
|
-
s.homepage = "
|
9
|
-
s.description = "Polish extensions for Ruby 1.9 String #upcase
|
7
|
+
s.homepage = "https://github.com/apohllo/string_pl"
|
8
|
+
s.description = "Polish extensions for Ruby 1.9 String #upcase, #downcase and #capitalize supporting polish diacritics"
|
10
9
|
s.require_path = "lib"
|
11
10
|
s.has_rdoc = false
|
12
|
-
s.authors = ['Aleksander Pohl']
|
11
|
+
s.authors = ['Aleksander Pohl',"hosiawak","sebcioz"]
|
13
12
|
s.files = ["Rakefile", "string_case_pl.gemspec", 'lib/string_case_pl.rb'] +
|
14
13
|
Dir.glob("lib/**/*")
|
15
14
|
s.test_files = Dir.glob("{test}/**/*")
|
@@ -38,112 +38,23 @@ class TestCharacterCaseChange < Test::Unit::TestCase
|
|
38
38
|
def test_windows_1250_upcase
|
39
39
|
assert_equal(@windows_upper, @windows_lower.upcase)
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
def test_utf_8_capitalize
|
43
43
|
assert_equal(@utf_capitalized, @utf_lower.capitalize)
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
def test_windows_1250_capitalize
|
47
47
|
assert_equal(@windows_capitalized, @windows_lower.capitalize)
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
def test_iso_8859_2_capitalize
|
51
51
|
assert_equal(@iso_capitalized, @iso_lower.capitalize)
|
52
52
|
end
|
53
|
-
|
54
|
-
def test_preserve_utf_lower_case
|
55
|
-
original = @utf_lower.dup
|
56
|
-
@utf_lower.upcase
|
57
|
-
assert_equal(original,@utf_lower)
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_preserve_utf_upper_case
|
61
|
-
original = @utf_upper.dup
|
62
|
-
@utf_upper.downcase
|
63
|
-
assert_equal(original,@utf_upper)
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_preserve_iso_lower_case
|
67
|
-
original = @iso_lower.dup
|
68
|
-
@iso_lower.upcase
|
69
|
-
assert_equal(original,@iso_lower)
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_preserve_iso_upper_case
|
73
|
-
original = @iso_upper.dup
|
74
|
-
@iso_upper.downcase
|
75
|
-
assert_equal(original,@iso_upper)
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_preserve_windows_lower_case
|
79
|
-
original = @windows_lower.dup
|
80
|
-
@windows_lower.upcase
|
81
|
-
assert_equal(original,@windows_lower)
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_preserve_windows_upper_case
|
85
|
-
original = @windows_upper.dup
|
86
|
-
@windows_upper.downcase
|
87
|
-
assert_equal(original,@windows_upper)
|
88
|
-
end
|
89
|
-
|
90
|
-
def test_same_case
|
91
|
-
copy = @utf_lower.dup
|
92
|
-
assert_equal(@utf_lower,copy.downcase)
|
93
|
-
end
|
94
|
-
|
95
|
-
def test_same_case_bang
|
96
|
-
copy = @utf_lower.dup
|
97
|
-
assert_equal(nil,copy.downcase!)
|
98
|
-
assert_equal(copy,@utf_lower)
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_change_utf_lower_case
|
102
|
-
copy = @utf_lower.dup
|
103
|
-
copy.upcase!
|
104
|
-
assert_equal(copy,@utf_upper)
|
105
|
-
end
|
106
|
-
|
107
|
-
def test_change_utf_upper_case
|
108
|
-
copy = @utf_upper.dup
|
109
|
-
copy.downcase!
|
110
|
-
assert_equal(copy,@utf_lower)
|
111
|
-
end
|
112
|
-
|
113
|
-
def test_change_iso_lower_case
|
114
|
-
copy = @iso_lower.dup
|
115
|
-
copy.upcase!
|
116
|
-
assert_equal(copy,@iso_upper)
|
117
|
-
end
|
118
|
-
|
119
|
-
def test_change_iso_upper_case
|
120
|
-
copy = @iso_upper.dup
|
121
|
-
copy.downcase!
|
122
|
-
assert_equal(copy,@iso_lower)
|
123
|
-
end
|
124
|
-
|
125
|
-
def test_change_windows_lower_case
|
126
|
-
copy = @windows_lower.dup
|
127
|
-
copy.upcase!
|
128
|
-
assert_equal(copy,@windows_upper)
|
129
|
-
end
|
130
|
-
|
131
|
-
def test_change_windows_upper_case
|
132
|
-
copy = @windows_upper.dup
|
133
|
-
copy.downcase!
|
134
|
-
assert_equal(copy,@windows_lower)
|
135
|
-
end
|
136
|
-
|
137
|
-
def test_capitalize
|
138
|
-
original = @utf_lower.dup
|
139
|
-
assert_equal(original.capitalize, @utf_capitalized)
|
140
|
-
assert_equal(original, @utf_lower)
|
141
|
-
end
|
142
|
-
|
53
|
+
|
143
54
|
def test_capitalize!
|
144
|
-
|
145
|
-
assert_equal(
|
146
|
-
assert_equal(
|
55
|
+
d = @utf_lower.dup
|
56
|
+
assert_equal(d.capitalize!, @utf_capitalized)
|
57
|
+
assert_equal(d.capitalize!, nil)
|
147
58
|
end
|
148
|
-
|
59
|
+
|
149
60
|
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + "/test_helper")
|
3
|
+
|
4
|
+
class TestCharacterCaseChange < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_each_small_letter_comparison
|
10
|
+
assert_equal("a" <=> "b",-1)
|
11
|
+
assert_equal("a" <=> "ą",-1)
|
12
|
+
assert_equal("ą" <=> "a",1)
|
13
|
+
assert_equal("ą" <=> "ą",0)
|
14
|
+
assert_equal("b" <=> "ą",1)
|
15
|
+
assert_equal("b" <=> "ć",-1)
|
16
|
+
assert_equal("ć" <=> "ć",0)
|
17
|
+
assert_equal("ć" <=> "e",-1)
|
18
|
+
assert_equal("ć" <=> "b",1)
|
19
|
+
assert_equal("ę" <=> "e",1)
|
20
|
+
assert_equal("ę" <=> "f",-1)
|
21
|
+
assert_equal("ł" <=> "l",1)
|
22
|
+
assert_equal("ł" <=> "m",-1)
|
23
|
+
assert_equal("ń" <=> "n",1)
|
24
|
+
assert_equal("ń" <=> "o",-1)
|
25
|
+
assert_equal("ó" <=> "o",1)
|
26
|
+
assert_equal("ó" <=> "p",-1)
|
27
|
+
assert_equal("ś" <=> "s",1)
|
28
|
+
assert_equal("ś" <=> "t",-1)
|
29
|
+
assert_equal("ź" <=> "z",1)
|
30
|
+
assert_equal("ź" <=> "ż",-1)
|
31
|
+
assert_equal("ż" <=> "ź",1)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_each_big_letter_comparison
|
35
|
+
assert_equal("A" <=> "B",-1)
|
36
|
+
assert_equal("A" <=> "Ą",-1)
|
37
|
+
assert_equal("Ą" <=> "A",1)
|
38
|
+
assert_equal("Ą" <=> "Ą",0)
|
39
|
+
assert_equal("B" <=> "Ą",1)
|
40
|
+
assert_equal("B" <=> "Ć",-1)
|
41
|
+
assert_equal("Ć" <=> "Ć",0)
|
42
|
+
assert_equal("Ć" <=> "E",-1)
|
43
|
+
assert_equal("Ć" <=> "B",1)
|
44
|
+
assert_equal("Ę" <=> "E",1)
|
45
|
+
assert_equal("Ę" <=> "F",-1)
|
46
|
+
assert_equal("Ł" <=> "L",1)
|
47
|
+
assert_equal("Ł" <=> "M",-1)
|
48
|
+
assert_equal("Ń" <=> "N",1)
|
49
|
+
assert_equal("Ń" <=> "O",-1)
|
50
|
+
assert_equal("Ó" <=> "O",1)
|
51
|
+
assert_equal("Ó" <=> "P",-1)
|
52
|
+
assert_equal("Ś" <=> "S",1)
|
53
|
+
assert_equal("Ś" <=> "T",-1)
|
54
|
+
assert_equal("Ź" <=> "Z",1)
|
55
|
+
assert_equal("Ź" <=> "Ż",-1)
|
56
|
+
assert_equal("Ż" <=> "Ź",1)
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_non_string_comparison
|
60
|
+
assert_equal("a" <=> nil,nil)
|
61
|
+
assert_equal("ą" <=> nil,nil)
|
62
|
+
assert_equal(nil <=> "a",nil)
|
63
|
+
assert_equal(nil <=> "ą",nil)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_cross_encoding_comparison
|
67
|
+
assert_equal("a" <=> "b".encode("iso-8859-2"),-1)
|
68
|
+
assert_equal("a".encode("iso-8859-2") <=> "ą",-1)
|
69
|
+
assert_equal("a" <=> "ą".encode("iso-8859-2"),-1)
|
70
|
+
assert_equal("ą".encode("iso-8859-2") <=> "a".encode("iso-8859-2"),1)
|
71
|
+
assert_equal("a".encode("iso-8859-2") <=> "ą".encode("iso-8859-2"),-1)
|
72
|
+
assert_equal("ą".encode("iso-8859-2") <=> "ą".encode("iso-8859-2"),0)
|
73
|
+
assert_equal("b".encode("Windows-1250") <=> "ą".encode("iso-8859-2"),1)
|
74
|
+
assert_equal("b".encode("iso-8859-2") <=> "ć".encode("Windows-1250"),-1)
|
75
|
+
assert_equal("b".encode("iso-8859-2") <=> "b".encode("Windows-1250"),0)
|
76
|
+
assert_equal("ć".encode("Windows-1250") <=> "ć".encode("Windows-1250"),0)
|
77
|
+
assert_equal("ć".encode("Windows-1250") <=> "e".encode("Windows-1250"),-1)
|
78
|
+
assert_equal("ć" <=> "b".encode("Windows-1250"),1)
|
79
|
+
assert_equal("ę".encode("Windows-1250") <=> "e",1)
|
80
|
+
assert_equal("ę" <=> "ę".encode("Windows-1250"),0)
|
81
|
+
assert_equal("ę".encode("Windows-1250") <=> "ę",0)
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_multiletter_comparison
|
85
|
+
assert_equal("" <=> "ał",-1)
|
86
|
+
assert_equal("ał" <=> "",1)
|
87
|
+
assert_equal("a" <=> "ał",-1)
|
88
|
+
assert_equal("ał" <=> "a",1)
|
89
|
+
assert_equal("ał" <=> "ał",0)
|
90
|
+
assert_equal("ó" <=> "ów",-1)
|
91
|
+
assert_equal("ów" <=> "ó",1)
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_sort
|
95
|
+
assert_equal(
|
96
|
+
["ała","ama","ala"].sort,
|
97
|
+
["ala","ała","ama"])
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_case_comparison
|
101
|
+
assert_equal("Ą" <=> "ą",-1)
|
102
|
+
assert_equal("ą" <=> "Ą",1)
|
103
|
+
assert_equal("a" <=> "Ą",1)
|
104
|
+
assert_equal("Ą" <=> "a",-1)
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -2,18 +2,21 @@
|
|
2
2
|
name: string_case_pl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0
|
5
|
+
version: 0.1.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Aleksander Pohl
|
9
|
+
- hosiawak
|
10
|
+
- sebcioz
|
9
11
|
autorequire:
|
10
12
|
bindir: bin
|
11
13
|
cert_chain: []
|
12
14
|
|
13
|
-
date: 2011-
|
15
|
+
date: 2011-01-11 00:00:00 +01:00
|
16
|
+
default_executable:
|
14
17
|
dependencies: []
|
15
18
|
|
16
|
-
description: "Polish extensions for Ruby 1.9 String #upcase
|
19
|
+
description: "Polish extensions for Ruby 1.9 String #upcase, #downcase and #capitalize supporting polish diacritics"
|
17
20
|
email: apohllo@o2.pl
|
18
21
|
executables: []
|
19
22
|
|
@@ -25,9 +28,12 @@ files:
|
|
25
28
|
- Rakefile
|
26
29
|
- string_case_pl.gemspec
|
27
30
|
- lib/string_case_pl.rb
|
31
|
+
- lib/string_cmp_pl.rb
|
32
|
+
- test/test_comparison.rb
|
28
33
|
- test/test_character_case_change.rb
|
29
34
|
- test/test_helper.rb
|
30
|
-
|
35
|
+
has_rdoc: true
|
36
|
+
homepage: https://github.com/apohllo/string_pl
|
31
37
|
licenses: []
|
32
38
|
|
33
39
|
post_install_message:
|
@@ -40,7 +46,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
40
46
|
requirements:
|
41
47
|
- - ">="
|
42
48
|
- !ruby/object:Gem::Version
|
43
|
-
version:
|
49
|
+
version: "0"
|
44
50
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
51
|
none: false
|
46
52
|
requirements:
|
@@ -50,10 +56,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
50
56
|
requirements: []
|
51
57
|
|
52
58
|
rubyforge_project:
|
53
|
-
rubygems_version: 1.
|
59
|
+
rubygems_version: 1.5.2
|
54
60
|
signing_key:
|
55
61
|
specification_version: 3
|
56
62
|
summary: Additional support for Polish encodings in Ruby 1.9
|
57
63
|
test_files:
|
64
|
+
- test/test_comparison.rb
|
58
65
|
- test/test_character_case_change.rb
|
59
66
|
- test/test_helper.rb
|