carpodaster-unicase 0.2.0

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.
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+ require 'open-uri'
3
+
4
+ #downloads the latest UnicodeData.txt file, and then spits out
5
+ #codepoint, lowercase, uppercase
6
+ #for codepoiunts that have lowercase or uppercase versions
7
+ out = File.open("case_data.dat", "w")
8
+ open('http://unicode.org/Public/UNIDATA/UnicodeData.txt') do |f|
9
+ f.each_line do |line|
10
+ parts = line.chomp!.split(';')
11
+ cp = parts[0]
12
+ lc = parts[13]
13
+ uc = parts[12]
14
+ if lc || uc
15
+ out.puts [cp, lc || "", uc || ""].join("\t")
16
+ end
17
+ end
18
+ end
19
+ out.close
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+ module Unicase
3
+ Uppercase = Hash.new { |h,k| k}
4
+ Lowercase = Hash.new { |h,k| k}
5
+ def self.to_u(x)
6
+ [x.to_i(16)].pack("U").freeze
7
+ end
8
+
9
+ File.open(File.join(File.dirname(__FILE__), "case_data.dat")) do |f|
10
+ f.each do |line|
11
+ parts = line.chomp!.split("\t")
12
+ cp = parts[0]
13
+ lc = parts[1] || ""
14
+ uc = parts[2] || ""
15
+ char = Unicase::to_u(cp)
16
+ Lowercase[char] = Unicase::to_u(lc) if lc != ""
17
+ Uppercase[char] = Unicase::to_u(uc) if uc != ""
18
+ end
19
+ end
20
+ end
21
+
22
+ class String
23
+ def first_unicode_capitalize
24
+ if self =~ /\A(.)/um
25
+ Unicase::Uppercase[$1] + $'
26
+ else
27
+ self.dup
28
+ end
29
+ end
30
+
31
+ def first_unicode_lowercase
32
+ if self =~ /\A(.)/um
33
+ Unicase::Lowercase[$1] + $'
34
+ else
35
+ self.dup
36
+ end
37
+ end
38
+
39
+ def unicode_lowercase
40
+ res = ""
41
+ each_char { |x| res << Unicase::Lowercase[x] }
42
+ res
43
+ end
44
+ def unicode_uppercase
45
+ res = ""
46
+ each_char { |x| res << Unicase::Uppercase[x] }
47
+ res
48
+ end
49
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: carpodaster-unicase
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
+ platform: ruby
12
+ authors:
13
+ - bkkgrad
14
+ - Carsten Zimmermann
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2010-11-11 00:00:00 +01:00
20
+ default_executable:
21
+ dependencies: []
22
+
23
+ description: Upcase and downcase methods for non-ASCII string; originally taken from bkkbrad/unicase
24
+ email: carp@hacksocke.de
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files:
30
+ - LICENSE
31
+ - README
32
+ files:
33
+ - CHANGELOG.rdoc
34
+ - LICENSE
35
+ - README
36
+ - Rakefile
37
+ - VERSION
38
+ - lib/case_data.dat
39
+ - lib/case_data_creator.rb
40
+ - lib/unicase.rb
41
+ has_rdoc: true
42
+ homepage: http://github.com/carpodaster/unicase
43
+ licenses: []
44
+
45
+ post_install_message:
46
+ rdoc_options:
47
+ - --charset=UTF-8
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ hash: 3
56
+ segments:
57
+ - 0
58
+ version: "0"
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ hash: 3
65
+ segments:
66
+ - 0
67
+ version: "0"
68
+ requirements: []
69
+
70
+ rubyforge_project:
71
+ rubygems_version: 1.3.7
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Unicase-aware upcase and downcase
75
+ test_files: []
76
+