Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using DocumentFormat.OpenXml.Framework;
using System.Text;

namespace DocumentFormat.OpenXml.Validation.Semantic
{
Expand Down Expand Up @@ -59,17 +60,20 @@ public AttributeAbsentConditionToNonValue(OpenXmlQualifiedName absentAttribute,
}
}

string valueString = "'" + _values[0] + "'";
var sb = new StringBuilder();
sb.Append('\'').Append(_values[0]).Append('\'');
if (_values.Length > 1)
{
for (int i = 1; i < _values.Length - 1; i++)
{
valueString += ", '" + _values[i] + "'";
sb.Append(", '").Append(_values[i]).Append('\'');
}

valueString += " and '" + _values[_values.Length - 1] + "'";
sb.Append(" and '").Append(_values[_values.Length - 1]).Append('\'');
}

string valueString = sb.ToString();

return new ValidationErrorInfo()
{
Id = "Sem_AttributeAbsentConditionToNonValue",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using DocumentFormat.OpenXml.Framework;
using System.Text;

namespace DocumentFormat.OpenXml.Validation.Semantic
{
Expand Down Expand Up @@ -55,17 +56,20 @@ public AttributeAbsentConditionToValue(OpenXmlQualifiedName absentAttribute, Ope
{
if (AttributeValueEquals(conditionAttribute.Value, value, false))
{
string valueString = "'" + _values[0] + "'";
var sb = new StringBuilder();
sb.Append('\'').Append(_values[0]).Append('\'');
if (_values.Length > 1)
{
for (int i = 1; i < _values.Length - 1; i++)
{
valueString += ", '" + _values[i] + "'";
sb.Append(", '").Append(_values[i]).Append('\'');
}

valueString += " or '" + _values[_values.Length - 1] + "'";
sb.Append(" or '").Append(_values[_values.Length - 1]).Append('\'');
}

string valueString = sb.ToString();

return new ValidationErrorInfo()
{
Id = "Sem_AttributeAbsentConditionToValue",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using DocumentFormat.OpenXml.Framework;
using System.Text;

namespace DocumentFormat.OpenXml.Validation.Semantic
{
Expand Down Expand Up @@ -57,13 +58,18 @@ private AttributeMutualExclusive(OpenXmlQualifiedName[] attributes)
return null;
}

var attributes = string.Empty;
var existAttribute = string.Empty;
var existAttribute2 = string.Empty;
var attributesSb = new StringBuilder();
var existAttributeSb = new StringBuilder();
string? existAttribute2 = null;

foreach (var attribute in _attributes)
{
attributes += "," + attribute;
if (attributesSb.Length > 0)
{
attributesSb.Append(',');
}

attributesSb.Append(attribute);

if (!TryFindAttribute(element, attribute, out var found))
{
Expand All @@ -72,16 +78,21 @@ private AttributeMutualExclusive(OpenXmlQualifiedName[] attributes)

if (found.Value is not null)
{
if (!string.IsNullOrEmpty(existAttribute2))
if (existAttribute2 is not null)
{
existAttribute += "," + existAttribute2;
if (existAttributeSb.Length > 0)
{
existAttributeSb.Append(',');
}

existAttributeSb.Append(existAttribute2);
}

existAttribute2 = found.ToString();
}
}

if (string.IsNullOrEmpty(existAttribute))
if (existAttributeSb.Length == 0)
{
return null;
}
Expand All @@ -93,9 +104,9 @@ private AttributeMutualExclusive(OpenXmlQualifiedName[] attributes)
Node = element,
Description = SR.Format(
ValidationResources.Sem_AttributeMutualExclusive,
existAttribute.Substring(1),
existAttributeSb.ToString(),
existAttribute2,
attributes.Substring(1)),
attributesSb.ToString()),
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using DocumentFormat.OpenXml.Framework;
using System.Text;

namespace DocumentFormat.OpenXml.Validation.Semantic
{
Expand Down Expand Up @@ -65,28 +66,34 @@ public AttributeValueConditionToAnother(OpenXmlQualifiedName attribute, OpenXmlQ
{
if (AttributeValueEquals(conditionAttribute.Value, value, false))
{
string attributeValueString = "'" + _values[0] + "'";
var sb = new StringBuilder();
sb.Append('\'').Append(_values[0]).Append('\'');
if (_values.Length > 1)
{
for (int i = 1; i < _values.Length - 1; i++)
{
attributeValueString += ", '" + _values[i] + "'";
sb.Append(", '").Append(_values[i]).Append('\'');
}

attributeValueString += " or '" + _values[_values.Length - 1] + "'";
sb.Append(" or '").Append(_values[_values.Length - 1]).Append('\'');
}

string otherAttributeValueString = "'" + _otherValues[0] + "'";
string attributeValueString = sb.ToString();

var otherSb = new StringBuilder();
otherSb.Append('\'').Append(_otherValues[0]).Append('\'');
if (_otherValues.Length > 1)
{
for (int i = 1; i < _otherValues.Length - 1; i++)
{
otherAttributeValueString += ", '" + _otherValues[i] + "'";
otherSb.Append(", '").Append(_otherValues[i]).Append('\'');
}

otherAttributeValueString += " or '" + _otherValues[_otherValues.Length - 1] + "'";
otherSb.Append(" or '").Append(_otherValues[_otherValues.Length - 1]).Append('\'');
}

string otherAttributeValueString = otherSb.ToString();

return new ValidationErrorInfo()
{
Id = "Sem_AttributeValueConditionToAnother",
Expand Down
Loading