Injecting Language into <![CDATA[ area in xml file
I have following code:
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:
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
请先登录再写评论。