xingmamethod(srf_input, scheme){
	global IsPinyin, wumasp, DB, hasCaretPos, srf_all_Input, Imagine, pinyinhunsu, ShowCode, pinyinfancha, srf_last_input, fzm
		, srf_all_Input_tooltip, simasp, wumaqc, jichu_for_select_Array, srf_inputing, history_field_array, fuzhuma, save_field_array
	static history_field_array2:=[]
	max_code_len:=10, IsPinyin:=0
	srf_input_len:=StrLen(srf_input)

	If (fuzhuma&1)&&(A_ThisHotkey~="^[a-z]$"){
		If (srf_input_len>2)&&((Mod(srf_input_len,2)=1&&fzm:=SubStr(srf_input,0))||(fzm:=SubStr(srf_input,-1))){
			saixuan:=[], saixuan2:=[], fzmlen:=StrLen(fzm)
			Loop % jichu_for_select_Array.Length(){
				If (StrLen(jichu_for_select_Array[A_Index,1])>srf_input_len-fzmlen)
					Continue
				If (StrLen(jichu_for_select_Array[A_Index,2])>1&&jichu_for_select_Array[A_Index,6]~="i)" RegExReplace(fzm,"(.)","$1(.*)?"))
					jichu_for_select_Array[A_Index, -2]:=fzm, saixuan.Push(jichu_for_select_Array[A_Index])
				Else If (jichu_for_select_Array[A_Index,6]~="i)^" fzm)
					jichu_for_select_Array[A_Index, -2]:=fzm, saixuan2.Push(jichu_for_select_Array[A_Index])
				Else
					jichu_for_select_Array[A_Index].Delete(-2)
			}
			Loop % saixuan2.Length()
				saixuan.Push(saixuan2[A_Index])
			If saixuan.Length()=0
				fzm:=""		
		} Else If (Mod(StrLen(save_field_array[1,0]),2)=1)
			save_field_array:=[]
	}
	; pinyin
	; If (pinyinhunsu&&(((SubStr(srf_input,1,1)=="Z")&&(scheme~="wubi|五笔")&&(IsPinyin:=RegExMatch(srf_input:=SubStr(srf_input,2),"^(a[io]?|ou?|e[inr]?|ang?|ng|[bmp](a[io]?|[aei]ng?|ei|ie?|ia[no]|o|u)|pou|me|m[io]u|[fw](a|[ae]ng?|ei|o|u)|fou|wai|[dt](a[io]?|an|e|[aeio]ng|ie?|ia[no]|ou|u[ino]?|uan)|dei|diu|[nl](a[io]?|ei?|[eio]ng|i[eu]?|i?ang?|iao|in|ou|u[eo]?|ve?|uan)|nen|lia|lun|[ghk](a[io]?|[ae]ng?|e|ong|ou|u[aino]?|uai|uang?)|[gh]ei|[jqx](i(ao?|ang?|e|ng?|ong|u)?|u[en]?|uan)|([csz]h?|r)([ae]ng?|ao|e|i|ou|u[ino]?|uan)|[csz](ai?|ong)|[csz]h(ai?|uai|uang)|zei|[sz]hua|([cz]h|r)ong|y(ao?|[ai]ng?|e|i|ong|ou|u[en]?|uan))")))))
	If (pinyinhunsu&&(SubStr(srf_input,1,1)=="Z")&&(srf_input:=SubStr(srf_input,2)))
	{
		IsPinyin:=1
		SearchResult:=pinyinmethod(srf_input,"pinyin")
		tstr:=""
		If (ShowCode&1){
			mabiao:="", pinyinfancha:={}
			Loop % SearchResult.Length()
				If InStr(SearchResult[A_Index,0], "pinyin")
					mabiao .= "'" SearchResult[A_Index,2] "',"
			If (mabiao:=Trim(mabiao, ",")){
				DB.GetTable("SELECT value,key FROM " scheme " WHERE value IN (" mabiao ") ORDER BY key", Result)
				Loop % Result.RowCount
					pinyinfancha[Result.Rows[A_Index,1]]:=Result.Rows[A_Index,2]
			}
		}
		Return SearchResult
	} Else
		srf_all_Input_tooltip:=srf_input, IsPinyin:=0

	min_code_len:=1
	index:=1, save_field_array:={}
	While (index<srf_input_len+1){
		tlen:=Min(max_code_len,((srf_input_len+1-index)//min_code_len)*min_code_len)
		While (tlen>min_code_len-1){
			If !history_field_array.HasKey(srf_Input_trim_left:=SubStr(srf_input,index,tlen))
				history_field_array[srf_Input_trim_left]:=get_word(DB, srf_Input_trim_left, scheme)
			If (history_field_array[srf_Input_trim_left, 1, 2]){
				If SubStr(srf_input,index+tlen)&&(Mod(StrLen(srf_Input_trim_left)//min_code_len,2)=1)
					If (t:=SubStr(srf_Input_trim_left, 1, -2))&&(history_field_array[t, 1, 3]>=history_field_array[srf_Input_trim_left, 1, 3]){
						tlen-=min_code_len
						Continue
					}
				save_field_array.Push(CopyObj(history_field_array[srf_Input_trim_left])), index+=tlen
				Break
			}
			tlen-=min_code_len
		}
		If (tlen<min_code_len)
			Break
	}
	If (srf_Input_trim_left:=SubStr(srf_input, index))&&(StrLen(srf_Input_trim_left)<=min_code_len){
		If !history_field_array.HasKey(srf_Input_trim_left)
			history_field_array[srf_Input_trim_left]:=get_word(DB, srf_Input_trim_left, scheme)
		If (history_field_array[srf_Input_trim_left, 1, 2])
			save_field_array.Push(CopyObj(history_field_array[srf_Input_trim_left]))
		Else If (StrLen(srf_Input_trim_left)=1){
			If !history_field_array2.HasKey(srf_Input_trim_left)
				If history_field_array[srf_Input_trim_left, 1, 2]
					history_field_array2[srf_Input_trim_left]:=history_field_array[srf_Input_trim_left]
				Else
					history_field_array2[srf_Input_trim_left]:=get_word_lianxiang(DB, srf_Input_trim_left, scheme)
			save_field_array.Push(CopyObj(history_field_array2[srf_Input_trim_left]))
		}
	}
	comstr:=["",""], SearchResult:=[]
	Loop % tlen:=Min(max_code_len,StrLen(srf_input))
		If history_field_array[ci:=SubStr(srf_input, 1, tlen+1-A_Index), 1, 2]
			Break
	If (ci~="^" save_field_array[1, 0] "[a-z]+")
		SearchResult:=CopyObj(history_field_array[ci])
	Loop % save_field_array[1].Length()
		SearchResult.Push(save_field_array[1, A_Index])
	Loop % save_field_array.Length()
		comstr[2] .= save_field_array[A_Index, 1, 2]
	If SearchResult[1, 2]!=comstr[2]
		SearchResult.InsertAt(1, comstr)
	If (StrLen(fzm)=2), inspos:=2
		Loop % tt:=saixuan.Length()
			SearchResult.InsertAt(inspos,saixuan[tt+1-A_Index])	; 词组优先
	Else
		Loop % tt:=saixuan.Length()
			SearchResult.InsertAt(1,saixuan[tt+1-A_Index])	; 辅助词条优先
	Loop % srf_input_len
		If (zi:=SubStr(srf_input, 1, A_Index))=history_field_array[zi,1,1]
			Break
	If (zi!=srf_input)
		Loop % history_field_array[zi].Length()
			SearchResult.Push(CopyObj(history_field_array[zi, A_Index]))
	If (fuzhuma){
		Loop % SearchResult.Length()
			If InStr(SearchResult[A_Index, 0], scheme "|")&&(SearchResult[A_Index, 6]="")
				SearchResult[A_Index, 6]:=fzmfancha(SearchResult[A_Index, 2])
	}
	Return SearchResult
}

xingmazigen(chars, scheme){
	static xingma_dict:="", lastscheme:=""
	global ShowCode, YzIni
	If (lastscheme!=scheme){
		If (scheme="")
			xingma_dict:=""
		Else If !IsObject(xingma_dict){
			If FileExist("Lib\@" scheme ".txt"){
				FileRead, zigen, Lib\@%scheme%.txt
				xingma_dict:=[]
				Loop, Parse, zigen, `n, `r
					If (A_LoopField!="")
						xingma_dict[(tarr:=StrSplit(A_LoopField, "`t"))[1]]:=tarr[2]
			} Else {
				YzIni["Settings","ShowCode"]:=ShowCode:=ShowCode&1
				MsgBox, 16, 错误, Lib目录下缺少字根文件@%scheme%.txt！
				Return
			}
		}
		lastscheme:=scheme
	}
	index:=1, tarr:=[]
	While index:=RegExMatch(chars, "O)[^\x00-\xff]", match, index)
		tarr.Push(match.Value), index+=match.Len
	; msgbox
	Switch tarr.Length()
	{
		Case 0:
			Return ""
		Case 1:
			Return xingma_dict[chars]?" [" xingma_dict[chars] "]":""
		Case 2:
			tt:=""
			Loop 2
				If xingma_dict[tarr[A_Index]]
					tt .= ReSubStr(xingma_dict[tarr[A_Index]],1,2)
				Else
					Return ""
			Return " [" tt "]"
		Case 3:
			tt:=""
			Loop 3
				If xingma_dict[tarr[A_Index]]
					tt .= ReSubStr(xingma_dict[tarr[A_Index]],1,1)
				Else
					Return ""
			tt .= ReSubStr(xingma_dict[tarr[3]],2,1)
			Return " [" tt "]"
		Default:
			tt:=""
			Loop 3
				If xingma_dict[tarr[A_Index]]
					tt .= ReSubStr(xingma_dict[tarr[A_Index]],1,1)
				Else
					Return ""
			If xingma_dict[tarr[tarr.Length()]]
				tt .= ReSubStr(xingma_dict[tarr[tarr.Length()]],1,1)
			Else
				Return ""
			Return " [" tt "]"
	}
	Return ""
}

ReSubStr(str,Begin,Length:=0){
	Result:="", charnum:=0, index:=1
	While RegExMatch(str,".",Match,index){
		index+=StrLen(Match)
		If (A_Index<Begin)
			Continue
		Result .= Match, charnum++
		If (charnum=Length)
			Break
	}
	Return Result
}