com.intellij.openapi.util.text.StringUtilRt Java Examples
The following examples show how to use
com.intellij.openapi.util.text.StringUtilRt.
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: BuckFileTypeFactory.java From Buck-IntelliJ-Plugin with Apache License 2.0 | 6 votes |
@Override public void createFileTypes(FileTypeConsumer fileTypeConsumer) { fileTypeConsumer.consume( BuckFileType.INSTANCE, new FileNameMatcherEx() { @Override public String getPresentableString() { return BuckFileUtil.getBuildFileName(); } @Override public boolean acceptsCharSequence(CharSequence fileName) { String buildFileName = BuckFileUtil.getBuildFileName(); return StringUtilRt.endsWithIgnoreCase(fileName, buildFileName) || Comparing.equal(fileName, buildFileName, true); } }); }
Example #2
Source File: Comparing.java From consulo with Apache License 2.0 | 6 votes |
public static boolean equal(@Nullable CharSequence s1, @Nullable CharSequence s2, boolean caseSensitive) { if (s1 == s2) return true; if (s1 == null || s2 == null) return false; // Algorithm from String.regionMatches() if (s1.length() != s2.length()) return false; int to = 0; int po = 0; int len = s1.length(); while (len-- > 0) { char c1 = s1.charAt(to++); char c2 = s2.charAt(po++); if (c1 == c2) { continue; } if (!caseSensitive && StringUtilRt.charsEqualIgnoreCase(c1, c2)) continue; return false; } return true; }
Example #3
Source File: EncodingUtil.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull static Magic8 isSafeToConvertTo(@Nonnull VirtualFile virtualFile, @Nonnull CharSequence text, @Nonnull byte[] bytesOnDisk, @Nonnull Charset charset) { try { String lineSeparator = FileDocumentManager.getInstance().getLineSeparator(virtualFile, null); CharSequence textToSave = lineSeparator.equals("\n") ? text : StringUtilRt.convertLineSeparators(text, lineSeparator); Pair<Charset, byte[]> chosen = LoadTextUtil.chooseMostlyHarmlessCharset(virtualFile.getCharset(), charset, textToSave.toString()); byte[] saved = chosen.second; CharSequence textLoadedBack = LoadTextUtil.getTextByBinaryPresentation(saved, charset); return !StringUtil.equals(text, textLoadedBack) ? Magic8.NO_WAY : Arrays.equals(saved, bytesOnDisk) ? Magic8.ABSOLUTELY : Magic8.WELL_IF_YOU_INSIST; } catch (UnsupportedOperationException e) { // unsupported encoding return Magic8.NO_WAY; } }
Example #4
Source File: AbstractExternalFilter.java From consulo with Apache License 2.0 | 5 votes |
public CharSequence refFilter(final String root, @Nonnull CharSequence read) { CharSequence toMatch = StringUtilRt.toUpperCase(read); StringBuilder ready = new StringBuilder(); int prev = 0; Matcher matcher = mySelector.matcher(toMatch); while (matcher.find()) { CharSequence before = read.subSequence(prev, matcher.start(1) - 1); // Before reference final CharSequence href = read.subSequence(matcher.start(1), matcher.end(1)); // The URL prev = matcher.end(1) + 1; ready.append(before); ready.append("\""); ready.append(ApplicationManager.getApplication().runReadAction( new Computable<String>() { @Override public String compute() { return convertReference(root, href.toString()); } } )); ready.append("\""); } ready.append(read, prev, read.length()); return ready; }
Example #5
Source File: CsvTableEditorState.java From intellij-csv-validator with Apache License 2.0 | 5 votes |
public static CsvTableEditorState create(@NotNull Element element, @NotNull Project project, @NotNull VirtualFile file) { CsvTableEditorState state = new CsvTableEditorState(); Attribute attribute = element.getAttribute("showInfoPanel"); state.setShowInfoPanel( attribute == null ? CsvEditorSettings.getInstance().showTableEditorInfoPanel() : Boolean.parseBoolean(attribute.getValue()) ); attribute = element.getAttribute("fixedHeaders"); state.setFixedHeaders( attribute == null ? false : Boolean.parseBoolean(attribute.getValue()) ); attribute = element.getAttribute("autoColumnWidthOnOpen"); if (attribute != null) { state.setAutoColumnWidthOnOpen(Boolean.parseBoolean(attribute.getValue())); } state.setRowLines( StringUtilRt.parseInt(element.getAttributeValue("rowLines"), CsvEditorSettings.getInstance().getTableEditorRowHeight()) ); List<Element> columnWidthElements = element.getChildren("column"); int[] columnWidths = new int[columnWidthElements.size()]; int defaultColumnWidth = CsvEditorSettings.getInstance().getTableDefaultColumnWidth(); for (int i = 0; i < columnWidthElements.size(); ++i) { Element columnElement = columnWidthElements.get(i); int index = StringUtilRt.parseInt(columnElement.getAttributeValue("index"), i); columnWidths[index] = StringUtilRt.parseInt(columnElement.getAttributeValue("width"), defaultColumnWidth); } state.setColumnWidths(columnWidths); return state; }
Example #6
Source File: FileUtilRt.java From consulo with Apache License 2.0 | 5 votes |
@Contract("_,!null -> !null") public static CharSequence getExtension(@Nonnull CharSequence fileName, @Nullable String defaultValue) { int index = StringUtilRt.lastIndexOf(fileName, '.', 0, fileName.length()); if (index < 0) { return defaultValue; } return fileName.subSequence(index + 1, fileName.length()); }
Example #7
Source File: FileUtilRt.java From consulo with Apache License 2.0 | 5 votes |
@Contract("_, _, _, null -> true") private static boolean processDots(@Nonnull StringBuilder result, int dots, int start, SymlinkResolver symlinkResolver) { if (dots == 2) { int pos = -1; if (!StringUtilRt.endsWith(result, "/../") && !"../".contentEquals(result)) { pos = StringUtilRt.lastIndexOf(result, '/', start, result.length() - 1); if (pos >= 0) { ++pos; // separator found, trim to next char } else if (start > 0) { pos = start; // path is absolute, trim to root ('/..' -> '/') } else if (result.length() > 0) { pos = 0; // path is relative, trim to default ('a/..' -> '') } } if (pos >= 0) { if (symlinkResolver != null && symlinkResolver.isSymlink(result)) { return false; } result.delete(pos, result.length()); } else { result.append("../"); // impossible to traverse, keep as-is } } else if (dots != 1) { for (int i = 0; i < dots; i++) { result.append('.'); } result.append('/'); } return true; }
Example #8
Source File: FileUtilRt.java From consulo with Apache License 2.0 | 5 votes |
public static boolean isJarOrZip(@Nonnull File file, boolean isCheckIsDirectory) { if (isCheckIsDirectory && file.isDirectory()) { return false; } // do not use getName to avoid extra String creation (File.getName() calls substring) final String path = file.getPath(); return StringUtilRt.endsWithIgnoreCase(path, ".jar") || StringUtilRt.endsWithIgnoreCase(path, ".zip"); }
Example #9
Source File: WindowStateServiceImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override public final void loadState(@Nonnull Element element) { synchronized (myStateMap) { myStateMap.clear(); for (Element child : element.getChildren()) { if (!STATE.equals(child.getName())) continue; // ignore unexpected element long current = System.currentTimeMillis(); long timestamp = StringUtilRt.parseLong(child.getAttributeValue(TIMESTAMP), current); if (TimeUnit.DAYS.toMillis(100) <= (current - timestamp)) continue; // ignore old elements String key = child.getAttributeValue(KEY); if (StringUtilRt.isEmpty(key)) continue; // unexpected key Point location = JDOMUtil.getLocation(child); Dimension size = JDOMUtil.getSize(child); if (location == null && size == null) continue; // unexpected value CachedState state = new CachedState(); state.myLocation = location; state.mySize = size; state.myMaximized = Boolean.parseBoolean(child.getAttributeValue(MAXIMIZED)); state.myFullScreen = Boolean.parseBoolean(child.getAttributeValue(FULL_SCREEN)); state.myScreen = apply(JDOMUtil::getBounds, child.getChild(SCREEN)); state.myTimeStamp = timestamp; myStateMap.put(key, state); } } }
Example #10
Source File: SchemesManagerImpl.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private String createFileName(@Nonnull CharSequence fileName) { if (StringUtilRt.endsWithIgnoreCase(fileName, mySchemeExtension)) { fileName = fileName.subSequence(0, fileName.length() - mySchemeExtension.length()); } else if (StringUtilRt.endsWithIgnoreCase(fileName, DirectoryStorageData.DEFAULT_EXT)) { fileName = fileName.subSequence(0, fileName.length() - DirectoryStorageData.DEFAULT_EXT.length()); } return fileName.toString(); }
Example #11
Source File: SchemesManagerImpl.java From consulo with Apache License 2.0 | 5 votes |
private boolean canRead(@Nonnull File file) { if (file.isDirectory()) { return false; } // migrate from custom extension to default if (myUpdateExtension && StringUtilRt.endsWithIgnoreCase(file.getName(), mySchemeExtension)) { return true; } else { return StringUtilRt.endsWithIgnoreCase(file.getName(), DirectoryStorageData.DEFAULT_EXT); } }
Example #12
Source File: SchemesManagerImpl.java From consulo with Apache License 2.0 | 4 votes |
private boolean isMy(@Nonnull VirtualFileEvent event) { return StringUtilRt.endsWithIgnoreCase(event.getFile().getNameSequence(), mySchemeExtension); }
Example #13
Source File: FileTypeManagerImpl.java From consulo with Apache License 2.0 | 4 votes |
@Override public void loadState(@Nonnull Element state) { int savedVersion = StringUtilRt.parseInt(state.getAttributeValue(ATTRIBUTE_VERSION), 0); for (Element element : state.getChildren()) { if (element.getName().equals(ELEMENT_IGNORE_FILES)) { myIgnoredPatterns.setIgnoreMasks(element.getAttributeValue(ATTRIBUTE_LIST)); } else if (AbstractFileType.ELEMENT_EXTENSION_MAP.equals(element.getName())) { readGlobalMappings(element, false); } } if (savedVersion < 4) { if (savedVersion == 0) { addIgnore(".svn"); } if (savedVersion < 2) { restoreStandardFileExtensions(); } addIgnore("*.pyc"); addIgnore("*.pyo"); addIgnore(".git"); } if (savedVersion < 5) { addIgnore("*.hprof"); } if (savedVersion < 6) { addIgnore("_svn"); } if (savedVersion < 7) { addIgnore(".hg"); } if (savedVersion < 8) { addIgnore("*~"); } if (savedVersion < 9) { addIgnore("__pycache__"); } if (savedVersion < 11) { addIgnore("*.rbc"); } if (savedVersion < 13) { // we want *.lib back since it's an important user artifact for CLion, also for IDEA project itself, since we have some libs. unignoreMask("*.lib"); } if (savedVersion < 15) { // we want .bundle back, bundler keeps useful data there unignoreMask(".bundle"); } if (savedVersion < 16) { // we want .tox back to allow users selecting interpreters from it unignoreMask(".tox"); } if (savedVersion < 17) { addIgnore("*.rbc"); } myIgnoredFileCache.clearCache(); String counter = JDOMExternalizer.readString(state, "fileTypeChangedCounter"); if (counter != null) { fileTypeChangedCount.set(StringUtilRt.parseInt(counter, 0)); autoDetectedAttribute = autoDetectedAttribute.newVersion(fileTypeChangedCount.get()); } }
Example #14
Source File: JDOMExternalizer.java From consulo with Apache License 2.0 | 4 votes |
public static int readInteger(Element root, String name, int defaultValue) { return StringUtilRt.parseInt(readString(root, name), defaultValue); }
Example #15
Source File: VfsDirectoryBasedStorage.java From consulo with Apache License 2.0 | 4 votes |
public static boolean isStorageFile(@Nonnull VirtualFile file) { // ignore system files like .DS_Store on Mac return StringUtilRt.endsWithIgnoreCase(file.getNameSequence(), DirectoryStorageData.DEFAULT_EXT); }
Example #16
Source File: IoDirectoryBasedStorage.java From consulo with Apache License 2.0 | 4 votes |
public static boolean isStorageFile(@Nonnull File file) { // ignore system files like .DS_Store on Mac return StringUtilRt.endsWithIgnoreCase(file.getName(), DirectoryStorageData.DEFAULT_EXT); }
Example #17
Source File: PropertiesComponent.java From consulo with Apache License 2.0 | 4 votes |
default int getInt(@Nonnull String name, int defaultValue) { return StringUtilRt.parseInt(getValue(name), defaultValue); }
Example #18
Source File: ExtensionFileNameMatcher.java From consulo with Apache License 2.0 | 4 votes |
@Override public boolean acceptsCharSequence(@Nonnull @NonNls CharSequence fileName) { return StringUtilRt.endsWithIgnoreCase(fileName, myDotExtension); }
Example #19
Source File: FileUtilRt.java From consulo with Apache License 2.0 | 4 votes |
private static String ensureEnds(@Nonnull String s, final char endsWith) { return StringUtilRt.endsWithChar(s, endsWith) ? s : s + endsWith; }
Example #20
Source File: FileUtilRt.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull public static CharSequence getNameWithoutExtension(@Nonnull CharSequence name) { int i = StringUtilRt.lastIndexOf(name, '.', 0, name.length()); return i < 0 ? name : name.subSequence(0, i); }
Example #21
Source File: FileUtilRt.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull public static String loadFile(@Nonnull File file, @Nullable String encoding, boolean convertLineSeparators) throws IOException { final String s = new String(loadFileText(file, encoding)); return convertLineSeparators ? StringUtilRt.convertLineSeparators(s) : s; }
Example #22
Source File: FileUtilRt.java From consulo with Apache License 2.0 | 4 votes |
public boolean charsEqual(char ch1, char ch2) { return StringUtilRt.charsEqualIgnoreCase(ch1, ch2); }
Example #23
Source File: DataViewsConfigurableUi.java From consulo with Apache License 2.0 | 4 votes |
private int getValueTooltipDelay() { Object value = valueTooltipDelayTextField.getValue(); return value instanceof Number ? ((Number)value).intValue() : StringUtilRt.parseInt((String)value, XDebuggerDataViewSettings.DEFAULT_VALUE_TOOLTIP_DELAY); }
Example #24
Source File: BashPsiFileUtils.java From BashSupport with Apache License 2.0 | 4 votes |
private static String ensureEnds(@NotNull String s, final char endsWith) { return StringUtilRt.endsWithChar(s, endsWith) ? s : s + endsWith; }