module GsmHelper
  # Returns a new string in GSM 03.38 encoding
  def to_gsm0338(message)
    # Replace bad characters with GSM allowed ones
    map = 
    { 
      "“" => "\"",
      "”" => "\"", 
      "—" => "-" 
    }
    re = Regexp.new(map.keys.map { |x| Regexp.escape(x) }.join('|'))
    message_clean = message.gsub(re, map)

    # Run resulting string though GSMEncoder. Replace any remaining bad characters with a space.
    message_clean = GSMEncoder.encode(message_clean, ' ')
    return message_clean
  end

end
module GsmHelper
  # Returns a new string in GSM 03.38 encoding
  def to_gsm0338(message)
    # Replace bad characters with GSM allowed ones
    map = 
    { 
      "“" => "\"",
      "”" => "\"", 
      "—" => "-",
      "’" => "'"
    }
    re = Regexp.new(map.keys.map { |x| Regexp.escape(x) }.join('|'))
    message_clean = message.gsub(re, map)

    # Run resulting string though GSMEncoder. Replace any remaining bad characters with a space.
    message_clean = GSMEncoder.encode(message_clean, ' ')
    return message_clean
  end

end
Add non-GSM - to mapping
Add non-GSM - to mapping
