java.lang.CharSequence.codePoints()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(6.1k)|赞(0)|评价(0)|浏览(191)

本文整理了Java中java.lang.CharSequence.codePoints()方法的一些代码示例,展示了CharSequence.codePoints()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CharSequence.codePoints()方法的具体详情如下:
包路径:java.lang.CharSequence
类名称:CharSequence
方法名:codePoints

CharSequence.codePoints介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

public static boolean containsHanScript(String s) {
  return s.codePoints().anyMatch(
      codepoint ->
      Character.UnicodeScript.of(codepoint) == Character.UnicodeScript.HAN);
}

代码示例来源:origin: ml.alternet/alternet-tools

/**
 * Defines a range with the characters given in a string.
 *
 * @param equal <code>true</code> to indicate inclusion,
 *      <code>false</code> to indicate exclusion.
 * @param chars The actual characters.
 *
 * @see Reversible#includes()
 */
Chars(boolean equal, CharSequence chars) {
  this(equal, chars.codePoints());
}

代码示例来源:origin: stackoverflow.com

String result = "Hello world."
 .codePoints()
 .mapToObj(c -> c == ' ' ? " ": "*")
 .collect(Collectors.joining());

代码示例来源:origin: stackoverflow.com

IntStream in = "Convert me to a String".codePoints();

String intStreamToString = in.collect(StringBuilder::new,
    StringBuilder::appendCodePoint, StringBuilder::append)
    .toString();

System.out.println(intStreamToString);

代码示例来源:origin: stackoverflow.com

public static void main(String[] args) {
 String sample = "A" + "\uD835\uDD0A" + "B" + "C";
 int match = 0x1D50A;
 sample.codePoints()
    .forEach(cp -> System.out.println(cp == match));
}

代码示例来源:origin: com.globalmentor/globalmentor-core

/**
 * Convenience method to create a stream producing {@link CodePointCharacter} instances from the code points in the given character sequence. The
 * {@link CodePointCharacter} instances are only created when they are needed in stream processing.
 * @param charSequence The character sequence the code points of which should be processed.
 * @return A stream of {@link CodePointCharacter} instances representing the code points of the given character sequence.
 */
public static Stream<CodePointCharacter> streamOf(@Nonnull final CharSequence charSequence) {
  return charSequence.codePoints().mapToObj(CodePointCharacter::of);
}

代码示例来源:origin: stackoverflow.com

// if you want to work line by line, use Files.readAllLines()
// if you use Guava, there's also Guava's Files.toString() for reading the whole file into a String
byte[] bytes = Files.readAllBytes(Paths.get("test.txt"));
String text = new String(bytes, StandardCharsets.UTF_8);

IntStream codePoints = text.codePoints();

// do something with the code points
codePoints.forEach(codePoint -> System.out.println(codePoint));

代码示例来源:origin: org.seleniumhq.selenium/selenium-api

private Actions addKeyAction(CharSequence key, IntConsumer consumer) {
 // Verify that we only have a single character to type.
 if (key.codePoints().count() != 1) {
  throw new IllegalStateException(String.format(
   "Only one code point is allowed at a time: %s", key));
 }
 key.codePoints().forEach(consumer);
 return this;
}

代码示例来源:origin: stackoverflow.com

String s = "۱۲۳۴۵۶۷۸۹";
int[] cps = s.codePoints()
    .map((cp) -> Character.isDigit(cp) ? '0' + Character.digit(cp, 10)  : cp)
    .toArray();
System.out.println(new String(cps, 0, cps.length));

代码示例来源:origin: stackoverflow.com

public class NoopParserStaticArray implements Parser {
  private static final String[] EMPTY_STRING_ARRAY = new String[0];

  @Override public String[] supportedSchemas() {
    return EMPTY_STRING_ARRAY;
  }

  @Override public void parse(String s) {
    s.codePoints().count();
  }
}

代码示例来源:origin: org.jline/jline

/**
 * Insert the specified chars into the buffer, setting the cursor to the end of the insertion point.
 */
public void write(CharSequence str) {
  Objects.requireNonNull(str);
  write(str.codePoints().toArray());
}

代码示例来源:origin: stackoverflow.com

public static String stars(String t) {
  return t.codePoints().map(c -> c == ' ' ? ' ': '*').mapToObj(Stars::codePointToString).collect(Collectors.joining());
}

private static String codePointToString(int codePoint) {
  return new String(new int[] { codePoint }, 0, 1);
}

代码示例来源:origin: stackoverflow.com

public static void main(String[] args) {
  final Scanner input = new Scanner(System.in);
  System.out.println("Enter a character to get value of it:");
  String inputString =  input.next();
  // Print -1 on an empty input
  final OptionalInt codepoint = inputString.codePoints().findFirst();
  System.out.println(codepoint.isPresent() ? codepoint.get() : -1);
}

代码示例来源:origin: org.jline/jline

public void write(CharSequence str, boolean overTyping) {
  Objects.requireNonNull(str);
  int[] ucps = str.codePoints().toArray();
  if (overTyping) {
    delete(ucps.length);
  }
  write(ucps);
}

代码示例来源:origin: com.machinepublishers/jbrowserdriver

private static boolean isChord(CharSequence charSequence) {
 int[] codePoints = charSequence.codePoints().toArray();
 if (codePoints.length > 0) {
  char[] chars = Character.toChars(codePoints[codePoints.length - 1]);
  if (chars.length == 1) {
   return Keys.NULL.equals(Keys.getKeyFromUnicode(chars[0]));
  }
 }
 return false;
}

代码示例来源:origin: org.seleniumhq.selenium/selenium-api

@Override
 public List<Interaction> asInteractions(PointerInput mouse, KeyInput keyboard) {
  List<Interaction> interactions = new ArrayList<>(optionallyClickElement(mouse));

  for (CharSequence keys : keysToSend) {
   keys.codePoints().forEach(codePoint -> {
    interactions.add(keyboard.createKeyDown(codePoint));
    interactions.add(keyboard.createKeyUp(codePoint));
   });
  }

  return Collections.unmodifiableList(interactions);
 }
}

代码示例来源:origin: stackoverflow.com

jasonString.toCodePoints()
    .filter(cp -> cp >= 256)
    .forEach(cp -> {
      System.out.printf("U+%X = %s%n",
        cp, Character.getName(cp));
     });

boolean containsEmoji(String s) {
  return s.codePoints().anyMatch(cp ->
    UnicodeBlock.of(cp).equals(UnicodeBlock.EMOTICONS));
}

代码示例来源:origin: stackoverflow.com

private static boolean check(String input) {
  IntStream characters = input.codePoints().filter(Character::isLetter);
  return characters
      .distinct()
      .count() == characters.count();
}

代码示例来源:origin: org.seleniumhq.selenium/selenium-api

private Actions sendKeysInTicks(CharSequence... keys) {
 if (keys == null) {
  throw new IllegalArgumentException("Keys should be a not null CharSequence");
 }
 for (CharSequence key : keys) {
  key.codePoints().forEach(codePoint -> {
   tick(defaultKeyboard.createKeyDown(codePoint));
   tick(defaultKeyboard.createKeyUp(codePoint));
  });
 }
 return this;
}

代码示例来源:origin: org.jline/jline

public synchronized boolean write(CharSequence d) {
  d.codePoints().forEachOrdered(c -> {
    if (!vt100_write(c) && !dumb_write(c) && c <= 0xffff) {
      dumb_echo(c);
    }
  });
  return true;
}

相关文章