Skip to content

Instantly share code, notes, and snippets.

@think2011
Created June 26, 2014 07:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save think2011/be2f951bae284086f309 to your computer and use it in GitHub Desktop.
Save think2011/be2f951bae284086f309 to your computer and use it in GitHub Desktop.
提取复姓
# 提取复姓
#
# @param [String] name
# @example name = getHyphenated '曾浩'
#
getHyphenated = (name) ->
if !name then return
hyphenated = ["欧阳", "太史", "端木", "上官", "司马", "东方", "独孤", "南宫", "万俟", "闻人", "夏侯", "诸葛", "尉迟", "公羊", "赫连", "澹台", "皇甫", "宗政", "濮阳", "公冶", "太叔", "申屠", "公孙", "慕容", "仲孙", "钟离", "长孙", "宇文", "城池", "司徒", "鲜于", "司空", "汝嫣", "闾丘", "子车", "亓官", "司寇", "巫马", "公西", "颛孙", "壤驷", "公良", "漆雕", "乐正", "宰父", "谷梁", "拓跋", "夹谷", "轩辕", "令狐", "段干", "百里", "呼延", "东郭", "南门", "羊舌", "微生", "公户", "公玉", "公仪", "梁丘", "公仲", "公上", "公门", "公山", "公坚", "左丘", "公伯", "西门", "公祖", "第五", "公乘", "贯丘", "公皙", "南荣", "东里", "东宫", "仲长", "子书", "子桑", "即墨", "达奚", "褚师"]
result = null
if /^[\u4e00-\u9fa5]/.test name
return result = v for v in hyphenated when v is name.substr 0, 2
result = name[0] # 否则提取首字
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment