Created
November 19, 2011 04:39
-
-
Save idyll/1378455 to your computer and use it in GitHub Desktop.
UTF-16LE version of the sample code
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
require 'rubygems' | |
class String | |
def multibyte? | |
chars.count < bytes.count | |
end | |
end | |
if not ARGV[0] | |
abort("please pass in a .strings file to process...") | |
end | |
stringsfiletoprocess = ARGV[0] | |
onelinecomment = "//" | |
multilinecomment = "/*" | |
counter = 1 | |
# The encoding you sent looked like it was UTF16 Litte Endian. | |
# If not, change the encoding here | |
file = File.new(stringsfiletoprocess, "rb:UTF-16LE") | |
while (line = file.gets) | |
#You can't mix UTF16 with ASCII, but you can if you use UTF8 | |
puts "#{counter}: #{line.encode("UTF-8").to_s}" | |
#puts line | |
if counter == 10 | |
# You'll explode here unless you make a UTF16 String. | |
line = "// Alert Yes button".encode("UTF-16LE") | |
end | |
# Let the regex know what encoding you intend to use. | |
regex = Regexp.new("\/\/ Alert Yes button".encode("UTF-16LE")) | |
if line.match(regex) | |
#Again, you can't mix UTF16 with ASCII, but you can if you use UTF8 | |
puts "one line comment: #{line.encode("UTF-8").to_s}" | |
end | |
#puts "line multibyte: #{line.multibyte?}" | |
counter = counter + 1 | |
if counter == 12 | |
#abort("now") | |
end | |
end | |
file.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment