Injecting Language into <![CDATA[ area in xml file

I have following code:
function foo() { xxx = 0; } and I use following code to inject language, and all is fine: final Language language = ((LanguageFileType) FileTypeManager.getInstance().getFileTypeByExtension("js")).getLanguage(); injectionPlacesRegistrar.addPlace(language, new TextRange(0, host.getTextLength()-1), null, null); Now I want to change xml file to following code: <![CDATA[ function foo() { xxx = 0; } \]\]\> and I use following code, and IDEA always reports error, anyone can help me, thanks. String text = host.getOriginalElement().getText(); String startStr = "]]>";
if (text.contains(startStr) && text.contains(endStr))
{
int start = text.indexOf(startStr) + startStr.length();
int end = text.lastIndexOf(endStr);
final Language language = ((LanguageFileType) FileTypeManager.getInstance().getFileTypeByExtension("js")).getLanguage();
injectionPlacesRegistrar.addPlace(language, new TextRange(start, end), null, null);
}

Exception as following:
java.lang.StringIndexOutOfBoundsException: String index out of range: 224

Please sign in to leave a comment.