Last active
February 6, 2022 13:09
-
-
Save hpyhacking/4308935 to your computer and use it in GitHub Desktop.
Can use index by pinyin with English language setting on iPhone.
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' | |
require 'chinese_pinyin' | |
name = [] | |
cp = false | |
def p(z) | |
pinyin = Pinyin.t(z, '') | |
pinyin[0] = pinyin[0].upcase | |
pinyin | |
end | |
ARGF.readlines.each do |x| | |
if cp and (not (/X-PHONETIC/ =~ x)) | |
if name and name.length == 2 | |
puts "X-PHONETIC-FIRST-NAME:#{p(name[0])}" | |
puts "X-PHONETIC-LAST-NAME:#{p(name[1])}" | |
elsif name and name.length == 1 | |
puts "X-PHONETIC-LAST-NAME:#{p(name[0])}" | |
else | |
raise "ERROR NAME FORMAT #{name}" | |
end | |
end | |
cp = (/FN:/ =~ x) | |
name = x.split(':')[1].split(' ') if cp | |
puts x | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
在Mac OS X 10.12.4上运行会报:
/Library/Ruby/Gems/2.0.0/gems/chinese_pinyin-1.0.1/lib/chinese_pinyin.rb:54:in
translate': undefined method
fetch' for "":String (NoMethodError)系统自带的ruby版本:ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin16]