Tabnine Logo
String.codePointAt
Code IndexAdd Tabnine to your IDE (free)

How to use
codePointAt
method
in
java.lang.String

Best Java code snippets using java.lang.String.codePointAt (Showing top 20 results out of 5,616)

origin: stanfordnlp/CoreNLP

public static boolean langIndependentPuncCheck(String token) {
 boolean isNotWord = true;
 for (int offset = 0; offset < token.length(); ) {
   final int codepoint = token.codePointAt(offset);
   if (Character.isLetterOrDigit(codepoint)) {
    isNotWord = false;
   }
   offset += Character.charCount(codepoint);
 }
 return isNotWord;
}
origin: prestodb/presto

static int codePointIndexToCharIndex(String s, int codePointCount) {
 for (int i = 0, j = 0, length = s.length(), c; i < length; i += Character.charCount(c)) {
  if (j == codePointCount) {
   return i;
  }
  c = s.codePointAt(i);
  if ((Character.isISOControl(c) && c != '\n' && c != '\r')
    || c == Buffer.REPLACEMENT_CHARACTER) {
   return -1;
  }
  j++;
 }
 return s.length();
}
origin: neo4j/neo4j

private int ltrimIndex( String value )
{
  int start = 0, length = value.length();
  while ( start < length )
  {
    int codePoint = value.codePointAt( start );
    if ( !Character.isWhitespace( codePoint ) )
    {
      break;
    }
    start += Character.charCount( codePoint );
  }
  return start;
}
origin: redisson/redisson

private Constant(String content) {
  Arrays.fill(contains, false);
  StringBuilder sb = new StringBuilder();
  for (int i = 0; i < content.length(); i++) {
    int c = content.codePointAt(i);
    if (c < 128)
      contains[c] = true;
    else
      sb.appendCodePoint(c);
  }
  if (sb.length() > 0) {
    noASCII = true;
    this.content = sb.toString();
  }
}
origin: redisson/redisson

public static boolean isPrintable(final String data) {
  final int length = data.length();
  for (int offset = 0; offset < length; ) {
    final int codePoint = data.codePointAt(offset);
    if (!isPrintable(codePoint)) {
      return false;
    }
    offset += Character.charCount(codePoint);
  }
  return true;
}
origin: square/okhttp

/** Returns {@code s} with control characters and non-ASCII characters replaced with '?'. */
private static String toHumanReadableAscii(String s) {
 for (int i = 0, length = s.length(), c; i < length; i += Character.charCount(c)) {
  c = s.codePointAt(i);
  if (c > '\u001f' && c < '\u007f') continue;
  Buffer buffer = new Buffer();
  buffer.writeUtf8(s, 0, i);
  buffer.writeUtf8CodePoint('?');
  for (int j = i + Character.charCount(c); j < length; j += Character.charCount(c)) {
   c = s.codePointAt(j);
   buffer.writeUtf8CodePoint(c > '\u001f' && c < '\u007f' ? c : '?');
  }
  return buffer.readUtf8();
 }
 return s;
}
origin: square/retrofit

private static String canonicalizeForPath(String input, boolean alreadyEncoded) {
 int codePoint;
 for (int i = 0, limit = input.length(); i < limit; i += Character.charCount(codePoint)) {
  codePoint = input.codePointAt(i);
  if (codePoint < 0x20 || codePoint >= 0x7f
    || PATH_SEGMENT_ALWAYS_ENCODE_SET.indexOf(codePoint) != -1
    || (!alreadyEncoded && (codePoint == '/' || codePoint == '%'))) {
   // Slow path: the character at i requires encoding!
   Buffer out = new Buffer();
   out.writeUtf8(input, 0, i);
   canonicalizeForPath(out, input, i, limit, alreadyEncoded);
   return out.readUtf8();
  }
 }
 // Fast path: no characters required encoding.
 return input;
}
origin: facebook/litho

private static String getBasePropMatcherName(final MethodParamModel prop, final String suffix) {
 final String name = prop.getName();
 final int fst = Character.toUpperCase(name.codePointAt(0));
 return 'm'
   + String.copyValueOf(Character.toChars(fst))
   + name.substring(name.offsetByCodePoints(0, 1))
   + suffix;
}
origin: skylot/jadx

  public void testComplexIf(String a, int b) {
    if (d == null || (c == 0 && b != -1 && d.length() == 0)) {
      c = a.codePointAt(c);
    } else {
      if (a.hashCode() != 0xCDE) {
        c = f.compareTo(a);
      }
    }
  }
}
origin: prestodb/presto

/** Returns {@code s} with control characters and non-ASCII characters replaced with '?'. */
public static String toHumanReadableAscii(String s) {
 for (int i = 0, length = s.length(), c; i < length; i += Character.charCount(c)) {
  c = s.codePointAt(i);
  if (c > '\u001f' && c < '\u007f') continue;
  Buffer buffer = new Buffer();
  buffer.writeUtf8(s, 0, i);
  for (int j = i; j < length; j += Character.charCount(c)) {
   c = s.codePointAt(j);
   buffer.writeUtf8CodePoint(c > '\u001f' && c < '\u007f' ? c : '?');
  }
  return buffer.readUtf8();
 }
 return s;
}
origin: libgdx/libgdx

public int getWidth (String text) {
  if (text == null) throw new IllegalArgumentException("text cannot be null.");
  if (text.length() == 0) return 0;
  char[] chars = text.toCharArray();
  GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT);
  int width = 0;
  int extraX = 0;
  boolean startNewLine = false;
  for (int glyphIndex = 0, n = vector.getNumGlyphs(); glyphIndex < n; glyphIndex++) {
    int charIndex = vector.getGlyphCharIndex(glyphIndex);
    int codePoint = text.codePointAt(charIndex);
    Rectangle bounds = getGlyphBounds(vector, glyphIndex, codePoint);
    if (startNewLine && codePoint != '\n') extraX = -bounds.x;
    if (glyphIndex > 0) extraX += paddingLeft + paddingRight + paddingAdvanceX;
    width = Math.max(width, bounds.x + extraX + bounds.width);
    if (codePoint == '\n') startNewLine = true;
  }
  return width;
}
origin: libgdx/libgdx

public int getWidth (String text) {
  if (text == null) throw new IllegalArgumentException("text cannot be null.");
  if (text.length() == 0) return 0;
  char[] chars = text.toCharArray();
  GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT);
  int width = 0;
  int extraX = 0;
  boolean startNewLine = false;
  for (int glyphIndex = 0, n = vector.getNumGlyphs(); glyphIndex < n; glyphIndex++) {
    int charIndex = vector.getGlyphCharIndex(glyphIndex);
    int codePoint = text.codePointAt(charIndex);
    Rectangle bounds = getGlyphBounds(vector, glyphIndex, codePoint);
    if (startNewLine && codePoint != '\n') extraX = -bounds.x;
    if (glyphIndex > 0) extraX += paddingLeft + paddingRight + paddingAdvanceX;
    width = Math.max(width, bounds.x + extraX + bounds.width);
    if (codePoint == '\n') startNewLine = true;
  }
  return width;
}
origin: square/okhttp

static void percentDecode(Buffer out, String encoded, int pos, int limit, boolean plusIsSpace) {
 int codePoint;
 for (int i = pos; i < limit; i += Character.charCount(codePoint)) {
  codePoint = encoded.codePointAt(i);
  if (codePoint == '%' && i + 2 < limit) {
   int d1 = decodeHexDigit(encoded.charAt(i + 1));
   int d2 = decodeHexDigit(encoded.charAt(i + 2));
   if (d1 != -1 && d2 != -1) {
    out.writeByte((d1 << 4) + d2);
    i += 2;
    continue;
   }
  } else if (codePoint == '+' && plusIsSpace) {
   out.writeByte(' ');
   continue;
  }
  out.writeUtf8CodePoint(codePoint);
 }
}
origin: libgdx/libgdx

public int getHeight (String text) {
  if (text == null) throw new IllegalArgumentException("text cannot be null.");
  if (text.length() == 0) return 0;
  char[] chars = text.toCharArray();
  GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT);
  int lines = 0, height = 0;
  for (int i = 0, n = vector.getNumGlyphs(); i < n; i++) {
    int charIndex = vector.getGlyphCharIndex(i);
    int codePoint = text.codePointAt(charIndex);
    if (codePoint == ' ') continue;
    Rectangle bounds = getGlyphBounds(vector, i, codePoint);
    height = Math.max(height, ascent + bounds.y + bounds.height);
    if (codePoint == '\n') {
      lines++;
      height = 0;
    }
  }
  return lines * getLineHeight() + height;
}
origin: libgdx/libgdx

public int getHeight (String text) {
  if (text == null) throw new IllegalArgumentException("text cannot be null.");
  if (text.length() == 0) return 0;
  char[] chars = text.toCharArray();
  GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT);
  int lines = 0, height = 0;
  for (int i = 0, n = vector.getNumGlyphs(); i < n; i++) {
    int charIndex = vector.getGlyphCharIndex(i);
    int codePoint = text.codePointAt(charIndex);
    if (codePoint == ' ') continue;
    Rectangle bounds = getGlyphBounds(vector, i, codePoint);
    height = Math.max(height, ascent + bounds.y + bounds.height);
    if (codePoint == '\n') {
      lines++;
      height = 0;
    }
  }
  return lines * getLineHeight() + height;
}
origin: libgdx/libgdx

/** Queues the glyphs in the specified text to be loaded. Note that the glyphs are not actually loaded until
 * {@link #loadGlyphs()} is called. */
public void addGlyphs (String text) {
  if (text == null) throw new IllegalArgumentException("text cannot be null.");
  char[] chars = text.toCharArray();
  GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT);
  for (int i = 0, n = vector.getNumGlyphs(); i < n; i++) {
    int codePoint = text.codePointAt(vector.getGlyphCharIndex(i));
    Rectangle bounds = getGlyphBounds(vector, i, codePoint);
    getGlyph(vector.getGlyphCode(i), codePoint, bounds, vector, i);
  }
}
origin: libgdx/libgdx

/** Queues the glyphs in the specified text to be loaded. Note that the glyphs are not actually loaded until
 * {@link #loadGlyphs()} is called. */
public void addGlyphs (String text) {
  if (text == null) throw new IllegalArgumentException("text cannot be null.");
  char[] chars = text.toCharArray();
  GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT);
  for (int i = 0, n = vector.getNumGlyphs(); i < n; i++) {
    int codePoint = text.codePointAt(vector.getGlyphCharIndex(i));
    Rectangle bounds = getGlyphBounds(vector, i, codePoint);
    getGlyph(vector.getGlyphCode(i), codePoint, bounds, vector, i);
  }
}
origin: square/retrofit

private static void canonicalizeForPath(Buffer out, String input, int pos, int limit,
  boolean alreadyEncoded) {
 Buffer utf8Buffer = null; // Lazily allocated.
 int codePoint;
 for (int i = pos; i < limit; i += Character.charCount(codePoint)) {
  codePoint = input.codePointAt(i);
  if (alreadyEncoded
    && (codePoint == '\t' || codePoint == '\n' || codePoint == '\f' || codePoint == '\r')) {
   // Skip this character.
  } else if (codePoint < 0x20 || codePoint >= 0x7f
    || PATH_SEGMENT_ALWAYS_ENCODE_SET.indexOf(codePoint) != -1
    || (!alreadyEncoded && (codePoint == '/' || codePoint == '%'))) {
   // Percent encode this character.
   if (utf8Buffer == null) {
    utf8Buffer = new Buffer();
   }
   utf8Buffer.writeUtf8CodePoint(codePoint);
   while (!utf8Buffer.exhausted()) {
    int b = utf8Buffer.readByte() & 0xff;
    out.writeByte('%');
    out.writeByte(HEX_DIGITS[(b >> 4) & 0xf]);
    out.writeByte(HEX_DIGITS[b & 0xf]);
   }
  } else {
   // This character doesn't need encoding. Just copy it over.
   out.writeUtf8CodePoint(codePoint);
  }
 }
}
origin: neo4j/neo4j

@Test
void shouldHandleSingleByteCodePoints()
{
  // Given
  UTF8StringValueBuilder builder = new UTF8StringValueBuilder();
  int codepoint = "$".codePointAt( 0 );
  // When
  builder.addCodePoint( codepoint );
  builder.addCodePoint( codepoint );
  builder.addCodePoint( codepoint );
  // Then
  TextValue textValue = builder.build();
  assertThat( textValue.stringValue(), equalTo("$$$"));
}
origin: neo4j/neo4j

@Test
void shouldHandleTwoByteCodePoints()
{
  // Given
  UTF8StringValueBuilder builder = new UTF8StringValueBuilder();
  int codepoint = "¢".codePointAt( 0 );
  // When
  builder.addCodePoint( codepoint );
  builder.addCodePoint( codepoint );
  builder.addCodePoint( codepoint );
  // Then
  TextValue textValue = builder.build();
  assertThat( textValue.stringValue(), equalTo("¢¢¢"));
}
java.langStringcodePointAt

Javadoc

Returns the character (Unicode code point) at the specified index. The index refers to char values (Unicode code units) and ranges from 0 to #length() - 1.

If the char value specified at the given index is in the high-surrogate range, the following index is less than the length of this String, and the char value at the following index is in the low-surrogate range, then the supplementary code point corresponding to this surrogate pair is returned. Otherwise, the char value at the given index is returned.

Popular methods of String

  • equals
  • length
    Returns the number of characters in this string.
  • substring
    Returns a string containing a subsequence of characters from this string. The returned string shares
  • startsWith
    Compares the specified string to this string, starting at the specified offset, to determine if the
  • format
    Returns a formatted string, using the supplied format and arguments, localized to the given locale.
  • split
    Splits this string using the supplied regularExpression. See Pattern#split(CharSequence,int) for an
  • trim
  • valueOf
    Creates a new string containing the specified characters in the character array. Modifying the chara
  • indexOf
  • endsWith
    Compares the specified string to this string to determine if the specified string is a suffix.
  • toLowerCase
    Converts this string to lower case, using the rules of locale.Most case mappings are unaffected by t
  • contains
    Determines if this String contains the sequence of characters in the CharSequence passed.
  • toLowerCase,
  • contains,
  • getBytes,
  • <init>,
  • equalsIgnoreCase,
  • replace,
  • isEmpty,
  • charAt,
  • hashCode,
  • lastIndexOf

Popular in Java

  • Making http requests using okhttp
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • getResourceAsStream (ClassLoader)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • Runnable (java.lang)
    Represents a command that can be executed. Often used to run code in a different Thread.
  • Socket (java.net)
    Provides a client-side TCP socket.
  • TreeSet (java.util)
    TreeSet is an implementation of SortedSet. All optional operations (adding and removing) are support
  • Modifier (javassist)
    The Modifier class provides static methods and constants to decode class and member access modifiers
  • SSLHandshakeException (javax.net.ssl)
    The exception that is thrown when a handshake could not be completed successfully.
  • Servlet (javax.servlet)
    Defines methods that all servlets must implement. A servlet is a small Java program that runs within
  • Top plugins for Android Studio
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now