gsm_encoder 0.1.0 → 0.1.2
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.
- checksums.yaml +7 -0
- data/README.md +15 -3
- data/lib/gsm_encoder.rb +35 -41
- metadata +14 -14
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: afd16680c9add39fa0f0a6b40e0a5674df79ffdc
|
4
|
+
data.tar.gz: 27b2dbd76a63054ae29fdab05730ff7aa9342c53
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 91ea6159220788a7ff282a8ebb833b51901a0b9ca1b233de0222d7295e9a700a51d5e5d0cdfd0b9d4e8984b22f50e6a85769b14f8a595152fa0e59d6053399e4
|
7
|
+
data.tar.gz: b8bf806da9c5fead874c7db1253d62801badd906035bcf42c053611cab8003585c6951d58da68c4ce5b34ccac68bdf07ce54a999bf64a7202083ff988991153c
|
data/README.md
CHANGED
@@ -6,8 +6,10 @@ This is port of Twitter's Java [implementation](https://github.com/twitter/cloud
|
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
9
|
+
__NOTE: ruby >= 1.9.2 is required__
|
10
|
+
|
9
11
|
gem install gsm_encoder
|
10
|
-
|
12
|
+
|
11
13
|
## Usage
|
12
14
|
|
13
15
|
require 'gsm_encoder'
|
@@ -19,7 +21,17 @@ This is port of Twitter's Java [implementation](https://github.com/twitter/cloud
|
|
19
21
|
GSMEncoder.decode(GSMEncoder.encode('hi')) # => 'hi'
|
20
22
|
|
21
23
|
# can encode?
|
22
|
-
GSMEncoder.
|
24
|
+
GSMEncoder.can_encode?('`') # => false
|
23
25
|
|
24
26
|
# replaces unsupported chars with '?'
|
25
|
-
GSMEncoder.encode('`') # => '?'
|
27
|
+
GSMEncoder.encode('`') # => '?'
|
28
|
+
|
29
|
+
## Updates
|
30
|
+
|
31
|
+
### 0.1.1
|
32
|
+
|
33
|
+
Added support for Spanish shift
|
34
|
+
|
35
|
+
### 0.1.2
|
36
|
+
|
37
|
+
Fixed bug when encoding line feed & carriage return
|
data/lib/gsm_encoder.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
#encoding: utf-8
|
1
2
|
# Stealing from Twitter's Java implementation
|
2
3
|
# https://github.com/twitter/cloudhopper-commons-charset/blob/master/src/main/java/com/cloudhopper/commons/charset/GSMCharset.java
|
3
4
|
|
@@ -6,50 +7,44 @@
|
|
6
7
|
# alphabet. It also supports the default extension table. The default alphabet
|
7
8
|
# and it's extension table is defined in GSM 03.38.
|
8
9
|
module GSMEncoder
|
9
|
-
|
10
|
+
|
10
11
|
EXTENDED_ESCAPE = 0x1b
|
11
|
-
|
12
|
+
NL = 10.chr
|
13
|
+
CR = 13.chr
|
14
|
+
BS = 92.chr
|
15
|
+
|
12
16
|
CHAR_TABLE = [
|
13
|
-
'@',
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
" ", '!', '"', '#',
|
17
|
+
'@', '£', '$', '¥', 'è', 'é', 'ù', 'ì',
|
18
|
+
'ò', 'Ç', NL, 'Ø', 'ø', CR , 'Å', 'å',
|
19
|
+
'Δ', '_', 'Φ', 'Γ', 'Λ', 'Ω', 'Π', 'Ψ',
|
20
|
+
'Σ', 'Θ', 'Ξ', " ", 'Æ', 'æ', 'ß', 'É',
|
21
|
+
" ", '!', '"', '#', '¤', '%', '&', "'",
|
18
22
|
'(', ')', '*', '+', ',', '-', '.', '/',
|
19
23
|
'0', '1', '2', '3', '4', '5', '6', '7',
|
20
24
|
'8', '9', ':', ';', '<', '=', '>', '?',
|
21
|
-
|
25
|
+
'¡', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
|
22
26
|
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
|
23
27
|
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
|
24
|
-
'X', 'Y', 'Z',
|
25
|
-
|
28
|
+
'X', 'Y', 'Z', 'Ä', 'Ö', 'Ñ', 'Ü', '§',
|
29
|
+
'¿', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
|
26
30
|
'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
|
27
31
|
'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
|
28
|
-
'x', 'y', 'z',
|
32
|
+
'x', 'y', 'z', 'ä', 'ö', 'ñ', 'ü', 'à',
|
29
33
|
]
|
30
|
-
|
31
34
|
|
32
35
|
# Extended character table. Characters in this table are accessed by the
|
33
36
|
# 'escape' character in the base table. It is important that none of the
|
34
37
|
# 'inactive' characters ever be matchable with a valid base-table
|
35
38
|
# character as this breaks the encoding loop.
|
36
39
|
EXT_CHAR_TABLE = [
|
37
|
-
0, 0, 0, 0, 0, 0, 0, 0,
|
38
|
-
0,
|
39
|
-
0, 0, 0, 0,
|
40
|
-
0,
|
41
|
-
0, 0, 0, 0, 0, 0, 0, 0,
|
42
|
-
|
43
|
-
0, 0, 0, 0, 0, 0, 0, 0,
|
44
|
-
0,
|
45
|
-
'|', 0, 0, 0, 0, 0, 0, 0,
|
46
|
-
0, 0, 0, 0, 0, 0, 0, 0,
|
47
|
-
0, 0, 0, 0, 0, 0, 0, 0,
|
48
|
-
0, 0, 0, 0, 0, 0, 0, 0,
|
49
|
-
0, 0, 0, 0, 0, "\u20ac", 0, 0,
|
50
|
-
0, 0, 0, 0, 0, 0, 0, 0,
|
51
|
-
0, 0, 0, 0, 0, 0, 0, 0,
|
52
|
-
0, 0, 0, 0, 0, 0, 0, 0,
|
40
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 'ç', 0, 0, 0, 0, 0, 0,
|
41
|
+
0, 0, 0, 0, '^', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
42
|
+
0, 0, 0, 0, 0, 0, 0, 0, '{', '}', 0, 0, 0, 0, 0, BS,
|
43
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '[', '~', ']', 0,
|
44
|
+
'|', 'Á', 0, 0, 0, 0, 0, 0, 0, 'Í', 0, 0, 0, 0, 0, 'Ó',
|
45
|
+
0, 0, 0, 0, 0, 'Ú', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
46
|
+
0, 'á', 0, 0, 0, '€', 0, 0, 0, 'í', 0, 0, 0, 0, 0, 'ó',
|
47
|
+
0, 0, 0, 0, 0, 'ú', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
53
48
|
]
|
54
49
|
|
55
50
|
# Verifies that this charset can represent every character in the Ruby
|
@@ -60,8 +55,7 @@ module GSMEncoder
|
|
60
55
|
def can_encode? str
|
61
56
|
return true if !str
|
62
57
|
|
63
|
-
|
64
|
-
str.chars.each do |c|
|
58
|
+
str.each_char do |c|
|
65
59
|
# a very easy check a-z, A-Z, and 0-9 are always valid
|
66
60
|
if c >= ?A && c <= ?Z || c >= ?a && c <= ?z || c >= ?0 && c <= ?9
|
67
61
|
next
|
@@ -79,18 +73,18 @@ module GSMEncoder
|
|
79
73
|
# if we searched both charmaps and didn't find it, then its bad
|
80
74
|
return false if !found
|
81
75
|
end
|
82
|
-
end
|
83
|
-
|
76
|
+
end
|
77
|
+
|
84
78
|
true
|
85
79
|
end
|
86
|
-
|
87
|
-
def encode str
|
80
|
+
|
81
|
+
def encode str
|
88
82
|
return nil if !str
|
89
83
|
|
90
84
|
buffer = ''.encode('binary')
|
91
85
|
|
92
86
|
begin
|
93
|
-
str.
|
87
|
+
str.each_char do |c|
|
94
88
|
search = 0
|
95
89
|
while search < CHAR_TABLE.length
|
96
90
|
if search == EXTENDED_ESCAPE
|
@@ -112,7 +106,7 @@ module GSMEncoder
|
|
112
106
|
buffer << '?'
|
113
107
|
end
|
114
108
|
end
|
115
|
-
rescue
|
109
|
+
rescue
|
116
110
|
# TODO: ?
|
117
111
|
end
|
118
112
|
buffer
|
@@ -120,9 +114,9 @@ module GSMEncoder
|
|
120
114
|
|
121
115
|
def decode bstring
|
122
116
|
return nil if !bstring
|
123
|
-
|
117
|
+
|
124
118
|
buffer = ''.encode('utf-8')
|
125
|
-
|
119
|
+
|
126
120
|
table = CHAR_TABLE
|
127
121
|
bstring.bytes.each do |c|
|
128
122
|
code = c & 0x000000ff
|
@@ -132,14 +126,14 @@ module GSMEncoder
|
|
132
126
|
else
|
133
127
|
buffer << (code >= table.length ? '?' : table[code])
|
134
128
|
# go back to the default table
|
135
|
-
table = CHAR_TABLE
|
129
|
+
table = CHAR_TABLE
|
136
130
|
end
|
137
131
|
end
|
138
132
|
buffer
|
139
133
|
end
|
140
134
|
|
141
135
|
module_function :can_encode?
|
142
|
-
module_function :encode
|
136
|
+
module_function :encode
|
143
137
|
module_function :decode
|
144
138
|
|
145
|
-
end
|
139
|
+
end
|
metadata
CHANGED
@@ -1,49 +1,49 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gsm_encoder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Yury Korolev
|
8
|
+
- Jeff Webb
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-03-13 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
|
-
description:
|
15
|
-
|
16
|
-
|
14
|
+
description: GSMEncoder encodes and decodes Ruby Strings to and from the SMS default
|
15
|
+
alphabet. It also supports the default extension table. The default alphabet and
|
16
|
+
it's extension table is defined in GSM 03.38
|
17
17
|
email:
|
18
18
|
- yury.korolev@gmail.com
|
19
|
+
- jeff@boowebb.com
|
19
20
|
executables: []
|
20
21
|
extensions: []
|
21
22
|
extra_rdoc_files: []
|
22
23
|
files:
|
23
24
|
- lib/gsm_encoder.rb
|
24
25
|
- README.md
|
25
|
-
homepage: http://github.com/
|
26
|
+
homepage: http://github.com/boowebb/gsm_encoder
|
26
27
|
licenses: []
|
28
|
+
metadata: {}
|
27
29
|
post_install_message:
|
28
30
|
rdoc_options: []
|
29
31
|
require_paths:
|
30
32
|
- lib
|
31
33
|
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
-
none: false
|
33
34
|
requirements:
|
34
|
-
- -
|
35
|
+
- - '>='
|
35
36
|
- !ruby/object:Gem::Version
|
36
37
|
version: '0'
|
37
38
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
-
none: false
|
39
39
|
requirements:
|
40
|
-
- -
|
40
|
+
- - '>='
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: 1.3.6
|
43
43
|
requirements: []
|
44
44
|
rubyforge_project:
|
45
|
-
rubygems_version:
|
45
|
+
rubygems_version: 2.0.0
|
46
46
|
signing_key:
|
47
|
-
specification_version:
|
48
|
-
summary: GSM 03.38 encoder/decoder
|
47
|
+
specification_version: 4
|
48
|
+
summary: ruby GSM 03.38 encoder/decoder
|
49
49
|
test_files: []
|