
xingmamethod(srf_input,scheme){
	global
	local Loop_num, t, tt, tem, key, value, cutpos, zi, srf_Input_trim_left, srf_Input_trim_right
		, srf_all_Input_len, srf_all_Input_trim, srf_all_Input_trim_off, index
		, tpos, zisu, tarr, jichu_for_select, Loop_num:=0, history_cutpos:=[0], index:=0, checkstr:=""
	;qu ci bing qie fen
	srf_all_Input_tooltip:=srf_all_Input_trim:=srf_input
	; 正向
	Loop % save_field_array.Length()
	{
		If (save_field_array[A_Index,0]=""){
			index:=A_Index
			Break
		}
		checkstr .= save_field_array[A_Index,0]
		If InStr("^" srf_input, "^" checkstr){
			history_cutpos.Push(StrLen(checkstr))
		} Else {
			index:=A_Index
			Break
		}
	}
	If (index)
		save_field_array.RemoveAt(index, save_field_array.Length()-index+1)
	srf_all_Input_len:=StrLen(srf_input)
	If (save_field_array.Length()>0){
		; If history_cutpos.Length()>1&&SubStr(srf_input,history_cutpos[history_cutpos.Length()],1)!="'"
		; 	history_cutpos.Pop(), save_field_array.Pop()
		Loop % history_cutpos.Length()
		{
			If ((srf_all_Input_trim_off:=SubStr(srf_input,history_cutpos[A_Index]+1))="")
				Break
			If StrLen(srf_all_Input_trim_off)>16
				Continue
			
			If !history_field_array.HasKey(srf_all_Input_trim_off){
				jichu_for_select:=get_word(DB, srf_all_Input_trim_off, scheme)
				If (jichu_for_select[1, 2]=""){
					If (StrLen(srf_all_Input_trim_off)>2){
						history_field_array[srf_all_Input_trim_off]:={0:srf_all_Input_trim_off}
						Continue
					} Else {
						Break
					}
				}
			} Else
				jichu_for_select:=history_field_array[srf_all_Input_trim_off]
			If (jichu_for_select[1, 2]=""){
				If (StrLen(srf_all_Input_trim_off)>1)
					Continue
				Else
					Break
			} Else {
				jichu_for_select[0]:=srf_all_Input_trim_off
				history_field_array[srf_all_Input_trim_off]:=jichu_for_select
				tarr:={}, Ln:=A_Index-1
				Loop % Ln
					If save_field_array[A_Index, 0]
						tarr.Push(save_field_array[A_Index])
				tarr.Push(jichu_for_select)
				save_field_array:=tarr, tarr:="", history_cutpos:=[0]
				Loop % save_field_array.Length()
					history_cutpos[A_Index+1]:=history_cutpos[A_Index]+StrLen(save_field_array[A_Index,0])+1
			}
		}
	}
	If (tpos:=history_cutpos[history_cutpos.Length()])<srf_all_Input_len
	{
		cutpos:=srf_all_Input_len+1
		Loop
		{
			If (cutpos-=1)<tpos+1
				Break
			srf_Input_trim_left:=SubStr(srf_input,tpos+1,cutpos-tpos)
			; ToolTip % tpos "|" cutpos "|" srf_Input_trim_left
			If StrLen(srf_Input_trim_left)>16
				Continue
			srf_Input_trim_right:=SubStr(srf_input,cutpos+1)
			If srf_Input_trim_left&&!history_field_array.HasKey(srf_Input_trim_left){
				jichu_for_select:=get_word(DB, srf_Input_trim_left, scheme)
				If (jichu_for_select[1, 2]=""){
					history_field_array[srf_Input_trim_left]:={0:srf_Input_trim_left}
					If (StrLen(srf_Input_trim_left)>1)
						Continue
					Else
						Break
				} Else
					history_field_array[srf_Input_trim_left]:=jichu_for_select, history_field_array[srf_Input_trim_left, 0]:=srf_Input_trim_left
			}
			If (history_field_array[srf_Input_trim_left, 1, 2]="")||(srf_Input_trim_right&&(SubStr(srf_Input_trim_left,0)=SubStr(history_field_array[srf_Input_trim_left,1,1],-2,1)))
				Continue
			If (srf_Input_trim_left!="")
				save_field_array.Push(history_field_array[srf_Input_trim_left]), history_cutpos[history_cutpos.Length()+1]:=history_cutpos[history_cutpos.Length()]+StrLen(srf_Input_trim_left)
			; history_cutpos:=[0]
			; Loop % save_field_array.Length()
			; 	history_cutpos[A_Index+1]:=history_cutpos[A_Index]+StrLen(save_field_array[A_Index,0])+1
			tpos:=history_cutpos[history_cutpos.Length()], cutpos:=srf_all_Input_len+1
		}
	}
	;zu he
	jichu_for_select:="", jichu_for_select_Array:=[]
	jichu_for_select_Array:=firstzhuju(save_field_array)
	jichu_for_select_Array[1,1]:=StrReplace(jichu_for_select_Array[1,1],"'"," ")

	If InStr(jichu_for_select_Array[1, 1], " "){
		zi:=SubStr(srf_input ,1, 3)
		If (history_field_array[zi,1,1]="")
			If (history_field_array[zi:=SubStr(zi,1,2),1,1]="")
				zi:=""
		Loop % history_field_array[zi].Length()
			jichu_for_select_Array.Push(CopyObj(history_field_array[zi, A_Index]))
	}
	If (jichu_for_select_Array[1, 0]="")
		jichu_for_select_Array[1, 0]:=scheme
	; If CloudInput&&(StrLen(jichu_for_select_Array[1, 2])>3)
	; 	SetTimer, BDCloudInput, -10
	Return
}

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
}