public void WriteForEdit(string aWritePath, Encoding aCodePage) { using (var writeFile = new StreamWriter(aWritePath, false, aCodePage)) { using (var lineParser = new LineParser(mHeaderPath, aCodePage)) { while (lineParser.HasNext()) { var line = lineParser.GetNext(); var words = line.Name.Split(Constants.kSplitTokens, StringSplitOptions.RemoveEmptyEntries); if (words.Length == 0) { writeFile.WriteLine(line.Serialize()); continue; } if (words[0].Equals("#define") && words[1].Equals(SearchedName) && words[2].Equals(TestItem.ID.Value)) { writeFile.WriteLine(TestItem.SerializeForHeader()); } else { writeFile.WriteLine(line.Serialize()); } } } } }
public static IEnumerable <string> ExtractHeaderNames(string aPath, Encoding aCodePage) { var headerNames = new List <string>(); using (var lineParser = new LineParser(aPath, aCodePage)) { while (lineParser.HasNext()) { var line = lineParser.GetNext(); string[] words = line.Name.Split(Constants.kSplitTokens, StringSplitOptions.RemoveEmptyEntries); if (words.Length == 0) { continue; } if (words[0] == "#include" && words.Length >= 2 && !words[1].StartsWith("<") && !words[1].EndsWith(">")) { words[1] = words[1].Trim('\"'); headerNames.Add(words[1]); } else if (words[0] == "BEGIN") { return(headerNames); } } return(headerNames); } }
private void WriteUntilStringTables(StreamWriter aWriteFile, LineParser aLineParser) { while (aLineParser.HasNext()) { var line = aLineParser.GetNext(); if (line.Name == "STRINGTABLE") { break; } aWriteFile.WriteLine(line.Serialize()); } }
public void Write(string aWritePath, Encoding aCodePage) { using (var writeFile = new StreamWriter(aWritePath, false, aCodePage)) { var stringTableContent = mRCFileContent.StringTableContent; var stringTableIndexOrder = mRCFileContent.StringTableIndexOrder; using (var lineParser = new LineParser(mRCPath, aCodePage)) { WriteUntilStringTables(writeFile, lineParser); WriteStringTables(writeFile, stringTableContent, stringTableIndexOrder); WriteUntilEnd(writeFile, lineParser); } } }
private void WriteUntilEnd(StreamWriter aWriteFile, LineParser aLineParser) { while (aLineParser.HasNext()) { var line = aLineParser.GetNext(); if (line.Name.Length > 0 && line.Name[0] == '#') { aWriteFile.WriteLine(line.Serialize()); break; } } while (aLineParser.HasNext()) { aWriteFile.WriteLine(aLineParser.GetNext().Serialize()); } }
public static Encoding GetCodePage(string aPath) { using (var lineParser = new LineParser(aPath)) { while (lineParser.HasNext()) { var line = lineParser.GetNext(); string[] words = line?.Name.Split(Constants.kSplitTokens, StringSplitOptions.RemoveEmptyEntries); if (words.Length == 0) { continue; } if (words[0] == "#pragma") { return(Encoding.GetEncoding(Convert.ToInt32(Regex.Match(words[1], @"\d+").Value))); } } return(Encoding.GetEncoding(0)); } }
public void WriteForAdd(string aWritePath, Encoding aCodePage, int aNumberOfElementsInHeader) { using (var writeFile = new StreamWriter(aWritePath, false, aCodePage)) { using (var lineParser = new LineParser(mHeaderPath, aCodePage)) { var lineCount = -1; var ignoreValue = 0; LineParserResult line = null; while (lineParser.HasNext()) { line = lineParser.GetNext(); var words = line.Name.Split(Constants.kSplitTokens, StringSplitOptions.RemoveEmptyEntries); if (words.Length == 0) { writeFile.WriteLine(line.Serialize()); continue; } if (words[0].StartsWith("#if")) { ++ignoreValue; } else if (words[0].StartsWith("#endif") && ignoreValue > 0) { --ignoreValue; } if (ignoreValue > 0 || words[0] != "#define") { writeFile.WriteLine(line.Serialize()); continue; } ++lineCount; if (lineCount == FoundIndex) { break; } writeFile.WriteLine(line.Serialize()); if (lineCount + 2 == aNumberOfElementsInHeader) { break; } } writeFile.WriteLine(TestItem.SerializeForHeader()); // Check for no extra writing if (lineCount == FoundIndex) { writeFile.WriteLine(line.Serialize()); } while (lineParser.HasNext()) { writeFile.WriteLine(lineParser.GetNext().Serialize()); } } } }