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

How to use
codePointCount
method
in
java.lang.String

Best Java code snippets using java.lang.String.codePointCount (Showing top 20 results out of 1,323)

origin: neo4j/neo4j

@Override
public int length()
{
  return value.codePointCount( 0, value.length() );
}
origin: vavr-io/vavr

/**
 * Returns the number of Unicode code points in the specified text
 * range of this {@code CharSeq}. The text range begins at the
 * specified {@code beginIndex} and extends to the
 * {@code char} at index {@code endIndex - 1}. Thus the
 * length (in {@code char}s) of the text range is
 * {@code endIndex-beginIndex}. Unpaired surrogates within
 * the text range count as one code point each.
 *
 * @param beginIndex the index to the first {@code char} of
 *                   the text range.
 * @param endIndex   the index after the last {@code char} of
 *                   the text range.
 * @return the number of Unicode code points in the specified text
 * range
 * @throws IndexOutOfBoundsException if the
 *                                   {@code beginIndex} is negative, or {@code endIndex}
 *                                   is larger than the length of this {@code CharSeq}, or
 *                                   {@code beginIndex} is larger than {@code endIndex}.
 */
public int codePointCount(int beginIndex, int endIndex) {
  return back.codePointCount(beginIndex, endIndex);
}
origin: wildfly/wildfly

public StringBuilder drainTo(final StringBuilder b) {
  try {
    return b.append(string, idx + offs, offs + len);
  } finally {
    offset += string.codePointCount(idx + offs, offs + len);
    idx = len;
  }
}
origin: wildfly/wildfly

public StringBuilder drainTo(final StringBuilder b) {
  try {
    return b.append(string, idx + offs, offs + len);
  } finally {
    offset += string.codePointCount(idx + offs, offs + len);
    idx = len;
  }
}
origin: wildfly/wildfly

  public String drainToString() {
    try {
      return string.substring(idx + offs, offs + len);
    } finally {
      offset += string.codePointCount(idx + offs, offs + len);
      idx = len;
    }
  }
};
origin: wildfly/wildfly

  public String drainToString() {
    try {
      return string.substring(idx + offs, offs + len);
    } finally {
      offset += string.codePointCount(idx + offs, offs + len);
      idx = len;
    }
  }
}
origin: apache/hive

public int getCharacterLength() {
 return value.codePointCount(0, value.length());
}
origin: org.apache.commons/commons-lang3

final int[] result = new int[s.codePointCount(0, s.length())];
int index = 0;
for (int i = 0; i < result.length; i++) {
origin: apache/hive

@Override
public int getCharacterLength() {
 String strippedValue = getStrippedValue();
 return strippedValue.codePointCount(0, strippedValue.length());
}
origin: square/okio

public void dumpStringData(String s) throws IOException {
 System.out.println("                       " + s);
 System.out.println("        String.length: " + s.length());
 System.out.println("String.codePointCount: " + s.codePointCount(0, s.length()));
 System.out.println("            Utf8.size: " + Utf8.size(s));
 System.out.println("          UTF-8 bytes: " + ByteString.encodeUtf8(s).hex());
 System.out.println();
}
origin: apache/hive

public static String enforceMaxLength(String val, int maxLength) {
 if (val == null) {
  return null;
 }
 String value = val;
 if (maxLength > 0) {
  int valLength = val.codePointCount(0, val.length());
  if (valLength > maxLength) {
   // Truncate the excess chars to fit the character length.
   // Also make sure we take supplementary chars into account.
   value = val.substring(0, val.offsetByCodePoints(0, maxLength));
  }
 }
 return value;
}
origin: languagetool-org/languagetool

/**
 * Checks whether a given String consists only of surrogate pairs.
 * @param word to be checked
 * @since 4.2
 */
protected boolean isSurrogatePairCombination (String word) {
 if (word.length() > 1 && word.length() % 2 == 0 && word.codePointCount(0, word.length()) != word.length()) {
  // some symbols such as emojis (😂) have a string length that equals 2
  boolean isSurrogatePairCombination = true;
  for (int i = 0; i < word.length() && isSurrogatePairCombination; i += 2) {
   isSurrogatePairCombination &= Character.isSurrogatePair(word.charAt(i), word.charAt(i + 1));
  }
  return isSurrogatePairCombination;
 }
 return false;
}
origin: looly/hutool

/**
 * 编码
 * 
 * @param text 文本
 * @return 密文
 */
public String encode(String text) {
  Assert.notNull(text, "Text should not be null.");
  
  text = text.toUpperCase();
  final StringBuilder morseBuilder = new StringBuilder();
  final int len = text.codePointCount(0, text.length());
  for (int i = 0; i < len; i++) {
    int codePoint = text.codePointAt(i);
    String word = alphabets.get(codePoint);
    if (word == null) {
      word = Integer.toBinaryString(codePoint);
    }
    morseBuilder.append(word.replace('0', dit).replace('1', dah)).append(split);
  }
  return morseBuilder.toString();
}
origin: looly/hutool

/**
 * 编码
 * 
 * @param text 文本
 * @return 密文
 */
public String encode(String text) {
  Assert.notNull(text, "Text should not be null.");
  
  text = text.toUpperCase();
  final StringBuilder morseBuilder = new StringBuilder();
  final int len = text.codePointCount(0, text.length());
  for (int i = 0; i < len; i++) {
    int codePoint = text.codePointAt(i);
    String word = alphabets.get(codePoint);
    if (word == null) {
      word = Integer.toBinaryString(codePoint);
    }
    morseBuilder.append(word.replace('0', dit).replace('1', dah)).append(split);
  }
  return morseBuilder.toString();
}
origin: apache/hive

public static String getPaddedValue(String val, int maxLength) {
 if (val == null) {
  return null;
 }
 if (maxLength < 0) {
  return val;
 }
 int valLength = val.codePointCount(0, val.length());
 if (valLength > maxLength) {
  return enforceMaxLength(val, maxLength);
 }
 if (maxLength > valLength) {
  // Make sure we pad the right amount of spaces; valLength is in terms of code points,
  // while StringUtils.rpad() is based on the number of java chars.
  int padLength = val.length() + (maxLength - valLength);
  val = StringUtils.rightPad(val, padLength);
 }
 return val;
}
origin: java-json-tools/json-schema-validator

  @Override
  public void validate(final Processor<FullData, FullData> processor,
    final ProcessingReport report, final MessageBundle bundle,
    final FullData data)
    throws ProcessingException
  {
    final String value = data.getInstance().getNode().textValue();
    final int size = value.codePointCount(0, value.length());

    if (size < intValue)
      report.error(newMsg(data, bundle, "err.common.minLength.tooShort")
        .putArgument("value", value).putArgument("found", size)
        .putArgument(keyword, intValue));
  }
}
origin: java-json-tools/json-schema-validator

  @Override
  public void validate(final Processor<FullData, FullData> processor,
    final ProcessingReport report, final MessageBundle bundle,
    final FullData data)
    throws ProcessingException
  {
    final String value = data.getInstance().getNode().textValue();
    final int size = value.codePointCount(0, value.length());

    if (size > intValue)
      report.error(newMsg(data, bundle, "err.common.maxLength.tooLong")
        .putArgument("value", value).putArgument("found", size)
        .putArgument(keyword, intValue));
  }
}
origin: apache/hive

public void testStringLength() throws Exception {
 int strLen = 20;
 int[] lengths = { 15, 20, 25 };
 // Try with supplementary characters
 for (int idx1 = 0; idx1 < lengths.length; ++idx1) {
  // Create random test string
  int curLen = lengths[idx1];
  String testString = createRandomSupplementaryCharString(curLen);
  assertEquals(curLen, testString.codePointCount(0, testString.length()));
  String enforcedString = HiveBaseChar.enforceMaxLength(testString, strLen);
  if (curLen <= strLen) {
   // No truncation needed
   assertEquals(testString, enforcedString);
  } else {
   // String should have been truncated.
   assertEquals(strLen, enforcedString.codePointCount(0, enforcedString.length()));
  }
 }
 assertNull(HiveBaseChar.enforceMaxLength(null, 0));
}
origin: neo4j/neo4j

@Test
public void nextString()
{
  for ( int i = 0; i < ITERATIONS; i++ )
  {
    TextValue textValue = randomValues.nextTextValue( 10, 20 );
    String asString = textValue.stringValue();
    int length = asString.codePointCount( 0, asString.length() );
    assertThat( length, greaterThanOrEqualTo( 10 ) );
    assertThat( length, lessThanOrEqualTo( 20 ) );
  }
}
origin: apache/hive

 public void testGetPaddedValue() {
  int strLen = 20;
  int[] lengths = { 15, 20, 25 };
  for (int idx1 = 0; idx1 < lengths.length; ++idx1) {
   int curLen = lengths[idx1];
   // Random test string
   String testString = createRandomSupplementaryCharString(curLen);
   assertEquals(curLen, testString.codePointCount(0, testString.length()));
   String paddedString = HiveBaseChar.getPaddedValue(testString, strLen);
   assertEquals(strLen, paddedString.codePointCount(0, paddedString.length()));
  }

  assertEquals("abc       ", HiveBaseChar.getPaddedValue("abc", 10));
  assertEquals("abc       ", HiveBaseChar.getPaddedValue("abc ", 10));
  assertNull(HiveBaseChar.getPaddedValue(null, 0));
 }
}
java.langStringcodePointCount

Javadoc

Returns the number of Unicode code points in the specified text range of this String. The text range begins at the specified beginIndex and extends to the char at index endIndex - 1. Thus the length (in chars) of the text range is endIndex-beginIndex. Unpaired surrogates within the text range count as one code point each.

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
  • Best IntelliJ plugins
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