Skip to content

Instantly share code, notes, and snippets.

@luikore
Created June 13, 2013 17:24
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save luikore/5775559 to your computer and use it in GitHub Desktop.
Save luikore/5775559 to your computer and use it in GitHub Desktop.
textmate command to add space between english and chinese
#! /usr/bin/env ruby
str = $stdin.read
if RUBY_VERSION < '1.9'
print str
exit
end
str.force_encoding 'utf-8'
str.gsub! /(\p{Han})([a-zA-Z0-9\(\)\[\]\{\}])/u do
"#$1 #$2"
end
str.gsub! /([a-zA-Z0-9\(\)\[\]\{\}])(\p{Han})/u do
"#$1 #$2"
end
print str
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment