本文整理了Java中java.lang.StringBuilder.appendCodePoint()
方法的一些代码示例,展示了StringBuilder.appendCodePoint()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StringBuilder.appendCodePoint()
方法的具体详情如下:
包路径:java.lang.StringBuilder
类名称:StringBuilder
方法名:appendCodePoint
[英]Appends the encoded Unicode code point. The code point is converted to a char[] as defined by Character#toChars(int).
[中]
代码示例来源:origin: apache/ignite
/**
*
* @param codePoint Element to add.
* @return This buffer for chaining method calls.
*/
public GridStringBuilder appendCodePoint(int codePoint) {
impl.appendCodePoint(codePoint);
return this;
}
代码示例来源:origin: goldmansachs/gs-collections
public StringBuilder valueOf(StringBuilder builder, int value)
{
return builder.appendCodePoint(value);
}
});
代码示例来源:origin: goldmansachs/gs-collections
public void value(int each)
{
builder.appendCodePoint(each);
}
});
代码示例来源:origin: goldmansachs/gs-collections
public void value(int codePoint)
{
builder.appendCodePoint(codePoint);
}
});
代码示例来源: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: square/javapoet
public static String toJavaIdentifier(String suggestion) {
StringBuilder result = new StringBuilder();
for (int i = 0; i < suggestion.length(); ) {
int codePoint = suggestion.codePointAt(i);
if (i == 0
&& !Character.isJavaIdentifierStart(codePoint)
&& Character.isJavaIdentifierPart(codePoint)) {
result.append("_");
}
int validCodePoint = Character.isJavaIdentifierPart(codePoint) ? codePoint : '_';
result.appendCodePoint(validCodePoint);
i += Character.charCount(codePoint);
}
return result.toString();
}
代码示例来源:origin: apache/hive
@Override
String transform(final String value) {
final StringBuilder ret = new StringBuilder(value.length());
final int startIdx = value.length() <= charCount ? 0 : (value.length() - charCount);
for(int i = 0; i < startIdx; i++) {
ret.appendCodePoint(value.charAt(i));
}
for(int i = startIdx; i < value.length(); i++) {
ret.appendCodePoint(transformChar(value.charAt(i)));
}
return ret.toString();
}
代码示例来源:origin: apache/hive
@Override
String transform(final String value) {
final StringBuilder ret = new StringBuilder(value.length());
final int endIdx = value.length() < charCount ? value.length() : charCount;
for(int i = 0; i < endIdx; i++) {
ret.appendCodePoint(transformChar(value.charAt(i)));
}
for(int i = endIdx; i < value.length(); i++) {
ret.appendCodePoint(value.charAt(i));
}
return ret.toString();
}
代码示例来源:origin: wildfly/wildfly
private static void appendSegment(final StringBuilder b, final String segment) {
int cp;
for (int i = 0; i < segment.length(); i = segment.offsetByCodePoints(i, 1)) {
cp = segment.codePointAt(i);
if (cp == '/' || cp == '\'' || cp == '"') {
b.append('\\');
}
b.appendCodePoint(cp);
}
}
代码示例来源:origin: apache/hive
@Override
String transform(final String val) {
StringBuilder ret = new StringBuilder(val.length());
for(int i = 0; i < val.length(); i++) {
ret.appendCodePoint(transformChar(val.charAt(i)));
}
return ret.toString();
}
代码示例来源:origin: goldmansachs/gs-collections
public static CodePointAdapter from(int... codePoints)
{
StringBuilder builder = new StringBuilder();
for (int i = 0; i < codePoints.length; i++)
{
int codePoint = codePoints[i];
builder.appendCodePoint(codePoint);
}
return new CodePointAdapter(builder.toString());
}
代码示例来源:origin: goldmansachs/gs-collections
public CodePointAdapter newWith(int element)
{
StringBuilder builder = new StringBuilder(this.adapted);
builder.appendCodePoint(element);
return new CodePointAdapter(builder.toString());
}
代码示例来源:origin: neo4j/neo4j
private String nextStringRaw( int minStringLength, int maxStringLength, CodePointFactory codePointFactory )
{
int length = intBetween( minStringLength, maxStringLength );
StringBuilder sb = new StringBuilder( length );
for ( int i = 0; i < length; i++ )
{
sb.appendCodePoint( codePointFactory.generate() );
}
return sb.toString();
}
代码示例来源:origin: k9mail/k-9
private static String importStringFromIphone(String str) {
StringBuilder buff = new StringBuilder(str.length());
for (int i = 0; i < str.length(); i = str.offsetByCodePoints(i, 1)) {
int codePoint = str.codePointAt(i);
buff.appendCodePoint(importCodePointFromIphone(codePoint));
}
return buff.toString();
}
代码示例来源:origin: goldmansachs/gs-collections
public CodePointAdapter collectInt(IntToIntFunction function)
{
StringBuilder collected = new StringBuilder(this.length());
for (int i = 0; i < this.adapted.length(); )
{
int codePoint = this.adapted.codePointAt(i);
collected.appendCodePoint(function.valueOf(codePoint));
i += Character.charCount(codePoint);
}
return CodePointAdapter.adapt(collected.toString());
}
代码示例来源:origin: wildfly/wildfly
/**
* Drain all the remaining code points in this iterator to the given string builder.
*
* @param b the string builder
* @return the same string builder
*/
public StringBuilder drainTo(StringBuilder b) {
while (hasNext()) {
b.appendCodePoint(next());
}
return b;
}
代码示例来源:origin: wildfly/wildfly
/**
* Drain all the remaining code points in this iterator to the given string builder.
*
* @param b the string builder
* @return the same string builder
*/
public StringBuilder drainTo(StringBuilder b) {
while (hasNext()) {
b.appendCodePoint(next());
}
return b;
}
代码示例来源:origin: google/guava
public void testEncodedLength_validStrings2() {
HashMap<Integer, Integer> utf8Lengths = new HashMap<>();
utf8Lengths.put(0x00, 1);
utf8Lengths.put(0x7f, 1);
utf8Lengths.put(0x80, 2);
utf8Lengths.put(0x7ff, 2);
utf8Lengths.put(0x800, 3);
utf8Lengths.put(MIN_SUPPLEMENTARY_CODE_POINT - 1, 3);
utf8Lengths.put(MIN_SUPPLEMENTARY_CODE_POINT, 4);
utf8Lengths.put(MAX_CODE_POINT, 4);
Integer[] codePoints = utf8Lengths.keySet().toArray(new Integer[] {});
StringBuilder sb = new StringBuilder();
Random rnd = new Random();
for (int trial = 0; trial < 100; trial++) {
sb.setLength(0);
int utf8Length = 0;
for (int i = 0; i < 6; i++) {
Integer randomCodePoint = codePoints[rnd.nextInt(codePoints.length)];
sb.appendCodePoint(randomCodePoint);
utf8Length += utf8Lengths.get(randomCodePoint);
if (utf8Length != Utf8.encodedLength(sb)) {
StringBuilder repro = new StringBuilder();
for (int j = 0; j < sb.length(); j++) {
repro.append(" ").append((int) sb.charAt(j)); // GWT compatible
}
assertEquals(repro.toString(), utf8Length, Utf8.encodedLength(sb));
}
}
}
}
代码示例来源:origin: apache/hive
public static String createRandomSupplementaryCharString(int len) {
StringBuilder sb = new StringBuilder();
for (int idx = 0; idx < len; ++idx) {
sb.appendCodePoint(getRandomCodePoint(' '));
}
return sb.toString();
}
代码示例来源:origin: google/guava
@SuppressWarnings("deprecation")
public void testStringInputsUtf8() {
Random rng = new Random(0);
for (int z = 0; z < 100; z++) {
String str;
int[] codePoints = new int[rng.nextInt(8)];
for (int i = 0; i < codePoints.length; i++) {
do {
codePoints[i] = rng.nextInt(0x800);
} while (!Character.isValidCodePoint(codePoints[i])
|| (codePoints[i] >= Character.MIN_SURROGATE
&& codePoints[i] <= Character.MAX_SURROGATE));
}
StringBuilder builder = new StringBuilder();
for (int i = 0; i < codePoints.length; i++) {
builder.appendCodePoint(codePoints[i]);
}
str = builder.toString();
assertEquals(
murmur3_32().hashBytes(str.getBytes(Charsets.UTF_8)),
murmur3_32().hashString(str, Charsets.UTF_8));
}
}
内容来源于网络,如有侵权,请联系作者删除!