public bool Income(string chr) { if (kp == null) { return(false); } if (chr == "") { return(false); } KeyProcessorReturn x = kp.ProcessKey(chr); if (x == null) { if (chr == "delete") { Output("{BS}"); bf.PopChars(1); return(true); } else if (chr == "{BEEP}") { beep(); return(true); } else { Output(chr); bf.Append(chr); return(true); } } else { if (x.beep) { beep(); } // Better Optimized Method Needed for (int i = 0; i < x.leftcontext.Length; i++) { Output("{BS}"); } bf.PopChars(x.leftcontext.Length); bf.Append(x.output); Output(x.output); return(true); } }
public KeyProcessorReturn ProcessKey(string c) { KeyProcessorReturn kpr = new KeyProcessorReturn(); string btmp = buffer.getBuffer(); ArrayList matchs = new ArrayList(); for (int i = 0; i < Keys.Count; i++) { string k = (string)Keys[i]; string lcontext = (string)LeftContext[i]; if (k == c) { if (lcontext.Length == 0) { if (btmp.Length == 0) { kpr.key = c; kpr.leftcontext = ""; kpr.output = (string)Output[i]; kpr.beep = processOutput(kpr.output); kpr.output = kpr.output.Replace("_#_beep", ""); kpr.output = kpr.output.Replace("_#_null", ""); return kpr; } else { matchs.Add(i); } } else { string samelenbuf = ProcessBuffer(lcontext, btmp); if (lcontext.Equals(samelenbuf)) { matchs.Add(i); } } } } if (matchs.Count > 0) { int kpid = (int)matchs[0]; for (int i = 0; i < matchs.Count; i++) { string a = (string)LeftContext[kpid]; int x = (int)matchs[i]; string b = (string)LeftContext[x]; if (b.Length > a.Length) kpid = x; } kpr.key = c; kpr.leftcontext = (string)LeftContext[kpid]; kpr.output = (string)Output[kpid]; kpr.beep = processOutput(kpr.output); kpr.output = kpr.output.Replace("_#_beep", ""); kpr.output = kpr.output.Replace("_#_null", ""); return kpr; } return null; }
public KeyProcessorReturn ProcessKey(string c) { KeyProcessorReturn kpr = new KeyProcessorReturn(); string btmp = buffer.getBuffer(); ArrayList matchs = new ArrayList(); for (int i = 0; i < Keys.Count; i++) { string k = (string)Keys[i]; string lcontext = (string)LeftContext[i]; if (k == c) { if (lcontext.Length == 0) { if (btmp.Length == 0) { kpr.key = c; kpr.leftcontext = ""; kpr.output = (string)Output[i]; kpr.beep = processOutput(kpr.output); kpr.output = kpr.output.Replace("_#_beep", ""); kpr.output = kpr.output.Replace("_#_null", ""); return(kpr); } else { matchs.Add(i); } } else { string samelenbuf = ProcessBuffer(lcontext, btmp); if (lcontext.Equals(samelenbuf)) { matchs.Add(i); } } } } if (matchs.Count > 0) { int kpid = (int)matchs[0]; for (int i = 0; i < matchs.Count; i++) { string a = (string)LeftContext[kpid]; int x = (int)matchs[i]; string b = (string)LeftContext[x]; if (b.Length > a.Length) { kpid = x; } } kpr.key = c; kpr.leftcontext = (string)LeftContext[kpid]; kpr.output = (string)Output[kpid]; kpr.beep = processOutput(kpr.output); kpr.output = kpr.output.Replace("_#_beep", ""); kpr.output = kpr.output.Replace("_#_null", ""); return(kpr); } return(null); }