Java 类com.intellij.util.text.StringFactory 实例源码

项目:tools-idea    文件:FileNameCache.java   
@NotNull
public static String getVFileName(int nameId) {
  IntObjectLinkedMap.MapEntry<Object> entry = getEntry(nameId);
  Object name = entry.value;
  if (name instanceof String) {
    //noinspection StringEquality
    return (String)name;
  }

  byte[] bytes = (byte[])name;
  int length = bytes.length;
  char[] chars = new char[length];
  for (int i = 0; i < length; i++) {
    chars[i] = (char)bytes[i];
  }
  return StringFactory.createShared(chars);
}
项目:intellij-ce-playground    文件:ModuleInsight.java   
private void scanSourceFile(File file, final Set<String> usedPackages) {
  myProgress.setText2(file.getName());
  try {
    final char[] chars = FileUtil.loadFileText(file);
    scanSourceFileForImportedPackages(StringFactory.createShared(chars), new Consumer<String>() {
      public void consume(final String s) {
        usedPackages.add(myInterner.intern(s));
      }
    });
  }
  catch (IOException e) {
    LOG.info(e);
  }
}
项目:intellij-ce-playground    文件:ChunkExtractor.java   
private static void addChunk(@NotNull CharSequence chars,
                             int start,
                             int end,
                             @NotNull TextAttributes originalAttrs,
                             boolean bold,
                             @Nullable UsageType usageType,
                             @NotNull List<TextChunk> result) {
  if (start >= end) return;

  TextAttributes attrs = bold
                         ? TextAttributes.merge(originalAttrs, new TextAttributes(null, null, null, null, Font.BOLD))
                         : originalAttrs;
  result.add(new TextChunk(attrs, StringFactory.createShared(CharArrayUtil.fromSequence(chars, start, end)), usageType));
}
项目:intellij-ce-playground    文件:VfsUtilCore.java   
/**
 * Gets the relative path of <code>file</code> to its <code>ancestor</code>. Uses <code>separator</code> for
 * separating files.
 *
 * @param file      the file
 * @param ancestor  parent file
 * @param separator character to use as files separator
 * @return the relative path or {@code null} if {@code ancestor} is not ancestor for {@code file}
 */
@Nullable
public static String getRelativePath(@NotNull VirtualFile file, @NotNull VirtualFile ancestor, char separator) {
  if (!file.getFileSystem().equals(ancestor.getFileSystem())) {
    return null;
  }

  int length = 0;
  VirtualFile parent = file;
  while (true) {
    if (parent == null) return null;
    if (parent.equals(ancestor)) break;
    if (length > 0) {
      length++;
    }
    length += parent.getNameSequence().length();
    parent = parent.getParent();
  }

  char[] chars = new char[length];
  int index = chars.length;
  parent = file;
  while (true) {
    if (parent.equals(ancestor)) break;
    if (index < length) {
      chars[--index] = separator;
    }
    CharSequence name = parent.getNameSequence();
    for (int i = name.length() - 1; i >= 0; i--) {
      chars[--index] = name.charAt(i);
    }
    parent = parent.getParent();
  }
  return StringFactory.createShared(chars);
}
项目:intellij-ce-playground    文件:VfsUtilCore.java   
@NotNull
public static String loadText(@NotNull VirtualFile file, int length) throws IOException {
  InputStreamReader reader = new InputStreamReader(file.getInputStream(), file.getCharset());
  try {
    return StringFactory.createShared(FileUtil.loadText(reader, length));
  }
  finally {
    reader.close();
  }
}
项目:intellij-ce-playground    文件:VirtualFileSystemEntry.java   
@Override
@NotNull
public String getUrl() {
  String protocol = getFileSystem().getProtocol();
  int prefixLen = protocol.length() + "://".length();
  char[] chars = appendPathOnFileSystem(prefixLen, new int[]{prefixLen});
  copyString(chars, copyString(chars, 0, protocol), "://");
  return StringFactory.createShared(chars);
}
项目:intellij-ce-playground    文件:JDOMUtil.java   
@NotNull
public static byte[] printDocument(@NotNull Document document, String lineSeparator) throws IOException {
  CharArrayWriter writer = new CharArrayWriter();
  writeDocument(document, writer, lineSeparator);

  return StringFactory.createShared(writer.toCharArray()).getBytes(CharsetToolkit.UTF8_CHARSET);
}
项目:intellij-ce-playground    文件:StringUtil.java   
@NotNull
@Contract(pure = true)
public static String repeatSymbol(final char aChar, final int count) {
  char[] buffer = new char[count];
  Arrays.fill(buffer, aChar);
  return StringFactory.createShared(buffer);
}
项目:intellij-ce-playground    文件:StringUtil.java   
/**
 * @deprecated use #capitalize(String)
 */
@Contract(value = "null -> null; !null -> !null", pure = true)
public static String firstLetterToUpperCase(@Nullable final String displayString) {
  if (displayString == null || displayString.isEmpty()) return displayString;
  char firstChar = displayString.charAt(0);
  char uppedFirstChar = toUpperCase(firstChar);

  if (uppedFirstChar == firstChar) return displayString;

  char[] buffer = displayString.toCharArray();
  buffer[0] = uppedFirstChar;
  return StringFactory.createShared(buffer);
}
项目:intellij-ce-playground    文件:FileUtil.java   
@NotNull
public static String loadTextAndClose(@NotNull Reader reader) throws IOException {
  try {
    return StringFactory.createShared(adaptiveLoadText(reader));
  }
  finally {
    reader.close();
  }
}
项目:intellij-ce-playground    文件:CompressionUtil.java   
@NotNull
public static CharSequence uncompressStringRawBytes(@NotNull Object compressed) {
  if (compressed instanceof CharSequence) return (CharSequence)compressed;
  byte[] b = (byte[])compressed;
  try {
    int uncompressedLength = Snappy.getUncompressedLength(b, 0);
    byte[] bytes = spareBufferLocal.getBuffer(uncompressedLength);
    int bytesLength = Snappy.uncompress(b, 0, b.length, bytes, 0);
    ByteArrayInputStream byteStream = new ByteArrayInputStream(bytes, 0, bytesLength);
    @NotNull DataInput in = new DataInputStream(byteStream);

    int len = DataInputOutputUtil.readINT(in);
    char[] chars = new char[len];

    for (int i=0; i<len; i++) {
      int c = DataInputOutputUtil.readINT(in);
      chars[i] = (char)c;
    }
    return StringFactory.createShared(chars);
  }
  catch (CorruptionException ex) {
    throw new RuntimeException(ex);
  }
  catch (IOException e) {
    throw new RuntimeException(e);
  }
}
项目:intellij-ce-playground    文件:PsiFileSystemItemUtil.java   
@Nullable
public static String getRelativePathFromAncestor(PsiFileSystemItem file, PsiFileSystemItem ancestor) {
  int length = 0;
  PsiFileSystemItem parent = file;

  while (true) {
    if (parent == null) return null;
    if (parent.equals(ancestor)) break;
    if (length > 0) {
      length++;
    }
    length += parent.getName().length();
    parent = parent.getParent();
  }

  char[] chars = new char[length];
  int index = chars.length;
  parent = file;

  while (true) {
    if (parent.equals(ancestor)) break;
    if (index < length) {
      chars[--index] = '/';
    }
    String name = parent.getName();
    for (int i = name.length() - 1; i >= 0; i--) {
      chars[--index] = name.charAt(i);
    }
    parent = parent.getParent();
  }
  return StringFactory.createShared(chars);
}
项目:intellij-ce-playground    文件:CharTableImpl.java   
@NotNull
private static String createSequence(@NotNull CharSequence text, int startOffset, int endOffset) {
  if (text instanceof String) {
    return ((String)text).substring(startOffset, endOffset);
  }
  char[] buf = new char[endOffset - startOffset];
  CharArrayUtil.getChars(text, buf, startOffset, 0, buf.length);
  return StringFactory.createShared(buf); // this way the .toString() doesn't create another instance (as opposed to new CharArrayCharSequence())
}
项目:tools-idea    文件:ModuleInsight.java   
private void scanSourceFile(File file, final Set<String> usedPackages) {
  myProgress.setText2(file.getName());
  try {
    final char[] chars = FileUtil.loadFileText(file);
    scanSourceFileForImportedPackages(StringFactory.createShared(chars), new Consumer<String>() {
      public void consume(final String s) {
        usedPackages.add(myInterner.intern(s));
      }
    });
  }
  catch (IOException e) {
    LOG.info(e);
  }
}
项目:tools-idea    文件:ChunkExtractor.java   
private static void addChunk(@NotNull CharSequence chars,
                             int start,
                             int end,
                             @NotNull TextAttributes originalAttrs,
                             boolean bold,
                             @NotNull List<TextChunk> result) {
  if (start >= end) return;

  TextAttributes attrs = bold
                         ? TextAttributes.merge(originalAttrs, new TextAttributes(null, null, null, null, Font.BOLD))
                         : originalAttrs;
  result.add(new TextChunk(attrs, StringFactory.createShared(CharArrayUtil.fromSequence(chars, start, end))));
}
项目:tools-idea    文件:VfsUtilCore.java   
public static String doGetRelative(VirtualFile file, VirtualFile ancestor, char separator) {
  int length = 0;
  VirtualFile parent = file;
  while (true) {
    if (parent == null) return null;
    if (parent.equals(ancestor)) break;
    if (length > 0) {
      length++;
    }
    length += parent.getName().length();
    parent = parent.getParent();
  }

  char[] chars = new char[length];
  int index = chars.length;
  parent = file;
  while (true) {
    if (parent.equals(ancestor)) break;
    if (index < length) {
      chars[--index] = separator;
    }
    String name = parent.getName();
    for (int i = name.length() - 1; i >= 0; i--) {
      chars[--index] = name.charAt(i);
    }
    parent = parent.getParent();
  }
  return StringFactory.createShared(chars);
}
项目:tools-idea    文件:VfsUtilCore.java   
@NotNull
public static String loadText(@NotNull VirtualFile file, int length) throws IOException {
  InputStreamReader reader = new InputStreamReader(file.getInputStream(), file.getCharset());
  try {
    return StringFactory.createShared(FileUtil.loadText(reader, length));
  }
  finally {
    reader.close();
  }
}
项目:tools-idea    文件:VirtualFileSystemEntry.java   
@Override
@NotNull
public String getUrl() {
  String protocol = getFileSystem().getProtocol();
  int prefixLen = protocol.length() + "://".length();
  int[] pos = {prefixLen};
  char[] chars = appendPathOnFileSystem(prefixLen, pos);
  copyString(chars, copyString(chars, 0, protocol), "://");
  return chars.length == pos[0] ? StringFactory.createShared(chars) : new String(chars, 0, pos[0]);
}
项目:tools-idea    文件:VirtualFileSystemEntry.java   
@Override
@NotNull
public String getPath() {
  int[] pos = {0};
  char[] chars = appendPathOnFileSystem(0, pos);
  return chars.length == pos[0] ? StringFactory.createShared(chars) : new String(chars, 0, pos[0]);
}
项目:tools-idea    文件:JDOMUtil.java   
@NotNull
public static byte[] printDocument(@NotNull Document document, String lineSeparator) throws IOException {
  CharArrayWriter writer = new CharArrayWriter();
  writeDocument(document, writer, lineSeparator);

  return StringFactory.createShared(writer.toCharArray()).getBytes(ENCODING);
}
项目:tools-idea    文件:StringUtil.java   
/**
 * @deprecated use #capitalize(String)
 */
@Nullable
public static String firstLetterToUpperCase(@Nullable final String displayString) {
  if (displayString == null || displayString.isEmpty()) return displayString;
  char firstChar = displayString.charAt(0);
  char uppedFirstChar = toUpperCase(firstChar);

  if (uppedFirstChar == firstChar) return displayString;

  char[] buffer = displayString.toCharArray();
  buffer[0] = uppedFirstChar;
  return StringFactory.createShared(buffer);
}
项目:tools-idea    文件:FileUtil.java   
@NotNull
public static String loadTextAndClose(@NotNull Reader reader) throws IOException {
  try {
    return StringFactory.createShared(adaptiveLoadText(reader));
  }
  finally {
    reader.close();
  }
}
项目:tools-idea    文件:PsiFileSystemItemUtil.java   
@Nullable
public static String getRelativePathFromAncestor(PsiFileSystemItem file, PsiFileSystemItem ancestor) {
  int length = 0;
  PsiFileSystemItem parent = file;

  while (true) {
    if (parent == null) return null;
    if (parent.equals(ancestor)) break;
    if (length > 0) {
      length++;
    }
    length += parent.getName().length();
    parent = parent.getParent();
  }

  char[] chars = new char[length];
  int index = chars.length;
  parent = file;

  while (true) {
    if (parent.equals(ancestor)) break;
    if (index < length) {
      chars[--index] = '/';
    }
    String name = parent.getName();
    for (int i = name.length() - 1; i >= 0; i--) {
      chars[--index] = name.charAt(i);
    }
    parent = parent.getParent();
  }
  return StringFactory.createShared(chars);
}
项目:tools-idea    文件:CharTableImpl.java   
@NotNull
private static String createSequence(@NotNull CharSequence text) {
  char[] buf = new char[text.length()];
  CharArrayUtil.getChars(text, buf, 0);

  return StringFactory.createShared(buf); // this way the .toString() doesn't create another instance (as opposed to new CharArrayCharSequence())
}
项目:consulo    文件:VfsUtilCore.java   
/**
 * Gets the relative path of <code>file</code> to its <code>ancestor</code>. Uses <code>separator</code> for
 * separating files.
 *
 * @param file      the file
 * @param ancestor  parent file
 * @param separator character to use as files separator
 * @return the relative path or {@code null} if {@code ancestor} is not ancestor for {@code file}
 */
@Nullable
public static String getRelativePath(@Nonnull VirtualFile file, @Nonnull VirtualFile ancestor, char separator) {
  if (!file.getFileSystem().equals(ancestor.getFileSystem())) {
    return null;
  }

  int length = 0;
  VirtualFile parent = file;
  while (true) {
    if (parent == null) return null;
    if (parent.equals(ancestor)) break;
    if (length > 0) {
      length++;
    }
    length += parent.getNameSequence().length();
    parent = parent.getParent();
  }

  char[] chars = new char[length];
  int index = chars.length;
  parent = file;
  while (true) {
    if (parent.equals(ancestor)) break;
    if (index < length) {
      chars[--index] = separator;
    }
    CharSequence name = parent.getNameSequence();
    for (int i = name.length() - 1; i >= 0; i--) {
      chars[--index] = name.charAt(i);
    }
    parent = parent.getParent();
  }
  return StringFactory.createShared(chars);
}
项目:consulo    文件:VfsUtilCore.java   
@Nonnull
public static String loadText(@Nonnull VirtualFile file, int length) throws IOException {
  InputStreamReader reader = new InputStreamReader(file.getInputStream(), file.getCharset());
  try {
    return StringFactory.createShared(FileUtil.loadText(reader, length));
  }
  finally {
    reader.close();
  }
}
项目:consulo    文件:VirtualFileSystemEntry.java   
@Override
@Nonnull
public String getUrl() {
  String protocol = getFileSystem().getProtocol();
  int prefixLen = protocol.length() + "://".length();
  char[] chars = appendPathOnFileSystem(prefixLen, new int[]{prefixLen});
  copyString(chars, copyString(chars, 0, protocol), "://");
  return StringFactory.createShared(chars);
}
项目:consulo    文件:JDOMUtil.java   
@Nonnull
public static byte[] printDocument(@Nonnull Document document, String lineSeparator) throws IOException {
  CharArrayWriter writer = new CharArrayWriter();
  writeDocument(document, writer, lineSeparator);

  return StringFactory.createShared(writer.toCharArray()).getBytes(CharsetToolkit.UTF8_CHARSET);
}
项目:consulo    文件:StringUtil.java   
@Nonnull
@Contract(pure = true)
public static String repeatSymbol(final char aChar, final int count) {
  char[] buffer = new char[count];
  Arrays.fill(buffer, aChar);
  return StringFactory.createShared(buffer);
}
项目:consulo    文件:StringUtil.java   
/**
 * @deprecated use #capitalize(String)
 */
@Contract(value = "null -> null; !null -> !null", pure = true)
public static String firstLetterToUpperCase(@Nullable final String displayString) {
  if (displayString == null || displayString.isEmpty()) return displayString;
  char firstChar = displayString.charAt(0);
  char uppedFirstChar = toUpperCase(firstChar);

  if (uppedFirstChar == firstChar) return displayString;

  char[] buffer = displayString.toCharArray();
  buffer[0] = uppedFirstChar;
  return StringFactory.createShared(buffer);
}
项目:consulo    文件:FileUtil.java   
@Nonnull
public static String loadTextAndClose(@Nonnull Reader reader) throws IOException {
  try {
    return StringFactory.createShared(adaptiveLoadText(reader));
  }
  finally {
    reader.close();
  }
}
项目:consulo    文件:CompressionUtil.java   
@Nonnull
public static CharSequence uncompressStringRawBytes(@Nonnull Object compressed) {
  if (compressed instanceof CharSequence) return (CharSequence)compressed;
  byte[] b = (byte[])compressed;
  try {
    int uncompressedLength = Snappy.getUncompressedLength(b, 0);
    byte[] bytes = spareBufferLocal.getBuffer(uncompressedLength);
    int bytesLength = Snappy.uncompress(b, 0, b.length, bytes, 0);
    ByteArrayInputStream byteStream = new ByteArrayInputStream(bytes, 0, bytesLength);
    @Nonnull DataInput in = new DataInputStream(byteStream);

    int len = DataInputOutputUtil.readINT(in);
    char[] chars = new char[len];

    for (int i=0; i<len; i++) {
      int c = DataInputOutputUtil.readINT(in);
      chars[i] = (char)c;
    }
    return StringFactory.createShared(chars);
  }
  catch (CorruptionException ex) {
    throw new RuntimeException(ex);
  }
  catch (IOException e) {
    throw new RuntimeException(e);
  }
}
项目:consulo    文件:PsiFileSystemItemUtil.java   
@Nullable
public static String getRelativePathFromAncestor(PsiFileSystemItem file, PsiFileSystemItem ancestor) {
  int length = 0;
  PsiFileSystemItem parent = file;

  while (true) {
    if (parent == null) return null;
    if (parent.equals(ancestor)) break;
    if (length > 0) {
      length++;
    }
    length += parent.getName().length();
    parent = parent.getParent();
  }

  char[] chars = new char[length];
  int index = chars.length;
  parent = file;

  while (true) {
    if (parent.equals(ancestor)) break;
    if (index < length) {
      chars[--index] = '/';
    }
    String name = parent.getName();
    for (int i = name.length() - 1; i >= 0; i--) {
      chars[--index] = name.charAt(i);
    }
    parent = parent.getParent();
  }
  return StringFactory.createShared(chars);
}
项目:consulo    文件:CharTableImpl.java   
@Nonnull
private static String createSequence(@Nonnull CharSequence text, int startOffset, int endOffset) {
  if (text instanceof String) {
    return ((String)text).substring(startOffset, endOffset);
  }
  char[] buf = new char[endOffset - startOffset];
  CharArrayUtil.getChars(text, buf, startOffset, 0, buf.length);
  return StringFactory.createShared(buf); // this way the .toString() doesn't create another instance (as opposed to new CharArrayCharSequence())
}
项目:intellij-ce-playground    文件:CommonSourceRootDetectionUtil.java   
@Override
protected CharSequence loadText(final File file) throws IOException {
  return StringFactory.createShared(loadFileTextSkippingBom(file));
}
项目:intellij-ce-playground    文件:VirtualFileSystemEntry.java   
@Override
@NotNull
public String getPath() {
  return StringFactory.createShared(appendPathOnFileSystem(0, new int[]{0}));
}
项目:intellij-ce-playground    文件:StreamUtil.java   
public static String convertSeparators(String s) {
  return StringFactory.createShared(convertSeparators(s.toCharArray()));
}
项目:intellij-ce-playground    文件:StreamUtil.java   
public static String readTextFrom(Reader reader) throws IOException {
  return StringFactory.createShared(readText(reader));
}
项目:intellij-ce-playground    文件:Base64Converter.java   
public static String encode(@NotNull byte[] octetString) {
  int bits24;
  int bits6;

  char[] out
    = new char[((octetString.length - 1) / 3 + 1) * 4];

  int outIndex = 0;
  int i = 0;

  while ((i + 3) <= octetString.length) {
    // store the octets
    bits24 = (octetString[i++] & 0xFF) << 16;
    bits24 |= (octetString[i++] & 0xFF) << 8;
    bits24 |= (octetString[i++] & 0xFF);

    bits6 = (bits24 & 0x00FC0000) >> 18;
    out[outIndex++] = alphabet[bits6];
    bits6 = (bits24 & 0x0003F000) >> 12;
    out[outIndex++] = alphabet[bits6];
    bits6 = (bits24 & 0x00000FC0) >> 6;
    out[outIndex++] = alphabet[bits6];
    bits6 = (bits24 & 0x0000003F);
    out[outIndex++] = alphabet[bits6];
  }

  if (octetString.length - i == 2) {
    // store the octets
    bits24 = (octetString[i] & 0xFF) << 16;
    bits24 |= (octetString[i + 1] & 0xFF) << 8;

    bits6 = (bits24 & 0x00FC0000) >> 18;
    out[outIndex++] = alphabet[bits6];
    bits6 = (bits24 & 0x0003F000) >> 12;
    out[outIndex++] = alphabet[bits6];
    bits6 = (bits24 & 0x00000FC0) >> 6;
    out[outIndex++] = alphabet[bits6];

    // padding
    out[outIndex] = '=';
  }
  else if (octetString.length - i == 1) {
    // store the octets
    bits24 = (octetString[i] & 0xFF) << 16;

    bits6 = (bits24 & 0x00FC0000) >> 18;
    out[outIndex++] = alphabet[bits6];
    bits6 = (bits24 & 0x0003F000) >> 12;
    out[outIndex++] = alphabet[bits6];

    // padding
    out[outIndex++] = '=';
    out[outIndex] = '=';
  }

  return StringFactory.createShared(out);
}
项目:intellij-ce-playground    文件:CharTrie.java   
/**
 * Returns reversed string by unique hash code.
 */
public String getReversedString(int hashCode) {
  return StringFactory.createShared(getReversedChars(hashCode));
}