Git Product home page Git Product logo

encoding_checker's Introduction

EncodingChecker

Build Status

When you need to parse some text files - you need to be sure, that they are in some particular encoding before actually parsing them. For example, some symbols are invalid for UTF-8 encoding, but nevertheless files which are mainly in UTF-8 can contain some invalid characters and many of editors will not show you that. This gem will help you identify lines and characters of the text which are invalid for particular encoding.

Installation

This gem relies on encoding information, which is available only in Ruby 1.9.x. Maybe sometimes I'll add 1.8.x support through iconv library, but for now 1.8.x is not supported.

Add this line to your application's Gemfile:

gem 'encoding_checker'

And then execute:

$ bundle

Or install it yourself as:

$ gem install encoding_checker

Usage

# instantiate checker with encoding name
checker = EncodingChecker.new("utf-8")
# check any particular text
result = checker.check("some string with wrong\xA0symbol")

unless result.empty?
  result.invalid_lines.each do |line|
    # use line.content, line.index and line.invalid_characters
    line.invalid_characters.each do |character|
      # use character.content and character.index
    end
  end
end

# raises EncodingChecker::Error
checker.check!("some string with wrong\xA0symbol")

Read the specs for more information.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

encoding_checker's People

Contributors

fxposter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.