diff --git a/src/DocumentFormat.OpenXml.Framework/Validation/Semantic/AttributeAbsentConditionToNonValue.cs b/src/DocumentFormat.OpenXml.Framework/Validation/Semantic/AttributeAbsentConditionToNonValue.cs index a7639eb1d..74bf90d85 100644 --- a/src/DocumentFormat.OpenXml.Framework/Validation/Semantic/AttributeAbsentConditionToNonValue.cs +++ b/src/DocumentFormat.OpenXml.Framework/Validation/Semantic/AttributeAbsentConditionToNonValue.cs @@ -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 { @@ -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", diff --git a/src/DocumentFormat.OpenXml.Framework/Validation/Semantic/AttributeAbsentConditionToValue.cs b/src/DocumentFormat.OpenXml.Framework/Validation/Semantic/AttributeAbsentConditionToValue.cs index d4221913a..0bd5f3c0d 100644 --- a/src/DocumentFormat.OpenXml.Framework/Validation/Semantic/AttributeAbsentConditionToValue.cs +++ b/src/DocumentFormat.OpenXml.Framework/Validation/Semantic/AttributeAbsentConditionToValue.cs @@ -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 { @@ -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", diff --git a/src/DocumentFormat.OpenXml.Framework/Validation/Semantic/AttributeMutualExclusive.cs b/src/DocumentFormat.OpenXml.Framework/Validation/Semantic/AttributeMutualExclusive.cs index 1197ee40f..8ad401a7c 100644 --- a/src/DocumentFormat.OpenXml.Framework/Validation/Semantic/AttributeMutualExclusive.cs +++ b/src/DocumentFormat.OpenXml.Framework/Validation/Semantic/AttributeMutualExclusive.cs @@ -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 { @@ -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)) { @@ -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; } @@ -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()), }; } } diff --git a/src/DocumentFormat.OpenXml.Framework/Validation/Semantic/AttributeValueConditionToAnother.cs b/src/DocumentFormat.OpenXml.Framework/Validation/Semantic/AttributeValueConditionToAnother.cs index e1380a2cc..37744f78f 100644 --- a/src/DocumentFormat.OpenXml.Framework/Validation/Semantic/AttributeValueConditionToAnother.cs +++ b/src/DocumentFormat.OpenXml.Framework/Validation/Semantic/AttributeValueConditionToAnother.cs @@ -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 { @@ -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",