ykutils 0.1.8 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 94d8725f098ed2fab402064d5d17f29a3d66893a9f0ec2046d2bbf6de385f0d6
4
- data.tar.gz: de9db8ffac06710ed34babc306e1f273d7b4719651de134c29e50606ed3d19c2
3
+ metadata.gz: e5d696f13493f9f0087022669fcaea75295086078ba4ebd851c4d3daca72746c
4
+ data.tar.gz: 366473d0cb86d38dce2c0e4d183aba31a40bcce6aee18c28633817d3b7ee2cb0
5
5
  SHA512:
6
- metadata.gz: 4fa01e7f6a1b09185b054a55cf34ee8852e9f127580880af3fa40ab3c48ad0216ed94f41acafabe43a7abb33182ed511a406c52482ea9b6916f9c98120f0fafc
7
- data.tar.gz: 57fba77e78eb39fedb2cce6caaf6f65fbf13bb4c1b4ab742b4c606eeb56849d7aa3fd82dbe6c007c5d693fb7b6255b288589022fafe7f4048d078fea68a71363
6
+ metadata.gz: 9845481d8f18dd7326a4f3109a3b6e57ef226055c9bdd4ecf89a0ade2c69675e6022a5f09bd0e87f6002a499cb9c4ef3d2bfadf4e89b6324d60da7b28d2b223e
7
+ data.tar.gz: 60f678a622a4a063d71fe9b033460ad4291b6088d152433204b21da1b50ebd1dbe3293bcac871ac2f6e73b07f2aa9caa6e8509e5c42df0731ee8ff248a29a5f2
data/Gemfile CHANGED
@@ -9,6 +9,7 @@ gem "erubi"
9
9
  gem "filex"
10
10
  gem "rake", "~> 13.2"
11
11
  gem "tilt"
12
+ gem "nkf", "0.2.0"
12
13
 
13
14
  group :development, optional: true do
14
15
  gem "yard"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ykutils (0.1.8)
4
+ ykutils (0.1.10)
5
5
  erubi
6
6
  filex
7
7
  tilt
@@ -19,6 +19,7 @@ GEM
19
19
  json (2.7.1)
20
20
  language_server-protocol (3.17.0.3)
21
21
  messagex (0.1.5)
22
+ nkf (0.2.0)
22
23
  parallel (1.24.0)
23
24
  parser (3.3.0.2)
24
25
  ast (~> 2.4.1)
@@ -78,6 +79,7 @@ PLATFORMS
78
79
  DEPENDENCIES
79
80
  erubi
80
81
  filex
82
+ nkf (= 0.2.0)
81
83
  rake (~> 13.2)
82
84
  rspec (~> 3.13)
83
85
  rubocop (~> 1.50)
@@ -0,0 +1,167 @@
1
+ # -*- coding utf-8 -*-
2
+
3
+ require "nkf"
4
+
5
+ module Ykutils
6
+ module NKFUTIL
7
+ # ASCII-8BIT
8
+ # US-ASCII
9
+ unless CODE_TO_NAME
10
+ CODE_TO_NAME = Hash.new("ASCII")
11
+ CODE_TO_NAME["US-ASCII"] = "ASCII"
12
+ CODE_TO_NAME["stateless-ISO-2022-JP"] = "JIS"
13
+ CODE_TO_NAME["ISO-2022-JP"] = "JIS"
14
+ CODE_TO_NAME["ISO-2022-JP-2"] = "JIS"
15
+ CODE_TO_NAME["EUC-JP"] = "EUC"
16
+ CODE_TO_NAME["eucJP-ms"] = "EUC"
17
+ CODE_TO_NAME["Shift_JIS"] = "SJIS"
18
+ CODE_TO_NAME["Windows-31J"] = "SJIS"
19
+ CODE_TO_NAME["ASCII-8BIT"] = "BINARY"
20
+ CODE_TO_NAME["UTF-8"] = "UTF8"
21
+ end
22
+
23
+ begin
24
+ NAME_TO_ENCODING
25
+ rescue StandardError
26
+ NAME_TO_ENCODING = Hash.new("US-ASCII")
27
+ NAME_TO_ENCODING["UTF8"] = "UTF-8"
28
+ NAME_TO_ENCODING["ASCII"] = "US-ASCII"
29
+ NAME_TO_ENCODING["JIS"] = "ISO-2022-JP"
30
+ NAME_TO_ENCODING["EUC"] = "EUC-JP"
31
+ NAME_TO_ENCODING["SJIS"] = "Winodws-31J"
32
+ NAME_TO_ENCODING["BINARY"] = "ASCII-8BIT"
33
+ end
34
+
35
+ def self.guess_encoding(str)
36
+ puts "**#{str.encoding}"
37
+ CODE_TO_NAME[str.encoding.to_s]
38
+ end
39
+
40
+ class Assoc
41
+ @hs = {}
42
+ @config = nil
43
+
44
+ def self.set(key, value)
45
+ @hs[key] = if value
46
+ Assoc.convert(value)
47
+ # else
48
+ # value
49
+ end
50
+ end
51
+
52
+ def self.get(key)
53
+ @hs[key]
54
+ end
55
+
56
+ def self.to_nkf_encoding_format(encoding)
57
+ NAME_TO_ENCODING[encoding]
58
+ end
59
+
60
+ def self.config(_src_encoding, dest_encoding, _misc_option = nil)
61
+ @config = dest_encoding
62
+ end
63
+
64
+ def self.auto_config_to_inner(str, _misc_option = nil)
65
+ src_encoding = if str
66
+ Assoc.to_nkf_encoding_format(NKFUTIL.guess_encoding(str))
67
+ else
68
+ "US-ASCII"
69
+ end
70
+
71
+ # inner_encoding = Assoc.to_nkf_encoding_format( Assoc.get_inner_encoding )
72
+ # if inner_encoding != "US-ASCII"
73
+ # @config = inner_encoding
74
+ @config = nil
75
+ # end
76
+ src_encoding
77
+ end
78
+
79
+ def self.auto_config_from_inner(dest_enc, _misc_option = nil)
80
+ dest_encoding = Assoc.to_nkf_encoding_format(dest_enc)
81
+ # inner_encoding = Assoc.to_nkf_encoding_format( Assoc.get_inner_encoding )
82
+ # if inner_encoding != "US-ASCII"
83
+ # @config = dest_encoding.downcase
84
+ @config = dest_encoding
85
+ # end
86
+ end
87
+
88
+ def self.convert(str)
89
+ nstr = nil
90
+ unless str.nil?
91
+ if @config.nil?
92
+ nstr = str
93
+ else
94
+ begin
95
+ # nstr = NKF.nkf( @@config , str )
96
+ nstr = str.encode(@config)
97
+ rescue StandardError => e
98
+ puts e
99
+ puts "========="
100
+ pp caller(0)
101
+ end
102
+ end
103
+ end
104
+ nstr
105
+ end
106
+
107
+ # def Assoc.get_inner_encoding
108
+ # @@inner_encoding = ($KCODE != "NONE") ? $KCODE : "ASCII"
109
+ # end
110
+ end
111
+
112
+ def self.set(key, value)
113
+ Assoc.set(key, value)
114
+ end
115
+
116
+ def self.get(key)
117
+ Assoc.get(key)
118
+ end
119
+
120
+ def self.convert(str)
121
+ if str.nil?
122
+ ""
123
+ else
124
+ Assoc.convert(str)
125
+ end
126
+ end
127
+
128
+ def self.assoc_equal(target, key)
129
+ target == key || target == Assoc.get(key)
130
+ end
131
+
132
+ def self.config(src_encoding, dest_encoding, misc_option = nil)
133
+ Assoc.config(src_encoding, dest_encoding, misc_option)
134
+ end
135
+
136
+ def self.auto_config_to_inner(str, misc_option = nil)
137
+ Assoc.auto_config_to_inner(str, misc_option)
138
+ end
139
+
140
+ def self.auto_config_from_inner(dest_encoding, misc_option = nil)
141
+ Assoc.auto_config_to_inner(dest_encoding, misc_option)
142
+ end
143
+
144
+ def puts_sj(line)
145
+ puts line.encod(NAME_TO_ENCODING["SJIS"])
146
+ # puts NKF.nkf( "-Ws -m0" , line )
147
+ end
148
+
149
+ def puts_u(line)
150
+ puts line.encod(NAME_TO_ENCODING["UTF8"])
151
+ puts NKF.nkf("-Sw -m0", line)
152
+ end
153
+
154
+ def nkf_utf8_file(infname, outfname)
155
+ File.open(outfname) do |outf|
156
+ File.open(infname) do |file|
157
+ while (line = file.gets)
158
+ line.chomp!
159
+ # oline = NKF.nkf( "-w -m0" , line )
160
+ oline = line.encode(NAME_TO_ENCODING["UTF8"])
161
+ outf.printf("%s\n", oline)
162
+ end
163
+ end
164
+ end
165
+ end
166
+ end
167
+ end
@@ -3,11 +3,12 @@
3
3
  require "yaml"
4
4
  require "csv"
5
5
  require "ykutils/treemanagera"
6
- if RUBY_VERSION >= "1.8.7"
7
- require "ykutils/nkfutil19"
8
- else
9
- require "ykutils/nkfutil"
10
- end
6
+ #if RUBY_VERSION >= "1.8.7"
7
+ # require "ykutils/nkfutil19"
8
+ #else
9
+ # require "ykutils/nkfutil"
10
+ #end
11
+ require "ykutils/nkfutil20"
11
12
  require "ykutils/debugutils"
12
13
 
13
14
  module Ykutils
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ykutils
4
- VERSION = "0.1.8"
4
+ VERSION = "0.1.10"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ykutils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - yasuo kominami
@@ -92,6 +92,7 @@ files:
92
92
  - lib/ykutils/nginxconfigfiles.rb
93
93
  - lib/ykutils/nkfutil.rb
94
94
  - lib/ykutils/nkfutil19.rb
95
+ - lib/ykutils/nkfutil20.rb
95
96
  - lib/ykutils/osutil.rb
96
97
  - lib/ykutils/pathop.rb
97
98
  - lib/ykutils/retcodex.rb