Created
January 14, 2012 10:01
-
-
Save rubypanther/1610875 to your computer and use it in GitHub Desktop.
FICS paste cleaner utility
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
FICS_LIMIT = 400 | |
if RUBY_VERSION < '1.9' | |
require 'iconv' | |
def conv str | |
Iconv.conv("US-ASCII//TRANSLIT//IGNORE","UTF-8", str) | |
end | |
else | |
def conv str | |
str.encode 'US-ASCII', 'UTF-8', :invalid => :replace, :undef => :replace | |
end | |
end | |
def print_chunk chunk | |
chunk.strip! | |
print "\n+++\n%s\n---\s" % chunk unless chunk.empty? | |
end | |
while input = STDIN.gets | |
str = conv input | |
str.scan(/.{0,#{FICS_LIMIT}}(?:(?!\w)|$)/).each do |chunk| | |
print_chunk chunk | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment