private void ReadInstructions() { Labels.Clear(); _instructions.Clear(); using (var memory = new MemoryStream(_msilBytes)) using (var reader = new BinaryReader(memory)) while (memory.Length > memory.Position) { var opcodeOffset = (int)memory.Position; var instructionValue = (short)memory.ReadByte(); if (Prefixes.Contains(instructionValue)) { instructionValue = (short)((instructionValue << 8) | memory.ReadByte()); } if (!OpCodeLookup.TryGetValue(instructionValue, out OpCode opcode)) { var msg = $"Unknown opcode {instructionValue:X}"; _log.Error(msg); Debug.Assert(false, msg); continue; } if (opcode.Size != memory.Position - opcodeOffset) { throw new Exception( $"Opcode said it was {opcode.Size} but we read {memory.Position - opcodeOffset}"); } var instruction = new MsilInstruction(opcode) { Offset = opcodeOffset }; _instructions.Add(instruction); instruction.Operand?.Read(this, reader); } }
/// <summary> /// Determines whether <see cref="piece"/> is a given name component as opposed to an affix, initial or title. /// </summary> /// <param name="piece">A single word from a name</param> /// <returns>False if <see cref="piece"/> is a prefix (de, abu, bin), suffix (jr, iv, cpa), title (mr, pope), or initial (x, e.); true otherwise</returns> private static bool IsRootname(string piece) { var lcPiece = piece.ToLower().Replace(".", string.Empty); return(!Suffixes.Contains(lcPiece) && !Prefixes.Contains(lcPiece) && !Titles.Contains(lcPiece) && !IsAnInitial(piece)); }
public void AddPrefix(string prefix) { if (Prefixes.Contains(prefix)) { throw new Exception("Prefix already exists."); } else { Prefixes.Add(prefix); } }
public void RemovePrefix(string prefix) { if (!Prefixes.Contains(prefix)) { throw new Exception("This is not a prefix in this server."); } else { Prefixes.Remove(prefix); } }
private bool TryExtractQueryFromRange(ITextRange range, out string prefix, out string query) { prefix = string.Empty; query = string.Empty; range.GetText(TextGetOptions.NoHidden, out var possibleQuery); if (possibleQuery.Length > 0 && Prefixes.Contains(possibleQuery[0]) && !possibleQuery.Any(char.IsWhiteSpace) && string.IsNullOrEmpty(range.Link)) { if (possibleQuery.Length == 1) { prefix = possibleQuery; return(true); } prefix = possibleQuery[0].ToString(); query = possibleQuery.Substring(1); return(true); } return(false); }
private bool RemovePrefixIfStringContains(ref string str) { if (Prefixes == null) { return(false); } bool contain = false; foreach (int count in PrefixesCount) { //contains some of the configurated prefixes contain = Prefixes.Contains(str.Substring(0, count)); if (contain) { str = str.Remove(0, count); return(contain); } } return(contain); }
private bool IsPrefix(string prefix) { return(Prefixes.Contains(prefix)); }
private static bool IsPrefix(string piece) { return(Prefixes.Contains(piece.ToLower().Replace(".", string.Empty)) && !IsAnInitial(piece)); }
private bool KeysContainsSomePrePostfix(IDictionary <string, object> dict) { if (Prefixes != null && Postfixes != null) { return(dict.Any(kvp => { foreach (int count in PrefixesCount) { //contains some of the configurated prefixes or postfixes if (Prefixes.Contains(kvp.Key.Substring(0, count)) || Postfixes.Contains(kvp.Key.Substring(kvp.Key.Length - count, count))) { return true; } else { return false; } } return false; })); } else if (Prefixes != null) { return(dict.Any(kvp => { foreach (int count in PrefixesCount) { //contains some of the configurated prefixes if (Prefixes.Contains(kvp.Key.Substring(0, count))) { return true; } else { return false; } } return false; })); } else if (Postfixes != null) { return(dict.Any(kvp => { foreach (int count in PrefixesCount) { //contains some of the configurated postfixes if (Postfixes.Contains(kvp.Key.Substring(kvp.Key.Length - count, count))) { return true; } else { return false; } } return false; })); } return(false); //return dict.Any(kvp => (Prefixes.Contains(kvp.Key.Substring(0,) }
public override Task <bool> ExecuteCheckAsync(CommandContext ctx, bool help) => Task.FromResult((help && ShowInHelp) || Prefixes.Contains(ctx.Prefix));