Browse Source

Fixed bugs in XmlParser when getting the attribute value and attribute name when the attribute value contains an equals sign.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4247 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 16 years ago
parent
commit
85e78d6762
  1. 21
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlParser.cs
  2. 2
      src/AddIns/DisplayBindings/XmlEditor/Test/Parser/AttributeValueUnderCursorTests.cs

21
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlParser.cs

@ -243,12 +243,15 @@ namespace ICSharpCode.XmlEditor @@ -243,12 +243,15 @@ namespace ICSharpCode.XmlEditor
}
// Find equals sign.
bool foundQuoteChar = false;
for (int i = index; i > elementStartIndex; --i) {
char ch = xml[i];
if (ch == '=') {
if (ch == '=' && foundQuoteChar) {
index = i;
ignoreEqualsSign = true;
break;
} else if (IsQuoteChar(ch)) {
foundQuoteChar = true;
}
}
} else {
@ -364,11 +367,14 @@ namespace ICSharpCode.XmlEditor @@ -364,11 +367,14 @@ namespace ICSharpCode.XmlEditor
// Find equals sign.
int equalsSignIndex = -1;
bool foundQuoteChar = false;
for (int i = index; i > elementStartIndex; --i) {
char ch = xml[i];
if (ch == '=') {
if (ch == '=' && foundQuoteChar) {
equalsSignIndex = i;
break;
} else if (IsQuoteChar(ch)) {
foundQuoteChar = true;
}
}
@ -378,12 +384,12 @@ namespace ICSharpCode.XmlEditor @@ -378,12 +384,12 @@ namespace ICSharpCode.XmlEditor
// Find attribute value.
char quoteChar = ' ';
bool foundQuoteChar = false;
foundQuoteChar = false;
StringBuilder attributeValue = new StringBuilder();
for (int i = equalsSignIndex; i < xml.Length; ++i) {
char ch = xml[i];
if (!foundQuoteChar) {
if (ch == '\"' || ch == '\'') {
if (IsQuoteChar(ch)) {
quoteChar = ch;
foundQuoteChar = true;
}
@ -391,7 +397,7 @@ namespace ICSharpCode.XmlEditor @@ -391,7 +397,7 @@ namespace ICSharpCode.XmlEditor
if (ch == quoteChar) {
// End of attribute value.
return attributeValue.ToString();
} else if (IsAttributeValueChar(ch) || (ch == '\"' || ch == '\'')) {
} else if (IsAttributeValueChar(ch) || IsQuoteChar(ch)) {
attributeValue.Append(ch);
} else {
// Invalid character found.
@ -783,5 +789,10 @@ namespace ICSharpCode.XmlEditor @@ -783,5 +789,10 @@ namespace ICSharpCode.XmlEditor
}
return new XmlElementPath();
}
static bool IsQuoteChar(char ch)
{
return (ch == '\"') || (ch == '\'');
}
}
}

2
src/AddIns/DisplayBindings/XmlEditor/Test/Parser/AttributeValueUnderCursorTests.cs

@ -85,6 +85,8 @@ namespace XmlEditor.Tests.Parser @@ -85,6 +85,8 @@ namespace XmlEditor.Tests.Parser
string xaml = "<Test val1=\"{Binding Value, Path=Control}\" />";
int offset = "<Test val1=\"{Binding Value, Path=".Length;
Assert.IsTrue(XmlParser.IsInsideAttributeValue(xaml, offset));
Assert.AreEqual("{Binding Value, Path=Control}", XmlParser.GetAttributeValueAtIndex(xaml, offset));
Assert.AreEqual("val1", XmlParser.GetAttributeNameAtIndex(xaml, offset));
}
[Test]

Loading…
Cancel
Save