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; }
public SslSocketFactory() throws GeneralSecurityException, IOException { super(); SSLContext ctx = SSLContext.getInstance("TLS"); TrustManager[] tms; KeyManager[] kms; try { String caCertPath = System.getProperty(SSL_CA_CERT_PATH); String clientCertPath = System.getProperty(SSL_CLIENT_CERT_PATH); String clientKeyPath = System.getProperty(SSL_CLIENT_KEY_PATH); boolean trustEverybody = StringUtilRt.parseBoolean(System.getProperty(SSL_TRUST_EVERYBODY), false); tms = trustEverybody ? new TrustManager[]{new MyTrustEverybodyManager()} : caCertPath == null ? new TrustManager[]{} : new TrustManager[]{new MyTrustManager(caCertPath)}; kms = clientCertPath != null && clientKeyPath != null ? new KeyManager[]{new MyKeyManager(clientCertPath, clientKeyPath)} : new KeyManager[]{}; } catch (Exception e) { throw new RuntimeException(e); } ctx.init(kms, tms, null); myFactory = ctx.getSocketFactory(); }
public DefaultHtmlDoctypeInitialConfigurator(ProjectManager projectManager, PropertiesComponent propertiesComponent) { if (!propertiesComponent.getBoolean("DefaultHtmlDoctype.MigrateToHtml5")) { propertiesComponent.setValue("DefaultHtmlDoctype.MigrateToHtml5", true); ExternalResourceManagerEx.getInstanceEx() .setDefaultHtmlDoctype(Html5SchemaProvider.getHtml5SchemaLocation(), projectManager.getDefaultProject()); } // sometimes VFS fails to pick up updated schema contents and we need to force refresh if (StringUtilRt.parseInt(propertiesComponent.getValue("DefaultHtmlDoctype.Refreshed"), 0) < VERSION) { propertiesComponent.setValue("DefaultHtmlDoctype.Refreshed", Integer.toString(VERSION)); final String schemaUrl = VfsUtilCore.pathToUrl(Html5SchemaProvider.getHtml5SchemaLocation()); final VirtualFile schemaFile = VirtualFileManager.getInstance().findFileByUrl(schemaUrl); if (schemaFile != null) { schemaFile.getParent().refresh(false, true); } } }
private static int extractArgNum(String[] options) { for (String value : options) { Integer parsedValue = parseArgNum(value); if (parsedValue != null) { return parsedValue; } } if (options.length == 1) { return StringUtilRt.parseInt(options[0], 0); } return 0; }
@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); } }); }
public static String appendToPath(@NotNull String basePath, @NotNull String relativePath) { final boolean endsWithSlash = StringUtilRt.endsWithChar(basePath, '/') || StringUtilRt.endsWithChar(basePath, '\\'); final boolean startsWithSlash = StringUtil.startsWithChar(relativePath, '/') || StringUtil.startsWithChar(relativePath, '\\'); String tail; if (endsWithSlash && startsWithSlash) { tail = trimForwardSlashes(relativePath); } else if (!endsWithSlash && !startsWithSlash && basePath.length() > 0 && relativePath.length() > 0) { tail = "/" + relativePath; } else { tail = relativePath; } return basePath + tail; }
private void setPort(String port) { if (isSocket()) { myPortField.setText(String.valueOf(StringUtilRt.parseInt(port, 0))); } else { myAddressField.setText(port); } }
private static void fillPrimitivesNames(final PsiPrimitiveType type) { PRIMITIVES_NAMES.add(type.getBoxedTypeName()); PRIMITIVES_NAMES.add(type.getCanonicalText()); PRIMITIVES_SHORT_NAMES.add(StringUtilRt.getShortName(type.getBoxedTypeName())); PRIMITIVES_SHORT_NAMES.add(type.getCanonicalText()); }
public CharSequence refFilter(final String root, @NotNull 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; }
@NotNull private static Pair<Boolean, String> parseArguments(@NotNull String arg) { boolean username = StringUtilRt.startsWithIgnoreCase(arg, "username"); String url; String[] split = arg.split(" "); if (split.length > 2) { url = parseUrl(split[2]); } else { url = ""; // XML RPC doesn't like nulls } return Pair.create(username, url); }
private static boolean extractIndex(String[] options) { for (String value : options) { Boolean parsedValue = parseIndex(value); if (parsedValue != null) { return parsedValue; } } if (options.length == 1) { return StringUtilRt.parseBoolean(options[0], false); } return false; }
private static Boolean parseIndex(String value) { Couple<String> pair = parseValue(value); if (pair == null) return null; Boolean parsedValue = StringUtilRt.parseBoolean(pair.getSecond(), false); if ("index".equals(pair.getFirst())) { return parsedValue; } return null; }
private static Integer parseArgNum(String value) { Couple<String> pair = parseValue(value); if (pair == null) return null; Integer parsedValue = StringUtilRt.parseInt(pair.getSecond(), 0); if ("argNum".equals(pair.getFirst())) { return parsedValue; } return null; }
@Nonnull @RequiredUIAccess public FormBuilder addLabeled(@Nonnull final String labelText, @Nonnull Component component) { String newLabelText = labelText; if (!StringUtilRt.endsWithChar(newLabelText, ':')) { newLabelText += ": "; } myLayout.add(Label.create(newLabelText), TableLayout.cell(myLineCount, 0)); myLayout.add(component, TableLayout.cell(myLineCount, 1).fill()); myLineCount++; return this; }
@RequiredUIAccess public static Component left(@Nonnull String text, @Nonnull Component component) { if (!StringUtilRt.endsWithChar(text, ':')) { text += ": "; } HorizontalLayout horizontal = HorizontalLayout.create(); horizontal.add(Label.create(text)); horizontal.add(component); return horizontal; }
@RequiredUIAccess public static Component leftFilled(@Nonnull String text, @Nonnull Component component) { if (!StringUtilRt.endsWithChar(text, ':')) { text += ": "; } DockLayout dock = DockLayout.create(); dock.left(Label.create(text)); dock.center(component); return dock; }
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); } }
@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(); }
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; }
@Override public boolean acceptsCharSequence(@NonNls @NotNull CharSequence fileName) { return StringUtilRt.endsWithIgnoreCase(fileName, myDotExtension); }
private static void fillNonPrimitiveNames(final String typeAsString) { PRIMITIVES_NAMES.add(typeAsString); PRIMITIVES_SHORT_NAMES.add(StringUtilRt.getShortName(typeAsString)); }
@NotNull public static CharSequence getExtension(@NotNull CharSequence fileName) { int index = StringUtilRt.lastIndexOf(fileName, '.', 0, fileName.length()); if (index < 0) return ""; return fileName.subSequence(index + 1, fileName.length()); }
private static String ensureEnds(@NotNull String s, final char endsWith) { return StringUtilRt.endsWithChar(s, endsWith) ? s : s + endsWith; }
@NotNull public static String loadFile(@NotNull File file, @Nullable @NonNls String encoding, boolean convertLineSeparators) throws IOException { final String s = new String(loadFileText(file, encoding)); return convertLineSeparators ? StringUtilRt.convertLineSeparators(s) : s; }
@Override public boolean charsEqual(char ch1, char ch2) { return StringUtilRt.charsEqualIgnoreCase(ch1, ch2); }
@NotNull public static Map<String, Element> loadFrom(@Nullable VirtualFile dir, @Nullable TrackingPathMacroSubstitutor pathMacroSubstitutor) { if (dir == null || !dir.exists()) { return Collections.emptyMap(); } StringInterner interner = new StringInterner(); Map<String, Element> fileToState = new THashMap<String, Element>(); for (VirtualFile file : dir.getChildren()) { // ignore system files like .DS_Store on Mac if (!StringUtilRt.endsWithIgnoreCase(file.getNameSequence(), FileStorageCoreUtil.DEFAULT_EXT)) { continue; } try { if (file.getLength() == 0) { LOG.warn("Ignore empty file " + file.getPath()); continue; } Element element = JDOMUtil.load(file.getInputStream()); String componentName = FileStorageCoreUtil.getComponentNameIfValid(element); if (componentName == null) { continue; } if (!element.getName().equals(FileStorageCoreUtil.COMPONENT)) { LOG.error("Incorrect root tag name (" + element.getName() + ") in " + file.getPresentableUrl()); continue; } List<Element> elementChildren = element.getChildren(); if (elementChildren.isEmpty()) { continue; } Element state = (Element)elementChildren.get(0).detach(); if (JDOMUtil.isEmpty(state)) { continue; } JDOMUtil.internElement(state, interner); if (pathMacroSubstitutor != null) { pathMacroSubstitutor.expandPaths(state); pathMacroSubstitutor.addUnknownMacros(componentName, PathMacrosCollector.getMacroNames(state)); } fileToState.put(file.getName(), state); } catch (Throwable e) { LOG.warn("Unable to load state", e); } } return fileToState; }
public int getInt(@NotNull String name, int defaultValue) { return StringUtilRt.parseInt(getValue(name), defaultValue); }
protected static int getIntParameter(@NotNull String name, @NotNull QueryStringDecoder urlDecoder) { return StringUtilRt.parseInt(StringUtil.nullize(ContainerUtil.getLastItem(urlDecoder.parameters().get(name)), true), -1); }
@Nullable @Override public String execute(@NotNull QueryStringDecoder urlDecoder, @NotNull FullHttpRequest request, @NotNull ChannelHandlerContext context) throws IOException { final boolean keepAlive = HttpUtil.isKeepAlive(request); final Channel channel = context.channel(); OpenFileRequest apiRequest; if (request.method() == HttpMethod.POST) { apiRequest = gson.getValue().fromJson(createJsonReader(request), OpenFileRequest.class); } else { apiRequest = new OpenFileRequest(); apiRequest.file = StringUtil.nullize(getStringParameter("file", urlDecoder), true); apiRequest.line = getIntParameter("line", urlDecoder); apiRequest.column = getIntParameter("column", urlDecoder); apiRequest.focused = getBooleanParameter("focused", urlDecoder, true); } int prefixLength = 1 + PREFIX.length() + 1 + getServiceName().length() + 1; String path = urlDecoder.path(); if (path.length() > prefixLength) { Matcher matcher = LINE_AND_COLUMN.matcher(path).region(prefixLength, path.length()); LOG.assertTrue(matcher.matches()); if (apiRequest.file == null) { apiRequest.file = matcher.group(1).trim(); } if (apiRequest.line == -1) { apiRequest.line = StringUtilRt.parseInt(matcher.group(2), 1); } if (apiRequest.column == -1) { apiRequest.column = StringUtilRt.parseInt(matcher.group(3), 1); } } if (apiRequest.file == null) { sendStatus(HttpResponseStatus.BAD_REQUEST, keepAlive, channel); return null; } openFile(apiRequest) .done(new Consumer<Void>() { @Override public void consume(Void aVoid) { sendStatus(HttpResponseStatus.OK, keepAlive, channel); } }) .rejected(new Consumer<Throwable>() { @Override public void consume(Throwable throwable) { if (throwable == NOT_FOUND) { sendStatus(HttpResponseStatus.NOT_FOUND, keepAlive, channel); } else { // todo send error sendStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR, keepAlive, channel); LOG.error(throwable); } } }); return null; }
@Override public void loadState(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); } } 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"); } myIgnoredFileCache.clearCache(); String counter = JDOMExternalizer.readString(state, "fileTypeChangedCounter"); if (counter != null) { fileTypeChangedCount.set(StringUtilRt.parseInt(counter, 0)); autoDetectedAttribute = autoDetectedAttribute.newVersion(fileTypeChangedCount.get()); } }
public static int readInteger(Element root, String name, int defaultValue) { return StringUtilRt.parseInt(readString(root, name), defaultValue); }
public AutoTestManager(@NotNull Project project) { myProject = project; myDelayMillis = StringUtilRt.parseInt(PropertiesComponent.getInstance(project).getValue(AUTO_TEST_MANAGER_DELAY), AUTO_TEST_MANAGER_DELAY_DEFAULT); myDocumentWatcher = createWatcher(); }
private int getValueTooltipDelay() { Object value = valueTooltipDelayTextField.getValue(); return value instanceof Number ? ((Number)value).intValue() : StringUtilRt.parseInt((String)value, XDebuggerDataViewSettings.DEFAULT_VALUE_TOOLTIP_DELAY); }
private static int getIntegerValue(String s, int defaultValue) { int value = StringUtilRt.parseInt(s, defaultValue); return value < 0 ? defaultValue : value; }