java.lang.Character.isBmpCodePoint()方法的使用及代码示例

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

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

Character.isBmpCodePoint介绍

[英]Returns true if the given code point is in the Basic Multilingual Plane (BMP). Such code points can be represented by a single char.
[中]如果给定代码点位于基本多语言平面(BMP)中,则返回true。这样的代码点可以用单个字符表示。

代码示例

代码示例来源:origin: goldmansachs/gs-collections

  1. public boolean accept(int codePoint)
  2. {
  3. return Character.isBmpCodePoint(codePoint);
  4. }
  5. };

代码示例来源:origin: eclipse/eclipse-collections

  1. public boolean accept(int codePoint)
  2. {
  3. return Character.isBmpCodePoint(codePoint);
  4. }
  5. };

代码示例来源:origin: eclipse/eclipse-collections

  1. public boolean accept(int codePoint)
  2. {
  3. return Character.isBmpCodePoint(codePoint);
  4. }
  5. };

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

  1. /**
  2. * Determines whether the code point is in the Basic Multilingual Plane (BMP) and can thus be represented by a single <code>char</code>.
  3. * @return <code>true</code> if the code point is in the BMP.
  4. * @see #isBmpCodePoint()
  5. */
  6. public boolean isBmpCodePoint() {
  7. return Character.isBmpCodePoint(codePoint);
  8. }

代码示例来源:origin: com.goldmansachs/gs-collections

  1. public boolean accept(int codePoint)
  2. {
  3. return Character.isBmpCodePoint(codePoint);
  4. }
  5. };

代码示例来源:origin: org.eclipse.collections/eclipse-collections

  1. public boolean accept(int codePoint)
  2. {
  3. return Character.isBmpCodePoint(codePoint);
  4. }
  5. };

代码示例来源:origin: anba/es6draft

  1. @Override
  2. public int codeToMbcLength(int code) {
  3. if (Character.isBmpCodePoint(code)) {
  4. return 2;
  5. }
  6. return 4;
  7. }

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

  1. IntStream converted = utf8mb4string.codePoints().map(cp -> Character.isBmpCodePoint(cp) ? cp : '\uFFFD');
  2. String str = converted.collect(StringBuilder::new, (buf, ch) -> buf.append((char) ch), StringBuilder::append).toString();

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

  1. private boolean isValidUTF8(final String string) {
  2. for (int i = 0; i < string.length(); i++) {
  3. final char c = string.charAt(i);
  4. if (!Character.isBmpCodePoint(c)) {
  5. return false;
  6. }
  7. }
  8. return true;
  9. }

代码示例来源:origin: anba/es6draft

  1. /**
  2. * Returns the string representation of a single code point.
  3. *
  4. * @param codePoint
  5. * the code point
  6. * @return the result string
  7. */
  8. public static String fromCodePoint(int codePoint) {
  9. if (Character.isBmpCodePoint(codePoint)) {
  10. return String.valueOf((char) codePoint);
  11. }
  12. return String.valueOf(Character.toChars(codePoint));
  13. }

代码示例来源:origin: anba/es6draft

  1. private void appendCodeUnit(int codeUnit) {
  2. assert Character.isBmpCodePoint(codeUnit);
  3. out.append("\\u").append(toHexDigit(codeUnit >> 12)).append(toHexDigit(codeUnit >> 8))
  4. .append(toHexDigit(codeUnit >> 4)).append(toHexDigit(codeUnit >> 0));
  5. }

代码示例来源:origin: ESAPI/esapi-java-legacy

  1. /**
  2. * WARNING!! {@code Character} based Codecs will silently transform code points that are not
  3. * legal UTF code points into garbage data as they will cast them to {@code char}s.
  4. * </br></br>
  5. * If you are implementing an {@code Integer} based codec, these will be silently discarded
  6. * based on the return from {@code Character.isValidCodePoint( int )}. This is the preferred
  7. * behavior moving forward.
  8. *
  9. *
  10. * {@inheritDoc}
  11. */
  12. @Override
  13. public String encode(char[] immune, String input) {
  14. StringBuilder sb = new StringBuilder();
  15. for(int offset = 0; offset < input.length(); ){
  16. final int point = input.codePointAt(offset);
  17. if(Character.isBmpCodePoint(point)){
  18. //We can then safely cast this to char and maintain legacy behavior.
  19. sb.append(encodeCharacter(immune, new Character((char) point)));
  20. }else{
  21. sb.append(encodeCharacter(immune, point));
  22. }
  23. offset += Character.charCount(point);
  24. }
  25. return sb.toString();
  26. }

代码示例来源:origin: org.eclipse.rdf4j/rdf4j-client

  1. /**
  2. * Appends the characters from codepoint into the string builder. This is the same as Character#toChars
  3. * but prevents the additional char array garbage for BMP codepoints.
  4. *
  5. * @param dst
  6. * the destination in which to append the characters
  7. * @param codePoint
  8. * the codepoint to be appended
  9. */
  10. private static void appendCodepoint(StringBuilder dst, int codePoint) {
  11. if (Character.isBmpCodePoint(codePoint)) {
  12. dst.append((char)codePoint);
  13. }
  14. else if (Character.isValidCodePoint(codePoint)) {
  15. dst.append(Character.highSurrogate(codePoint));
  16. dst.append(Character.lowSurrogate(codePoint));
  17. }
  18. else {
  19. throw new IllegalArgumentException("Invalid codepoint " + codePoint);
  20. }
  21. }
  22. }

代码示例来源:origin: anba/es6draft

  1. @Override
  2. public int codeToMbc(int code, byte[] bytes, int p) {
  3. if (Character.isBmpCodePoint(code)) {
  4. bytes[p + 0] = (byte) (code >>> 8);
  5. bytes[p + 1] = (byte) (code >>> 0);
  6. return 2;
  7. }
  8. char high = Character.highSurrogate(code);
  9. char low = Character.lowSurrogate(code);
  10. bytes[p + 0] = (byte) (high >>> 8);
  11. bytes[p + 1] = (byte) (high >>> 0);
  12. bytes[p + 2] = (byte) (low >>> 8);
  13. bytes[p + 3] = (byte) (low >>> 0);
  14. return 4;
  15. }

代码示例来源:origin: eclipse/rdf4j

  1. /**
  2. * Appends the characters from codepoint into the string builder. This is the same as Character#toChars
  3. * but prevents the additional char array garbage for BMP codepoints.
  4. *
  5. * @param dst
  6. * the destination in which to append the characters
  7. * @param codePoint
  8. * the codepoint to be appended
  9. */
  10. private static void appendCodepoint(StringBuilder dst, int codePoint) {
  11. if (Character.isBmpCodePoint(codePoint)) {
  12. dst.append((char)codePoint);
  13. }
  14. else if (Character.isValidCodePoint(codePoint)) {
  15. dst.append(Character.highSurrogate(codePoint));
  16. dst.append(Character.lowSurrogate(codePoint));
  17. }
  18. else {
  19. throw new IllegalArgumentException("Invalid codepoint " + codePoint);
  20. }
  21. }
  22. }

代码示例来源:origin: org.apache.sis.core/sis-utility

  1. /**
  2. * Appends the given code point to the underlying {@link #out} stream or buffer.
  3. *
  4. * @param c the code point to append.
  5. * @throws IOException if an error occurred while appending the code point.
  6. */
  7. final void appendCodePoint(final int c) throws IOException {
  8. if (Character.isBmpCodePoint(c)) {
  9. out.append((char) c);
  10. } else if (Character.isSupplementaryCodePoint(c)) {
  11. out.append(Character.highSurrogate(c))
  12. .append(Character. lowSurrogate(c));
  13. } else {
  14. throw new CharConversionException();
  15. }
  16. }

代码示例来源:origin: apache/sis

  1. /**
  2. * Appends the given code point to the underlying {@link #out} stream or buffer.
  3. *
  4. * @param c the code point to append.
  5. * @throws IOException if an error occurred while appending the code point.
  6. */
  7. final void appendCodePoint(final int c) throws IOException {
  8. if (Character.isBmpCodePoint(c)) {
  9. out.append((char) c);
  10. } else if (Character.isSupplementaryCodePoint(c)) {
  11. out.append(Character.highSurrogate(c))
  12. .append(Character. lowSurrogate(c));
  13. } else {
  14. throw new CharConversionException();
  15. }
  16. }

代码示例来源:origin: anba/es6draft

  1. /**
  2. * Appends the code point to the buffer.
  3. *
  4. * @param c
  5. * the code point
  6. */
  7. public void appendCodePoint(int c) {
  8. if (Character.isBmpCodePoint(c)) {
  9. append(c);
  10. } else {
  11. append(Character.highSurrogate(c));
  12. append(Character.lowSurrogate(c));
  13. }
  14. }

代码示例来源:origin: org.opencypher/grammar

  1. /**
  2. * Appends the string representation of the {@code codePoint} argument to this sequence.
  3. *
  4. * @param codePoint a Unicode code point
  5. * @return this {@code Output} instance to allow invocation chaining.
  6. * @throws IllegalArgumentException if the specified {@code codePoint} isn't a valid Unicode code point.
  7. * @see java.lang.StringBuilder#appendCodePoint(int) the corresponding method of <code>StringBuilder</code>
  8. */
  9. default Output appendCodePoint( int codePoint )
  10. {
  11. if ( isBmpCodePoint( codePoint ) )
  12. {
  13. append( (char) codePoint );
  14. }
  15. else if ( isValidCodePoint( codePoint ) )
  16. {
  17. append( highSurrogate( codePoint ) );
  18. append( lowSurrogate( codePoint ) );
  19. }
  20. else
  21. {
  22. throw new IllegalArgumentException();
  23. }
  24. return this;
  25. }

代码示例来源:origin: org.jruby/jruby-complete

  1. private char multibyteCharAt(Encoding enc, int beg, int length) {
  2. int p;
  3. int s = value.getBegin();
  4. int end = s + length;
  5. byte[] bytes = value.getUnsafeBytes();
  6. if (beg > 0 && beg > StringSupport.strLengthFromRubyString(this, enc)) {
  7. throw new StringIndexOutOfBoundsException(beg);
  8. }
  9. if (isCodeRangeValid() && enc.isUTF8()) {
  10. p = StringSupport.utf8Nth(bytes, s, end, beg);
  11. } else if (enc.isFixedWidth()) {
  12. int w = enc.maxLength();
  13. p = s + beg * w;
  14. if (p > end || w > end - p) {
  15. throw new StringIndexOutOfBoundsException(beg);
  16. }
  17. } else if ((p = StringSupport.nth(enc, bytes, s, end, beg)) == end) {
  18. throw new StringIndexOutOfBoundsException(beg);
  19. }
  20. int codepoint = enc.mbcToCode(bytes, p, end);
  21. if (Character.isBmpCodePoint(codepoint)) {
  22. return (char) codepoint;
  23. }
  24. // we can only return high surrogate here
  25. return Character.highSurrogate(codepoint);
  26. }

相关文章

Character类方法