Created
          June 13, 2013 17:24 
        
      - 
      
- 
        Save luikore/5775559 to your computer and use it in GitHub Desktop. 
    textmate command to add space between english and chinese
  
        
  
    
      This file contains hidden or 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 | |
| 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