Browse Source

[Ast] Fixed end location of multi line strings.

newNRvisualizers
Mike Krüger 13 years ago
parent
commit
6c62b5b2c3
  1. 35
      ICSharpCode.NRefactory.CSharp/Ast/Expressions/PrimitiveExpression.cs
  2. 4
      ICSharpCode.NRefactory.CSharp/ICSharpCode.NRefactory.CSharp.csproj

35
ICSharpCode.NRefactory.CSharp/Ast/Expressions/PrimitiveExpression.cs

@ -43,9 +43,14 @@ namespace ICSharpCode.NRefactory.CSharp @@ -43,9 +43,14 @@ namespace ICSharpCode.NRefactory.CSharp
}
string literalValue;
TextLocation? endLocation;
public override TextLocation EndLocation {
get {
return new TextLocation (StartLocation.Line, StartLocation.Column + literalValue.Length);
if (!endLocation.HasValue) {
endLocation = value is string ? AdvanceLocation (StartLocation, literalValue) :
new TextLocation (StartLocation.Line, StartLocation.Column + literalValue.Length);
}
return endLocation.Value;
}
}
@ -103,6 +108,34 @@ namespace ICSharpCode.NRefactory.CSharp @@ -103,6 +108,34 @@ namespace ICSharpCode.NRefactory.CSharp
return visitor.VisitPrimitiveExpression (this, data);
}
unsafe static TextLocation AdvanceLocation(TextLocation startLocation, string str)
{
int line = startLocation.Line;
int col = startLocation.Column;
fixed (char* start = str) {
char* p = start;
char* endPtr = start + str.Length;
while (p < endPtr) {
switch (*p) {
case '\r':
char* nextp = p + 1;
if (nextp < endPtr && *nextp == '\n')
p++;
goto case '\n';
case '\n':
line++;
col = 1;
break;
default:
col++;
break;
}
p++;
}
}
return new TextLocation (line, col);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
PrimitiveExpression o = other as PrimitiveExpression;

4
ICSharpCode.NRefactory.CSharp/ICSharpCode.NRefactory.CSharp.csproj

@ -42,10 +42,12 @@ @@ -42,10 +42,12 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>PdbOnly</DebugType>
<DebugSymbols>false</DebugSymbols>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugType>Full</DebugType>
<DebugSymbols>true</DebugSymbols>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'net_4_5_Debug' ">
<Optimize>False</Optimize>
@ -56,6 +58,7 @@ @@ -56,6 +58,7 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_4_5_Debug|AnyCPU' ">
<DebugType>Full</DebugType>
<DebugSymbols>true</DebugSymbols>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'net_4_5_Release' ">
<Optimize>True</Optimize>
@ -66,6 +69,7 @@ @@ -66,6 +69,7 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_4_5_Release|AnyCPU' ">
<DebugType>PdbOnly</DebugType>
<DebugSymbols>false</DebugSymbols>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />

Loading…
Cancel
Save