easy_conv 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +1 -0
- data/easy_conv.gemspec +22 -0
- data/lib/easy_conv.rb +58 -0
- data/lib/easy_conv/version.rb +3 -0
- metadata +86 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 yoshikizh
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# EasyConv
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'easy_conv'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install easy_conv
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
EasyConv.u2s(str)
|
22
|
+
EasyConv.s2u(str)
|
23
|
+
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/easy_conv.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'easy_conv/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "easy_conv"
|
8
|
+
gem.version = EasyConv::VERSION
|
9
|
+
gem.authors = ["yoshikizh"]
|
10
|
+
gem.email = ["177365340@qq.com"]
|
11
|
+
gem.description = "easy_conv"
|
12
|
+
gem.summary = "easy_conv"
|
13
|
+
gem.homepage = "https://github.com/yoshikizh/easy_conv"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency "rspec"
|
21
|
+
gem.add_development_dependency "bundler", ">= 1.0.0"
|
22
|
+
end
|
data/lib/easy_conv.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require "easy_conv/version"
|
2
|
+
|
3
|
+
module EasyConv
|
4
|
+
# API梡掕悢掕媊
|
5
|
+
CP_ACP = 0
|
6
|
+
CP_UTF8 = 65001
|
7
|
+
CP_UTF7 = 65000
|
8
|
+
|
9
|
+
#--------------------------------------------------------------------------
|
10
|
+
# 仠 S-JIS -> UTF-8
|
11
|
+
#--------------------------------------------------------------------------
|
12
|
+
def s2u(text)
|
13
|
+
# API掕媊
|
14
|
+
m2w = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
|
15
|
+
w2m = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')
|
16
|
+
|
17
|
+
# S-JIS -> Unicode
|
18
|
+
len = m2w.call(CP_ACP, 0, text, -1, nil, 0);
|
19
|
+
buf = "\0" * (len*2)
|
20
|
+
m2w.call(CP_ACP, 0, text, -1, buf, buf.size/2);
|
21
|
+
|
22
|
+
# Unicode -> UTF-8
|
23
|
+
len = w2m.call(CP_UTF8, 0, buf, -1, nil, 0, nil, nil);
|
24
|
+
|
25
|
+
#---<shana marked>---<len - 1>---
|
26
|
+
ret = "\0" * (len - 1)
|
27
|
+
#--------------------------------
|
28
|
+
|
29
|
+
w2m.call(CP_UTF8, 0, buf, -1, ret, ret.size, nil, nil);
|
30
|
+
return ret
|
31
|
+
end
|
32
|
+
# module_function偲偟偰岞奐
|
33
|
+
module_function :s2u
|
34
|
+
#--------------------------------------------------------------------------
|
35
|
+
# 仠 UTF-8 -> S-JIS
|
36
|
+
#--------------------------------------------------------------------------
|
37
|
+
def u2s(text)
|
38
|
+
# API掕媊
|
39
|
+
m2w = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
|
40
|
+
w2m = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')
|
41
|
+
|
42
|
+
# UTF-8 -> Unicode
|
43
|
+
len = m2w.call(CP_UTF8, 0, text, -1, nil, 0);
|
44
|
+
buf = "\0" * (len*2)
|
45
|
+
m2w.call(CP_UTF8, 0, text, -1, buf, buf.size/2);
|
46
|
+
|
47
|
+
# Unicode -> S-JIS
|
48
|
+
len = w2m.call(CP_ACP, 0, buf, -1, nil, 0, nil, nil);
|
49
|
+
#---<shana marked>---<len - 1>---
|
50
|
+
ret = "\0" * (len - 1)
|
51
|
+
#--------------------------------
|
52
|
+
w2m.call(CP_ACP, 0, buf, -1, ret, ret.size, nil, nil);
|
53
|
+
|
54
|
+
return ret
|
55
|
+
end
|
56
|
+
# module_function偲偟偰岞奐
|
57
|
+
module_function :u2s
|
58
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: easy_conv
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- yoshikizh
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: bundler
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.0.0
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.0.0
|
46
|
+
description: easy_conv
|
47
|
+
email:
|
48
|
+
- 177365340@qq.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- easy_conv.gemspec
|
59
|
+
- lib/easy_conv.rb
|
60
|
+
- lib/easy_conv/version.rb
|
61
|
+
homepage: https://github.com/yoshikizh/easy_conv
|
62
|
+
licenses: []
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 1.8.24
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: easy_conv
|
85
|
+
test_files: []
|
86
|
+
has_rdoc:
|