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

The following examples show how to use com.intellij.openapi.util.text.StringUtil#startsWithIgnoreCase() . 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: ReplacePathToMacroMap.java    From consulo with Apache License 2.0 6 votes vote down vote up
private String replacePathMacro(String text, final String path, boolean caseSensitive) {
  if (text.length() < path.length() || path.isEmpty()) {
    return text;
  }

  boolean startsWith = caseSensitive ? text.startsWith(path) : StringUtil.startsWithIgnoreCase(text, path);

  if (!startsWith) return text;

  //check that this is complete path (ends with "/" or "!/")
  // do not collapse partial paths, i.e. do not substitute "/a/b/cd" in paths like "/a/b/cdeFgh"
  int endOfOccurrence = path.length();
  final boolean isWindowsRoot = path.endsWith(":/");
  if (!isWindowsRoot &&
      endOfOccurrence < text.length() &&
      text.charAt(endOfOccurrence) != '/' &&
      !text.substring(endOfOccurrence).startsWith("!/")) {
    return text;
  }

  return myMacroMap.get(path) + text.substring(endOfOccurrence);
}
 
Example 2
Source File: LoadingOrder.java    From consulo with Apache License 2.0 6 votes vote down vote up
private LoadingOrder(@NonNls @Nonnull String text) {
  myName = text;
  boolean last = false;
  boolean first = false;
  for (final String string : StringUtil.split(text, ORDER_RULE_SEPARATOR)) {
    String trimmed = string.trim();
    if (trimmed.equalsIgnoreCase(FIRST_STR)) first = true;
    else if (trimmed.equalsIgnoreCase(LAST_STR)) last = true;
    else if (StringUtil.startsWithIgnoreCase(trimmed, BEFORE_STR)) myBefore.add(trimmed.substring(BEFORE_STR.length()).trim());
    else if (StringUtil.startsWithIgnoreCase(trimmed, BEFORE_STR_OLD)) myBefore.add(trimmed.substring(BEFORE_STR_OLD.length()).trim());
    else if (StringUtil.startsWithIgnoreCase(trimmed, AFTER_STR)) myAfter.add(trimmed.substring(AFTER_STR.length()).trim());
    else if (StringUtil.startsWithIgnoreCase(trimmed, AFTER_STR_OLD)) myAfter.add(trimmed.substring(AFTER_STR_OLD.length()).trim());
    else throw new AssertionError("Invalid specification: " + trimmed + "; should be one of FIRST, LAST, BEFORE <id> or AFTER <id>");
  }
  myFirst = first;
  myLast = last;
}
 
Example 3
Source File: FilePathCompletionContributor.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static boolean filenameMatchesPrefixOrType(final String fileName,
                                                   final String prefix,
                                                   final FileType[] suitableFileTypes,
                                                   final int invocationCount) {
  final boolean prefixMatched = prefix.length() == 0 || StringUtil.startsWithIgnoreCase(fileName, prefix);
  if (prefixMatched && (suitableFileTypes.length == 0 || invocationCount > 2)) return true;

  if (prefixMatched) {
    final String extension = FileUtilRt.getExtension(fileName);
    if (extension.length() == 0) return false;

    for (final FileType fileType : suitableFileTypes) {
      for (final FileNameMatcher matcher : FileTypeManager.getInstance().getAssociations(fileType)) {
        if (matcher.accept(fileName)) return true;
      }
    }
  }

  return false;
}
 
Example 4
Source File: PantsUtil.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
public static boolean isGenTarget(@NotNull String address) {
  return StringUtil.startsWithIgnoreCase(address, ".pants.d") ||
         StringUtil.startsWithIgnoreCase(address, PantsConstants.PANTS_PROJECT_MODULE_ID_PREFIX) ||
         // Checking "_synthetic_resources" is a temporary fix. It also needs to match the postfix added from pants in
         // src.python.pants.backend.python.targets.python_target.PythonTarget#_synthetic_resources_target
         // TODO: The long term solution is collect non-synthetic targets at pre-compile stage
         // https://github.com/pantsbuild/intellij-pants-plugin/issues/83
         address.toLowerCase().endsWith("_synthetic_resources");
}
 
Example 5
Source File: GeneratedParserUtilBase.java    From intellij-latte with MIT License 5 votes vote down vote up
public boolean prefixMatches(@NotNull String prefix, @NotNull String variant) {
	boolean matches = new CamelHumpMatcher(prefix, false).prefixMatches(variant.replace(' ', '_'));
	if (matches && StringUtil.isWhiteSpace(prefix.charAt(prefix.length() - 1))) {
		return StringUtil.startsWithIgnoreCase(variant, prefix);
	}
	return matches;
}
 
Example 6
Source File: CamelHumpMatcher.java    From consulo with Apache License 2.0 5 votes vote down vote up
private boolean prefixMatchersInternal(final LookupElement element, final boolean itemCaseInsensitive) {
  for (final String name : element.getAllLookupStrings()) {
    if (itemCaseInsensitive && StringUtil.startsWithIgnoreCase(name, myPrefix) || prefixMatches(name)) {
      return true;
    }
    if (itemCaseInsensitive && CodeInsightSettings.ALL != CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE) {
      if (myCaseInsensitiveMatcher.matches(name)) {
        return true;
      }
    }
  }
  return false;
}
 
Example 7
Source File: UnityProcessDialog.java    From consulo-unity3d with Apache License 2.0 4 votes vote down vote up
@Nullable
public static UnityProcess tryParseIfUnityProcess(ProcessInfo processInfo)
{
	String name = processInfo.getName();

	// Unity 2019.3 linux bug - 2020.1 ok
	if(name.equals("Main"))
	{
		List<String> list = StringUtil.split(processInfo.getCommand(), " ");
		String first = ContainerUtil.getFirstItem(list);
		if(first != null && first.endsWith("/Editor/Unity"))
		{
			return new UnityProcess(processInfo.getPid(), name, "localhost", buildDebuggerPort(processInfo.getPid()));
		}
	}

	if(StringUtil.startsWithIgnoreCase(name, "unity") || StringUtil.containsIgnoreCase(name, "Unity.app"))
	{
		// ignore 'UnityHelper' and 'Unity Helper'
		if(StringUtil.containsIgnoreCase(name, "Unity") && StringUtil.containsIgnoreCase(name, "Helper"))
		{
			return null;
		}

		if(StringUtil.containsIgnoreCase(name, "Unity") && StringUtil.containsIgnoreCase(name, "Hub") || StringUtil.containsIgnoreCase(name, "unityhub"))
		{
			return null;
		}

		if(StringUtil.containsIgnoreCase(name, "Unity") && StringUtil.containsIgnoreCase(name, "CrashHandler"))
		{
			return null;
		}

		// UnityShader - Package Manager - Hub compiler
		if(StringUtil.containsIgnoreCase(name, "UnityShader") || StringUtil.containsIgnoreCase(name, "UnityPackageMan"))
		{
			return null;
		}

		return new UnityProcess(processInfo.getPid(), name, "localhost", buildDebuggerPort(processInfo.getPid()));
	}

	return null;
}
 
Example 8
Source File: Paths.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static boolean isParent(String parent, String path) {
  if (equals(parent, path)) return true;
  parent = appendParent(parent);
  return myIsCaseSensitive ? path.startsWith(parent) : StringUtil.startsWithIgnoreCase(path, parent);
}
 
Example 9
Source File: CommitIdByStringCondition.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public boolean value(CommitId commitId) {
  return StringUtil.startsWithIgnoreCase(commitId.getHash().asString(), myHashString);
}
 
Example 10
Source File: VMOptions.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static double parseUnit(String unitString) {
  if (StringUtil.startsWithIgnoreCase(unitString, "k")) return (double)1 / 1024;
  if (StringUtil.startsWithIgnoreCase(unitString, "g")) return 1024;
  return 1;
}
 
Example 11
Source File: PlainPrefixMatcher.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isStartMatch(String name) {
  return StringUtil.startsWithIgnoreCase(name, getPrefix());
}
 
Example 12
Source File: XmlStringUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static boolean isWrappedInHtml(@Nonnull String tooltip) {
  return StringUtil.startsWithIgnoreCase(tooltip, HTML_START) &&
         StringUtil.endsWithIgnoreCase(tooltip, HTML_END);
}
 
Example 13
Source File: GotoActionModel.java    From consulo with Apache License 2.0 4 votes vote down vote up
private int getRank(@Nonnull String text) {
  if (StringUtil.equalsIgnoreCase(StringUtil.trimEnd(text, "..."), pattern)) return 3;
  if (StringUtil.startsWithIgnoreCase(text, pattern)) return 2;
  if (StringUtil.containsIgnoreCase(text, pattern)) return 1;
  return 0;
}