| 125 | | def self.string_to_binary(value) |
|---|
| 126 | | value.gsub(/(\r|\n|\0|\x1a)/) do |
|---|
| 127 | | case $1 |
|---|
| 128 | | when "\r" then "%00" |
|---|
| 129 | | when "\n" then "%01" |
|---|
| 130 | | when "\0" then "%02" |
|---|
| 131 | | when "\x1a" then "%03" |
|---|
| 132 | | end |
|---|
| 133 | | end |
|---|
| 134 | | end |
|---|
| 135 | | |
|---|
| 136 | | def self.binary_to_string(value) |
|---|
| 137 | | value.gsub(/(%00|%01|%02|%03)/) do |
|---|
| 138 | | case $1 |
|---|
| 139 | | when "%00" then "\r" |
|---|
| 140 | | when "%01" then "\n" |
|---|
| 141 | | when "%02\0" then "\0" |
|---|
| 142 | | when "%03" then "\x1a" |
|---|
| 143 | | end |
|---|
| 144 | | end |
|---|
| 145 | | end |
|---|
| | 125 | def self.string_to_binary(value) |
|---|
| | 126 | Base64.encode64(value) |
|---|
| | 127 | end |
|---|
| | 128 | |
|---|
| | 129 | def self.binary_to_string(value) |
|---|
| | 130 | Base64.decode64(value) |
|---|
| | 131 | end |
|---|