gsm_encoder 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -1
- data/lib/gsm_encoder.rb +14 -37
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91c1a1004a76bf14885a1d182f059f9f57164318
|
4
|
+
data.tar.gz: fa5f8d73b4105406725dcc346794cf02e44097ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d1722f6afc1a458bbc52d9ad7f07b04c84cb4a4be69563bfe8db67563f0c93a41e69aac997fce83b5e47e75c3371f2813667014d5056f96db76adfb9a24e09b
|
7
|
+
data.tar.gz: 0e0e21460277b77fe888c62ef7ac7a21dab7790cf38398c36f7b891db56da1995a94e16dbcfe09fba5dcd184c828eb253b4e059b266c97823965c4ddd62ffdde
|
data/README.md
CHANGED
@@ -39,7 +39,11 @@ Added support for Spanish shift
|
|
39
39
|
|
40
40
|
Fixed bug when encoding line feed & carriage return
|
41
41
|
|
42
|
-
|
42
|
+
### 0.1.3
|
43
43
|
|
44
44
|
Adds the ability to provide the character used when encoding
|
45
45
|
unsupported strings
|
46
|
+
|
47
|
+
### 0.1.4
|
48
|
+
|
49
|
+
Code cleanup and speedup
|
data/lib/gsm_encoder.rb
CHANGED
@@ -18,7 +18,7 @@ module GSMEncoder
|
|
18
18
|
'@', '£', '$', '¥', 'è', 'é', 'ù', 'ì',
|
19
19
|
'ò', 'Ç', NL, 'Ø', 'ø', CR , 'Å', 'å',
|
20
20
|
'Δ', '_', 'Φ', 'Γ', 'Λ', 'Ω', 'Π', 'Ψ',
|
21
|
-
'Σ', 'Θ', 'Ξ', " ", 'Æ', 'æ', 'ß', 'É',
|
21
|
+
'Σ', 'Θ', 'Ξ', " ", 'Æ', 'æ', 'ß', 'É', # 0x1B is actually an escape which we'll encode to a space char
|
22
22
|
" ", '!', '"', '#', '¤', '%', '&', "'",
|
23
23
|
'(', ')', '*', '+', ',', '-', '.', '/',
|
24
24
|
'0', '1', '2', '3', '4', '5', '6', '7',
|
@@ -31,7 +31,7 @@ module GSMEncoder
|
|
31
31
|
'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
|
32
32
|
'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
|
33
33
|
'x', 'y', 'z', 'ä', 'ö', 'ñ', 'ü', 'à',
|
34
|
-
]
|
34
|
+
].join # make it string to speedup lookup
|
35
35
|
|
36
36
|
# Extended character table. Characters in this table are accessed by the
|
37
37
|
# 'escape' character in the base table. It is important that none of the
|
@@ -48,6 +48,8 @@ module GSMEncoder
|
|
48
48
|
0, 0, 0, 0, 0, 'ú', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
49
49
|
]
|
50
50
|
|
51
|
+
CHARS = CHAR_TABLE + EXT_CHAR_TABLE.select {|c| c != 0}.join
|
52
|
+
|
51
53
|
# Verifies that this charset can represent every character in the Ruby
|
52
54
|
# String.
|
53
55
|
# @param str The String to verfiy
|
@@ -57,25 +59,12 @@ module GSMEncoder
|
|
57
59
|
return true if !str
|
58
60
|
|
59
61
|
str.each_char do |c|
|
60
|
-
#
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
# search both charmaps (if char is in either, we're good!)
|
65
|
-
found = false
|
66
|
-
j = 0
|
67
|
-
while j < CHAR_TABLE.length
|
68
|
-
if c == CHAR_TABLE[j] || c == EXT_CHAR_TABLE[j]
|
69
|
-
found = true
|
70
|
-
break
|
71
|
-
end
|
72
|
-
j += 1
|
73
|
-
end
|
74
|
-
# if we searched both charmaps and didn't find it, then its bad
|
75
|
-
return false if !found
|
62
|
+
# simple range checks for most common characters (' '..'_') or ('a'..'~')
|
63
|
+
b = c.getbyte(0)
|
64
|
+
unless b >= 0x20 && b <= 0x5F || b >= 0x61 && b <= 0x7E || CHARS.index(c)
|
65
|
+
return false
|
76
66
|
end
|
77
67
|
end
|
78
|
-
|
79
68
|
true
|
80
69
|
end
|
81
70
|
|
@@ -88,24 +77,12 @@ module GSMEncoder
|
|
88
77
|
|
89
78
|
begin
|
90
79
|
str.each_char do |c|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
if c == CHAR_TABLE[search]
|
98
|
-
buffer << search
|
99
|
-
break
|
100
|
-
end
|
101
|
-
if c == EXT_CHAR_TABLE[search]
|
102
|
-
buffer << EXTENDED_ESCAPE
|
103
|
-
buffer << search
|
104
|
-
break
|
105
|
-
end
|
106
|
-
search += 1
|
107
|
-
end
|
108
|
-
if search == CHAR_TABLE.length
|
80
|
+
if index = EXT_CHAR_TABLE.index(c)
|
81
|
+
buffer << EXTENDED_ESCAPE
|
82
|
+
buffer << index
|
83
|
+
elsif index = CHAR_TABLE.rindex(c)
|
84
|
+
buffer << index
|
85
|
+
else
|
109
86
|
buffer << replace_char
|
110
87
|
end
|
111
88
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gsm_encoder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yury Korolev
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-26 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: GSMEncoder encodes and decodes Ruby Strings to and from the SMS default
|
15
15
|
alphabet. It also supports the default extension table. The default alphabet and
|