use of com.ibm.icu.util.StringTokenizer in project linuxtools by eclipse.
the class SpecfileElementHyperlinkDetector method detectHyperlinks.
@Override
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
if (region == null || textViewer == null) {
return null;
}
IDocument document = textViewer.getDocument();
if (document == null) {
return null;
}
// until a SpecfileEditor#editorSaved is called
if (specfile == null) {
SpecfileEditor a = this.getAdapter(SpecfileEditor.class);
if (a != null && a.getSpecfile() != null) {
specfile = a.getSpecfile();
} else {
SpecfileParser parser = new SpecfileParser();
specfile = parser.parse(document);
}
}
int offset = region.getOffset();
IRegion lineInfo;
String line;
try {
lineInfo = document.getLineInformationOfOffset(offset);
line = document.get(lineInfo.getOffset(), lineInfo.getLength());
} catch (BadLocationException ex) {
return null;
}
int offsetInLine = offset - lineInfo.getOffset();
StringTokenizer tokens = new StringTokenizer(line);
// $NON-NLS-1$
String word = "";
int tempLineOffset = 0;
int wordOffsetInLine = 0;
while (tokens.hasMoreTokens()) {
String tempWord = tokens.nextToken();
// $NON-NLS-1$
Pattern defineRegexp = Pattern.compile("%\\{(.*?)\\}");
Matcher fit = defineRegexp.matcher(tempWord);
while (fit.find()) {
if ((fit.start() + tempLineOffset <= offsetInLine) && (offsetInLine <= fit.end() + tempLineOffset)) {
tempWord = fit.group();
wordOffsetInLine = fit.start();
tempLineOffset += fit.start();
break;
}
}
tempLineOffset += tempWord.length();
word = tempWord;
if (tempLineOffset > offsetInLine) {
break;
}
}
if (word.startsWith(SOURCE_IDENTIFIER)) {
int sourceNumber = Integer.valueOf(word.substring(SOURCE_IDENTIFIER.length(), word.length() - 1)).intValue();
SpecfileSource source = specfile.getSource(sourceNumber);
if (source != null) {
return prepareHyperlink(lineInfo, line, word, source);
}
} else if (word.startsWith(PATCH_IDENTIFIER)) {
int sourceNumber = Integer.valueOf(word.substring(PATCH_IDENTIFIER.length(), word.length())).intValue();
SpecfileSource source = specfile.getPatch(sourceNumber);
if (source != null) {
return prepareHyperlink(lineInfo, line, word, source);
}
} else {
String defineName = getDefineName(word);
SpecfileDefine define = specfile.getDefine(defineName);
if (define != null) {
return prepareHyperlink(lineInfo, line, defineName, define, wordOffsetInLine);
}
}
return null;
}
use of com.ibm.icu.util.StringTokenizer in project webtools.sourceediting by eclipse.
the class CSSSelector method matchExactly.
/**
* @return boolean
*/
private boolean matchExactly(ICSSSimpleSelector selector, Element element, String pseudoName) {
IStyleSelectorAdapter adapter = (IStyleSelectorAdapter) ((INodeNotifier) element).getAdapterFor(IStyleSelectorAdapter.class);
if (adapter != null) {
return adapter.match(selector, element, pseudoName);
}
if (element == null)
return false;
int i;
String key;
// check tag name
if (!selector.isUniversal() && !element.getNodeName().equals(selector.getName()))
return false;
// check id
i = selector.getNumOfIDs();
if (i > 0) {
if (i > 1)
return false;
if (// $NON-NLS-1$ //$NON-NLS-2$
!element.hasAttribute("id") || (key = element.getAttribute("id")).length() == 0)
return false;
if (!selector.getID(0).equals(key))
return false;
}
// check class
i = selector.getNumOfClasses();
if (i > 0) {
if (// $NON-NLS-1$ //$NON-NLS-2$
!element.hasAttribute("class") || (key = element.getAttribute("class")).length() == 0)
return false;
StringTokenizer tokenizer = new StringTokenizer(key);
for (i = i - 1; i >= 0; i--) {
boolean ok = false;
while (tokenizer.hasMoreTokens()) {
if (selector.getClass(i).equals(tokenizer.nextToken())) {
ok = true;
break;
}
}
if (!ok)
return false;
}
}
// check attributes
for (i = selector.getNumOfAttributes() - 1; i >= 0; i--) {
// $NON-NLS-1$
StringTokenizer tokenizer = new StringTokenizer(selector.getAttribute(i), "=~| \t\r\n\f");
int countTokens = tokenizer.countTokens();
if (countTokens > 0) {
String attrName = tokenizer.nextToken();
String attrValue = null;
if (!element.hasAttribute(attrName) || (attrValue = element.getAttribute(attrName)).length() == 0)
return false;
if (countTokens > 1) {
// $NON-NLS-1$
String token = tokenizer.nextToken("= \t\r\n\f");
StringTokenizer attrValueTokenizer = null;
if (token.equals("~")) {
// $NON-NLS-1$
attrValueTokenizer = new StringTokenizer(attrValue);
} else if (token.equals("|")) {
// $NON-NLS-1$
// $NON-NLS-1$
attrValueTokenizer = new StringTokenizer(attrValue, "-");
}
if (attrValueTokenizer != null) {
if (tokenizer.hasMoreTokens()) {
token = tokenizer.nextToken();
boolean ok = false;
while (attrValueTokenizer.hasMoreTokens()) {
if (token.equals(attrValueTokenizer.nextToken())) {
ok = true;
break;
}
}
if (!ok)
return false;
}
} else {
if (!attrValue.equals(token))
return false;
}
}
}
}
return true;
}
use of com.ibm.icu.util.StringTokenizer in project webtools.sourceediting by eclipse.
the class AnnotationMap method addAnnotation.
public void addAnnotation(Annotation annotation) {
String spec = annotation.getSpec();
if (spec != null) {
list.add(annotation);
// $NON-NLS-1$
StringTokenizer st = new StringTokenizer(spec, "[]|\t\n\r\f ");
while (st.hasMoreTokens()) {
String cmNodeSpec = st.nextToken();
addAnnotationForCMNodeSpec(cmNodeSpec, annotation);
}
}
}
use of com.ibm.icu.util.StringTokenizer in project webtools.sourceediting by eclipse.
the class JSPResourceEncodingDetector method parseContentTypeValue.
/**
* This method should be exactly the same as what is in
* JSPHeadTokenizerTester
* @param contentType
*/
private void parseContentTypeValue(String contentType) {
/*
* Based partially on
* org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapterImpl
* .getMimeTypeFromContentTypeValue(String) , divides the full value
* into segments according to ';', assumes the first specifies the
* content type itself if it has no '=', and that the remainder are
* parameters which may specify a charset
*/
String cleanContentTypeValue = StringUtils.stripNonLetterDigits(contentType);
/* Break the mime header into the main value and its parameters, separated by ';' */
// $NON-NLS-1$
StringTokenizer tokenizer = new StringTokenizer(cleanContentTypeValue, ";");
int tLen = tokenizer.countTokens();
if (tLen == 0)
return;
String[] tokens = new String[tLen];
int j = 0;
while (tokenizer.hasMoreTokens()) {
tokens[j] = tokenizer.nextToken();
j++;
}
int firstParameter = 0;
if (tokens[0].indexOf('=') == -1) {
/*
* no equal sign in the first segment, so assume it indicates a
* content type properly
*/
fContentType = tokens[0].trim();
firstParameter = 1;
}
/*
* now handle parameters as name=value pairs, looking for "charset"
* specifically
*/
// $NON-NLS-1$
Pattern equalPattern = Pattern.compile("\\s*=\\s*");
for (int i = firstParameter; i < tokens.length; i++) {
String[] pair = equalPattern.split(tokens[i]);
if (pair.length < 2)
continue;
if (pair[0].trim().equals("charset")) {
// $NON-NLS-1$
fCharset = pair[1].trim();
}
}
}
use of com.ibm.icu.util.StringTokenizer in project webtools.sourceediting by eclipse.
the class JSPTranslationExtension method adjustIndent.
private String adjustIndent(String textBefore, String indent, String delim) {
// first replace multiple indent with single indent
// the triple indent occurs because the scriptlet code
// actually occurs under:
//
// class
// method
// code
//
// in the translated java document
// BUG188636 - just get indent info from code formatter
String level1 = getCodeFormatter().createIndentationString(1);
String level3 = getCodeFormatter().createIndentationString(3);
// $NON-NLS-1$
String theOld = "\n" + level3;
// $NON-NLS-1$
String theNew = "\n" + level1;
textBefore = textBefore.replaceAll(theOld, theNew);
// get indent after 2nd line break
StringBuffer textAfter = new StringBuffer();
// will this work on mac?
// $NON-NLS-1$ //$NON-NLS-2$
textBefore = textBefore.replaceAll("\r", "");
// $NON-NLS-1$
StringTokenizer st = new StringTokenizer(textBefore, "\n", true);
while (st.hasMoreTokens()) {
String tok = st.nextToken();
if (tok.equals("\n")) {
// $NON-NLS-1$
textAfter.append(delim);
} else {
// prepend each line w/ specified indent
textAfter.append(indent);
textAfter.append(tok);
}
}
return textAfter.toString();
}
Aggregations