use of com.perl5.lang.perl.idea.manipulators.PerlStringManipulator in project Perl5-IDEA by Camelcade.
the class PerlStringLiteralEscaper method decode.
@Override
public boolean decode(@NotNull TextRange rangeInsideHost, @NotNull StringBuilder outChars) {
ElementManipulator<PerlStringMixin> manipulator = ElementManipulators.getNotNullManipulator(myHost);
assert manipulator instanceof PerlStringManipulator;
PsiElement openQuoteElement = ((PerlStringManipulator) manipulator).getOpeningQuote(myHost);
char openQuote = openQuoteElement.getText().charAt(0);
char closeQuote = PerlLexer.getQuoteCloseChar(openQuote);
offsetsMap = new HashMap<>();
CharSequence sourceText = rangeInsideHost.subSequence(myHost.getText());
Integer sourceOffset = 0;
Integer targetOffset = 0;
Integer sourceLength = sourceText.length();
boolean isEscaped = false;
while (sourceOffset < sourceLength) {
char currentChar = sourceText.charAt(sourceOffset);
if (isEscaped) {
if (currentChar != openQuote && currentChar != closeQuote) {
assert sourceOffset > 0;
outChars.append('\\');
offsetsMap.put(targetOffset++, sourceOffset - 1);
}
outChars.append(currentChar);
offsetsMap.put(targetOffset++, sourceOffset);
isEscaped = false;
} else if (currentChar == '\\') {
isEscaped = true;
} else {
outChars.append(currentChar);
offsetsMap.put(targetOffset++, sourceOffset);
}
sourceOffset++;
}
if (// end with escape, not sure if possible
isEscaped) {
outChars.append('\\');
offsetsMap.put(targetOffset++, sourceOffset - 1);
}
// end marker
offsetsMap.put(targetOffset, sourceOffset);
return true;
}
use of com.perl5.lang.perl.idea.manipulators.PerlStringManipulator in project Perl5-IDEA by Camelcade.
the class PerlLightTestCase method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
myDisposable = Disposer.newDisposable();
EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
myReadAttributes = scheme.getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
myWriteAttributes = scheme.getAttributes(EditorColors.WRITE_SEARCH_RESULT_ATTRIBUTES);
ElementManipulators.INSTANCE.addExplicitExtension(PerlStringMixin.class, new PerlStringManipulator());
ElementManipulators.INSTANCE.addExplicitExtension(PerlStringBareMixin.class, new PerlBareStringManipulator());
ElementManipulators.INSTANCE.addExplicitExtension(PerlStringContentElement.class, new PerlStringContentManipulator());
setUpLibrary();
myCodeInsightSettings = Perl5CodeInsightSettings.getInstance().copy();
}
Aggregations