/// <summary> /// 从一串字符中解析出CSI的parameter,intermediate,final数据 /// </summary> /// <param name="bytes">要解析的bytes</param> /// <param name="parameter"></param> /// <param name="intermediate"></param> /// <param name="final"></param> /// <returns></returns> public static bool ParseCSI(byte[] chars, out ParameterBytes parameter, out IntermediateBytes intermediate, out FinalByte final) { final.PrivateUse = false; final.Char = 0; final.WithIntermediateByte0200 = false; bool isCsiStart = false; bool is7BitAscii = true; int length = chars.Length; List <byte> pBytes = new List <byte>(); // parameterBytes List <byte> iBytes = new List <byte>(); // intermediateBytes for (int idx = 0; idx < length; idx++) { byte c = chars[idx]; if (isCsiStart) { if (ParameterBytes.IsParameterByte(c)) { pBytes.Add(c); } if (IntermediateBytes.IsIntermediateByte(c)) { iBytes.Add(c); } if (FinalByte.IsFinalByte(c, out final.PrivateUse, out final.WithIntermediateByte0200)) { return(true); } } else { if (c == Fe.CSI_8BIT) { is7BitAscii = false; isCsiStart = true; continue; } if (c != ControlFunctions.ESC) { continue; } if (chars[idx + 1] == Fe.CSI_7BIT) { isCsiStart = true; } } } return(false); }
public override bool Parse(byte[] chars, int offset, out ControlFunctionParserResult result, out int funcEndIdx) { result.FeChar = 0; result.FunctionContent = null; result.ControlFunction = 0; funcEndIdx = 0; int length = chars.Length; byte fe = chars[offset + 1]; if (!Fe.Is7bitFe(fe)) { return(false); } if (fe == Fe.CSI_7BIT) { #region 解析CSI命令 if (fe == Fe.CSI_7BIT) { int charsSize = 0; bool privateUse = false; bool withIntermediateByte0200 = false; for (int idx = offset + 1; idx < length; idx++) { charsSize++; if (FinalByte.IsFinalByte(chars[idx], out privateUse, out withIntermediateByte0200)) { result.FeChar = fe; result.FunctionContent = new byte[charsSize]; Array.Copy(chars, offset + 1, result.FunctionContent, 0, result.FunctionContent.Length); funcEndIdx = idx; return(true); } } } #endregion } else if (fe == Fe.OSC_7BIT) { #region 解析OSC命令 int charsSize = 0; for (int idx = offset + 1; idx < length; idx++) { charsSize++; if (OSC.IsTerminatedChar(chars[idx])) { result.FeChar = fe; result.FunctionContent = new byte[charsSize]; Array.Copy(chars, offset + 1, result.FunctionContent, 0, result.FunctionContent.Length); funcEndIdx = idx; return(true); } } #endregion } logger.ErrorFormat("解析7位编码Fe'{0}'失败", fe); return(false); }