Java Code Examples for com.intellij.openapi.util.text.StringUtil#toUpperCase()

The following examples show how to use com.intellij.openapi.util.text.StringUtil#toUpperCase() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NameFilteringListModel.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void addToFiltered(T elt) {
  super.addToFiltered(elt);

  if (myNamer != null) {
    String name = myNamer.fun(elt);
    if (name != null) {
      String filterString = StringUtil.toUpperCase(myPattern.compute());
      String candidateString = StringUtil.toUpperCase(name);
      int index = getSize() - 1;

      if (myFullMatchIndex == -1 && filterString.equals(candidateString)) {
        myFullMatchIndex = index;
      }

      if (myStartsWithIndex == -1 && candidateString.startsWith(filterString)) {
        myStartsWithIndex = index;
      }
    }
  }
}
 
Example 2
Source File: KeywordParser.java    From consulo with Apache License 2.0 6 votes vote down vote up
public boolean hasToken(int position, CharSequence myBuffer, TokenInfo myTokenInfo) {
  int index = 0;
  int offset = position;
  boolean found = false;
  while (offset < myBuffer.length()) {
    char c = myBuffer.charAt(offset++);
    int nextIndex = myTrie.findSubNode(index, myIgnoreCase ? Character.toUpperCase(c) : c);
    if (nextIndex == 0) {
      break;
    }
    index = nextIndex;
    if (myHashCodes.contains(index) && isWordEnd(offset, myBuffer)) {
      String keyword = myBuffer.subSequence(position, offset).toString();
      String testKeyword = myIgnoreCase ? StringUtil.toUpperCase(keyword) : keyword;
      for (int i = 0; i < CustomHighlighterTokenType.KEYWORD_TYPE_COUNT; i++) {
        if (myKeywordSets.get(i).contains(testKeyword)) {
          myTokenInfo.updateData(position, position + keyword.length(), getToken(i));
          found = true;
          break;
        }
      }
    }
  }

  return found;
}
 
Example 3
Source File: LookupImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static String getCaseCorrectedLookupString(LookupElement item, PrefixMatcher prefixMatcher, String prefix) {
  String lookupString = item.getLookupString();
  if (item.isCaseSensitive()) {
    return lookupString;
  }

  final int length = prefix.length();
  if (length == 0 || !prefixMatcher.prefixMatches(prefix)) return lookupString;
  boolean isAllLower = true;
  boolean isAllUpper = true;
  boolean sameCase = true;
  for (int i = 0; i < length && (isAllLower || isAllUpper || sameCase); i++) {
    final char c = prefix.charAt(i);
    boolean isLower = Character.isLowerCase(c);
    boolean isUpper = Character.isUpperCase(c);
    // do not take this kind of symbols into account ('_', '@', etc.)
    if (!isLower && !isUpper) continue;
    isAllLower = isAllLower && isLower;
    isAllUpper = isAllUpper && isUpper;
    sameCase = sameCase && i < lookupString.length() && isLower == Character.isLowerCase(lookupString.charAt(i));
  }
  if (sameCase) return lookupString;
  if (isAllLower) return StringUtil.toLowerCase(lookupString);
  if (isAllUpper) return StringUtil.toUpperCase(lookupString);
  return lookupString;
}
 
Example 4
Source File: TypoTolerantMatcher.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a matcher by a given pattern.
 *
 * @param pattern        the pattern
 * @param options        case sensitivity settings
 * @param hardSeparators A string of characters (empty by default). Lowercase humps don't work for parts separated by any of these characters.
 *                       Need either an explicit uppercase letter or the same separator character in prefix
 */
TypoTolerantMatcher(@Nonnull String pattern, @Nonnull NameUtil.MatchingCaseSensitivity options, @Nonnull String hardSeparators) {
  myOptions = options;
  myPattern = StringUtil.trimEnd(pattern, "* ").toCharArray();
  myHardSeparators = hardSeparators;
  isLowerCase = new boolean[myPattern.length];
  isUpperCase = new boolean[myPattern.length];
  isWordSeparator = new boolean[myPattern.length];
  toUpperCase = new char[myPattern.length];
  toLowerCase = new char[myPattern.length];
  StringBuilder meaningful = new StringBuilder();
  for (int k = 0; k < myPattern.length; k++) {
    char c = myPattern[k];
    isLowerCase[k] = Character.isLowerCase(c);
    isUpperCase[k] = Character.isUpperCase(c);
    isWordSeparator[k] = isWordSeparator(c);
    toUpperCase[k] = StringUtil.toUpperCase(c);
    toLowerCase[k] = StringUtil.toLowerCase(c);
    if (!isWildcard(k)) {
      meaningful.append(toLowerCase[k]);
      meaningful.append(toUpperCase[k]);
    }
  }
  int i = 0;
  while (isWildcard(i)) i++;
  myHasHumps = hasFlag(i + 1, isUpperCase) && hasFlag(i, isLowerCase);
  myHasSeparators = hasFlag(i, isWordSeparator);
  myHasDots = hasDots(i);
  myMeaningfulCharacters = meaningful.toString().toCharArray();
  myMinNameLength = myMeaningfulCharacters.length / 2;
}
 
Example 5
Source File: MinusculeMatcherImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a matcher by a given pattern.
 *
 * @param pattern        the pattern
 * @param options        case sensitivity settings
 * @param hardSeparators A string of characters (empty by default). Lowercase humps don't work for parts separated by any of these characters.
 *                       Need either an explicit uppercase letter or the same separator character in prefix
 */
MinusculeMatcherImpl(@Nonnull String pattern, @Nonnull NameUtil.MatchingCaseSensitivity options, @Nonnull String hardSeparators) {
  myOptions = options;
  myPattern = StringUtil.trimEnd(pattern, "* ").toCharArray();
  myHardSeparators = hardSeparators;
  isLowerCase = new boolean[myPattern.length];
  isUpperCase = new boolean[myPattern.length];
  isWordSeparator = new boolean[myPattern.length];
  toUpperCase = new char[myPattern.length];
  toLowerCase = new char[myPattern.length];
  StringBuilder meaningful = new StringBuilder();
  for (int k = 0; k < myPattern.length; k++) {
    char c = myPattern[k];
    isLowerCase[k] = Character.isLowerCase(c);
    isUpperCase[k] = Character.isUpperCase(c);
    isWordSeparator[k] = isWordSeparator(c);
    toUpperCase[k] = StringUtil.toUpperCase(c);
    toLowerCase[k] = StringUtil.toLowerCase(c);
    if (!isWildcard(k)) {
      meaningful.append(toLowerCase[k]);
      meaningful.append(toUpperCase[k]);
    }
  }
  int i = 0;
  while (isWildcard(i)) i++;
  myHasHumps = hasFlag(i + 1, isUpperCase) && hasFlag(i, isLowerCase);
  myHasSeparators = hasFlag(i, isWordSeparator);
  myHasDots = hasDots(i);
  myMeaningfulCharacters = meaningful.toString().toCharArray();
  myMinNameLength = myMeaningfulCharacters.length / 2;
}
 
Example 6
Source File: ListPopupModel.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void addToFiltered(Object each) {
  myFilteredList.add(each);
  String filterString = StringUtil.toUpperCase(mySpeedSearch.getFilter());
  String candidateString = StringUtil.toUpperCase(myStep.getTextFor(each));
  int index = myFilteredList.size() - 1;

  if (myFullMatchIndex == -1 && filterString.equals(candidateString)) {
    myFullMatchIndex = index;
  }

  if (myStartsWithIndex == -1 && candidateString.startsWith(filterString)) {
    myStartsWithIndex = index;
  }
}
 
Example 7
Source File: LogConsolePreferences.java    From consulo with Apache License 2.0 5 votes vote down vote up
@javax.annotation.Nullable
public static String getType(@Nonnull String text) {
  String upcased = StringUtil.toUpperCase(text);
  if (ERROR_PATTERN.matcher(upcased).matches()) return ERROR;
  if (WARNING_PATTERN.matcher(upcased).matches() || WARN_PATTERN.matcher(upcased).matches()) return WARNING;
  if (INFO_PATTERN.matcher(upcased).matches()) return INFO;
  if (DEBUG_PATTERN.matcher(upcased).matches()) return DEBUG;
  return null;
}
 
Example 8
Source File: StringSearcher.java    From consulo with Apache License 2.0 5 votes vote down vote up
private char normalizedCharAt(@Nonnull CharSequence text, @Nullable char[] textArray, int index) {
  char lastChar = textArray != null ? textArray[index] : text.charAt(index);
  if (myCaseSensitive) {
    return lastChar;
  }
  return myLowecaseTransform ? StringUtil.toLowerCase(lastChar) : StringUtil.toUpperCase(lastChar);
}
 
Example 9
Source File: CapitalizeMacro.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected Result calculateResult(@Nonnull Expression[] params, ExpressionContext context, boolean quick) {
  String text = getTextResult(params, context);
  if (text != null) {
    if (text.length() > 0) {
      text = StringUtil.toUpperCase(text.substring(0, 1)) + text.substring(1, text.length());
    }
    return new TextResult(text);
  }
  return null;
}
 
Example 10
Source File: NameUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
private static String compoundSuggestion(@Nonnull String prefix, boolean upperCaseStyle, @Nonnull String[] words, int wordCount, @Nonnull String startWord, char c, boolean isArray, boolean skip_) {
  StringBuilder buffer = new StringBuilder();

  buffer.append(prefix);

  if (upperCaseStyle) {
    startWord = StringUtil.toUpperCase(startWord);
  }
  else {
    if (prefix.isEmpty() || StringUtil.endsWithChar(prefix, '_')) {
      startWord = StringUtil.toLowerCase(startWord);
    }
    else {
      startWord = Character.toUpperCase(c) + startWord.substring(1);
    }
  }
  buffer.append(startWord);

  for (int i = words.length - wordCount + 1; i < words.length; i++) {
    String word = words[i];
    String prevWord = words[i - 1];
    if (upperCaseStyle) {
      word = StringUtil.toUpperCase(word);
      if (prevWord.charAt(prevWord.length() - 1) != '_' && word.charAt(0) != '_') {
        word = "_" + word;
      }
    }
    else {
      if (prevWord.charAt(prevWord.length() - 1) == '_') {
        word = StringUtil.toLowerCase(word);
      }

      if (skip_) {
        if (word.equals("_")) continue;
        if (prevWord.equals("_")) {
          word = StringUtil.capitalize(word);
        }
      }
    }
    buffer.append(word);
  }

  String suggestion = buffer.toString();
  if (isArray) {
    suggestion = StringUtil.pluralize(suggestion);
    if (upperCaseStyle) {
      suggestion = StringUtil.toUpperCase(suggestion);
    }
  }
  return suggestion;
}
 
Example 11
Source File: LocalFileSystemBase.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
protected String extractRootPath(@Nonnull String path) {
  if (path.isEmpty()) {
    try {
      path = new File("").getCanonicalPath();
    }
    catch (IOException e) {
      throw new RuntimeException(e);
    }
  }

  for (String customRootPath : ourRootPaths) {
    if (path.startsWith(customRootPath)) return customRootPath;
  }

  if (SystemInfo.isWindows) {
    if (path.length() >= 2 && path.charAt(1) == ':') {
      // Drive letter
      return StringUtil.toUpperCase(path.substring(0, 2));
    }

    if (path.startsWith("//") || path.startsWith("\\\\")) {
      // UNC. Must skip exactly two path elements like [\\ServerName\ShareName]\pathOnShare\file.txt
      // Root path is in square brackets here.

      int slashCount = 0;
      int idx;
      boolean isSlash = false;
      for (idx = 2; idx < path.length() && slashCount < 2; idx++) {
        char c = path.charAt(idx);
        isSlash = c == '\\' || c == '/';
        if (isSlash) {
          slashCount++;
          if (slashCount == 2) {
            idx--;
          }
        }
      }

      if (slashCount == 2 || slashCount == 1 && !isSlash) {
        return path.substring(0, idx);
      }
    }

    return "";
  }

  return StringUtil.startsWithChar(path, '/') ? "/" : "";
}
 
Example 12
Source File: Switcher.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static String getIndexShortcut(int index) {
  return StringUtil.toUpperCase(Integer.toString(index, index + 1));
}
 
Example 13
Source File: DesktopColorPicker.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
  final boolean rgb = isRGBMode();
  char[] source = str.toCharArray();
  if (mySrc != null) {
    final int selected = mySrc.getSelectionEnd() - mySrc.getSelectionStart();
    int newLen = mySrc.getText().length() - selected + str.length();
    if (newLen > (myHex ? 6 : 3)) {
      Toolkit.getDefaultToolkit().beep();
      return;
    }
  }
  char[] result = new char[source.length];
  int j = 0;
  for (int i = 0; i < result.length; i++) {
    if (myHex ? "0123456789abcdefABCDEF".indexOf(source[i]) >= 0 : Character.isDigit(source[i])) {
      result[j++] = source[i];
    }
    else {
      Toolkit.getDefaultToolkit().beep();
    }
  }
  final String toInsert = StringUtil.toUpperCase(new String(result, 0, j));
  final String res = new StringBuilder(mySrc.getText()).insert(offs, toInsert).toString();
  try {
    if (!myHex) {
      final int num = Integer.parseInt(res);
      if (rgb) {
        if (num > 255) {
          Toolkit.getDefaultToolkit().beep();
          return;
        }
      }
      else {
        if ((mySrc == myRed && num > 359) || ((mySrc == myGreen || mySrc == myBlue) && num > 100)) {
          Toolkit.getDefaultToolkit().beep();
          return;
        }
      }
    }
  }
  catch (NumberFormatException ignore) {
  }
  super.insertString(offs, toInsert, a);
}