public static Parse ( |
||
reader | The reader from which a CppCheck error shall be read. | |
strings | Strings used to parse the CppCheck log. | |
리턴 |
public static CppCheckError Parse(XmlReader reader, CppCheckStrings strings)
{
if (!reader.IsStartElement(strings.Error))
{
throw reader.CreateException(ConverterResources.CppCheckElementNotError);
}
string id = null;
string message = null;
string verboseMessage = null;
string severity = null;
while (reader.MoveToNextAttribute())
{
string attributeName = reader.LocalName;
if (Ref.Equal(attributeName, strings.Id))
{
id = reader.Value;
}
else if (Ref.Equal(attributeName, strings.Msg))
{
message = reader.Value;
}
else if (Ref.Equal(attributeName, strings.Verbose))
{
verboseMessage = reader.Value;
}
else if (Ref.Equal(attributeName, strings.Severity))
{
severity = reader.Value;
}
}
reader.MoveToElement();
ImmutableArray<CppCheckLocation> locations = ParseLocationsSubtree(reader, strings);
reader.Read(); // Consumes the end element or self closing element and positions the reader on the next node
try
{
return new CppCheckError(
id,
message,
verboseMessage,
severity,
locations
);
}
catch (ArgumentException ex)
{
throw reader.CreateException(ex.Message);
}
}
private void ProcessCppCheckLog(XmlReader reader, IResultLogWriter issueWriter) { reader.ReadStartElement(_strings.Results); if (!Ref.Equal(reader.LocalName, _strings.CppCheck)) { throw reader.CreateException(SarifResources.CppCheckCppCheckElementMissing); } string version = reader.GetAttribute(_strings.Version); if (String.IsNullOrWhiteSpace(version)) { throw reader.CreateException(SarifResources.CppCheckCppCheckElementMissing); } issueWriter.WriteToolAndRunInfo(new ToolInfo { Name = "CppCheck", Version = version, }, null); reader.Skip(); // <cppcheck /> if (!Ref.Equal(reader.LocalName, _strings.Errors)) { throw reader.CreateException(SarifResources.CppCheckErrorsElementMissing); } if (reader.IsEmptyElement) { reader.Skip(); // <errors /> } else { int errorsDepth = reader.Depth; reader.Read(); // <errors> while (reader.Depth > errorsDepth) { var parsedError = CppCheckError.Parse(reader, _strings); issueWriter.WriteResult(parsedError.ToSarifIssue()); } reader.ReadEndElement(); // </errors> } reader.ReadEndElement(); // </results> }