Search in sources :

Example 1 with PerlStringManipulator

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;
}
Also used : PerlStringMixin(com.perl5.lang.perl.psi.mixins.PerlStringMixin) PsiElement(com.intellij.psi.PsiElement) PerlStringManipulator(com.perl5.lang.perl.idea.manipulators.PerlStringManipulator)

Example 2 with PerlStringManipulator

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();
}
Also used : PerlBareStringManipulator(com.perl5.lang.perl.idea.manipulators.PerlBareStringManipulator) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) PerlStringContentManipulator(com.perl5.lang.perl.idea.manipulators.PerlStringContentManipulator) PerlStringManipulator(com.perl5.lang.perl.idea.manipulators.PerlStringManipulator)

Aggregations

PerlStringManipulator (com.perl5.lang.perl.idea.manipulators.PerlStringManipulator)2 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)1 PsiElement (com.intellij.psi.PsiElement)1 PerlBareStringManipulator (com.perl5.lang.perl.idea.manipulators.PerlBareStringManipulator)1 PerlStringContentManipulator (com.perl5.lang.perl.idea.manipulators.PerlStringContentManipulator)1 PerlStringMixin (com.perl5.lang.perl.psi.mixins.PerlStringMixin)1