1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 17:56:01 +02:00

Bug 329196 - Incorrect highlighting of strings with #defines inside

This commit is contained in:
Anton Leherbauer 2010-11-03 13:49:12 +00:00
parent 63365064b7
commit c465508c81
2 changed files with 51 additions and 9 deletions

View file

@ -1189,6 +1189,24 @@ public class CPartitionerTest extends TestCase {
}
}
public void testString2() {
try {
fDocument.replace(0, fDocument.getLength(), "\"string\"RRRRRRRR\"string\"nostring");
ITypedRegion[] result= fDocument.computePartitioning(0, fDocument.getLength());
TypedRegion[] expectation= {
new TypedRegion(0, 8, ICPartitions.C_STRING),
new TypedRegion(8, 8, IDocument.DEFAULT_CONTENT_TYPE),
new TypedRegion(16, 8, ICPartitions.C_STRING),
new TypedRegion(24, 8, IDocument.DEFAULT_CONTENT_TYPE)
};
checkPartitioning(expectation, result);
} catch (BadLocationException x) {
assertTrue(false);
}
}
public void testRawString1() {
try {

View file

@ -63,6 +63,7 @@ public final class FastCPartitionScanner implements IPartitionTokenScanner, ICPa
private static final int BACKSLASH_CR= 6; // postfix for STRING, CHARACTER and SINGLE_LINE_COMMENT
private static final int BACKSLASH_BACKSLASH= 7; // postfix for STRING, CHARACTER
private static final int RAW_STRING_R= 8; // prefix for RAW_STRING
private static final int IDENT= 9;
/** The scanner. */
private final BufferedDocumentScanner fScanner= new BufferedDocumentScanner(1000); // faster implementation
@ -210,13 +211,6 @@ public final class FastCPartitionScanner implements IPartitionTokenScanner, ICPa
continue;
}
case 'R':
if (fState == CCODE) {
fLast = RAW_STRING_R;
}
fTokenLength++;
continue;
default:
if (fLast == CARRIAGE_RETURN) {
switch (fState) {
@ -343,6 +337,24 @@ public final class FastCPartitionScanner implements IPartitionTokenScanner, ICPa
break;
}
case 'u':
case 'U':
case 'L':
if (fLast != IDENT) {
fLast = NONE;
}
fTokenLength++;
continue;
case 'R':
if (fLast == RAW_STRING_R) {
fLast = IDENT;
} else if (fLast != IDENT) {
fLast = RAW_STRING_R;
}
fTokenLength++;
continue;
case '"':
int newState = STRING;
if (fLast == RAW_STRING_R) {
@ -376,7 +388,14 @@ public final class FastCPartitionScanner implements IPartitionTokenScanner, ICPa
consume();
break;
default:
consume();
if ('a' <= ch && ch <= 'z' || 'A' <= ch && 'Z' <= ch || ch =='_') {
fLast = IDENT;
fTokenOffset++;
} else if ('0' <= ch && ch <= '9' && fLast == IDENT) {
fTokenOffset++;
} else {
consume();
}
break;
}
break;
@ -509,8 +528,12 @@ public final class FastCPartitionScanner implements IPartitionTokenScanner, ICPa
case OPEN_DELIMITER:
if (ch == '(') {
rawStringState = RawStringState.CONTENT;
} else {
} else if (ch == '"') {
return postFix(RAW_STRING);
} else if (ch != ' ' && ch != '\\' && ch != ')' && fRawStringDelimiter.length() < 12) {
fRawStringDelimiter.append((char) ch);
} else {
fState = STRING;
}
consume();
break;
@ -565,6 +588,7 @@ public final class FastCPartitionScanner implements IPartitionTokenScanner, ICPa
return -1;
case NONE:
case IDENT:
return 0;
case CARRIAGE_RETURN: