use of java.text.StringCharacterIterator in project robovm by robovm.
the class CollatorTest method assertGetCollationElementIteratorCharacterIterator.
private void assertGetCollationElementIteratorCharacterIterator(Locale l, String s, Integer... offsets) {
RuleBasedCollator coll = (RuleBasedCollator) Collator.getInstance(l);
CharacterIterator it = new StringCharacterIterator(s);
assertCollationElementIterator(coll.getCollationElementIterator(it), offsets);
}
use of java.text.StringCharacterIterator in project adempiere by adempiere.
the class StringFilter method split.
/**
Need a way to parse the stream so we can do string comparisons instead
of character comparisons.
*/
private String[] split(String to_split) {
if (to_split == null || to_split.length() == 0) {
String[] array = new String[0];
return array;
}
StringBuffer sb = new StringBuffer(to_split.length() + 50);
StringCharacterIterator sci = new StringCharacterIterator(to_split);
int length = 0;
for (char c = sci.first(); c != CharacterIterator.DONE; c = sci.next()) {
if (String.valueOf(c).equals(" "))
length++;
else if (sci.getEndIndex() - 1 == sci.getIndex())
length++;
}
String[] array = new String[length];
length = 0;
String tmp = new String();
for (char c = sci.first(); c != CharacterIterator.DONE; c = sci.next()) {
if (String.valueOf(c).equals(" ")) {
array[length] = tmp;
tmp = new String();
length++;
} else if (sci.getEndIndex() - 1 == sci.getIndex()) {
tmp = tmp + String.valueOf(sci.last());
array[length] = tmp;
tmp = new String();
length++;
} else
tmp += String.valueOf(c);
}
return (array);
}
use of java.text.StringCharacterIterator in project drill by apache.
the class Text method utf8Length.
/**
* For the given string, returns the number of UTF-8 bytes required to encode the string.
*
* @param string
* text to encode
* @return number of UTF-8 bytes required to encode
*/
public static int utf8Length(String string) {
CharacterIterator iter = new StringCharacterIterator(string);
char ch = iter.first();
int size = 0;
while (ch != CharacterIterator.DONE) {
if ((ch >= 0xD800) && (ch < 0xDC00)) {
// surrogate pair?
char trail = iter.next();
if ((trail > 0xDBFF) && (trail < 0xE000)) {
// valid pair
size += 4;
} else {
// invalid pair
size += 3;
// rewind one
iter.previous();
}
} else if (ch < 0x80) {
size++;
} else if (ch < 0x800) {
size += 2;
} else {
// ch < 0x10000, that is, the largest char value
size += 3;
}
ch = iter.next();
}
return size;
}
use of java.text.StringCharacterIterator in project jena by apache.
the class N3JenaWriterCommon method checkNamePart.
protected static boolean checkNamePart(String s) {
if (s.length() == 0)
return true;
CharacterIterator cIter = new StringCharacterIterator(s);
char ch = cIter.first();
if (!checkNameStartChar(ch))
return false;
return checkNameTail(cIter);
}
use of java.text.StringCharacterIterator in project jena by apache.
the class TurtleValidate method checkValidNamePart.
protected static boolean checkValidNamePart(String s) {
if (s.length() == 0)
return true;
CharacterIterator cIter = new StringCharacterIterator(s);
char ch = cIter.first();
if (!checkNameStartChar(ch))
return false;
return checkNameTail(cIter);
}
Aggregations