本文整理汇总了Java中com.ibm.icu.lang.UCharacter.DIRECTIONALITY_OTHER_NEUTRALS属性的典型用法代码示例。如果您正苦于以下问题:Java UCharacter.DIRECTIONALITY_OTHER_NEUTRALS属性的具体用法?Java UCharacter.DIRECTIONALITY_OTHER_NEUTRALS怎么用?Java UCharacter.DIRECTIONALITY_OTHER_NEUTRALS使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.ibm.icu.lang.UCharacter
的用法示例。
在下文中一共展示了UCharacter.DIRECTIONALITY_OTHER_NEUTRALS属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: skipTagBackward
/**
* Advances charIndex backward through an HTML tag (after the closing > has already been
* read) and returns an appropriate dirtype for the tag. If there is no matching <, does not
* change charIndex and returns UCharacter.DIRECTIONALITY_OTHER_NEUTRALS (for the > that
* hadn't been part of a tag after all). Nevertheless, the running time for calling
* skipTagBackward() in a loop remains linear in the size of the text, even for a text like
* ">>>>", because skipTagBackward() also stops looking for a matching < when it
* encounters another >.
*/
private byte skipTagBackward() {
int initialCharIndex = charIndex;
while (charIndex > 0) {
lastChar = text.charAt(--charIndex);
if (lastChar == '<') {
// The start of the tag. See note in skipTagForward() regarding the dirtype we return.
// Note, however, that the "poor man's approach" described there for handling the dir
// attribute wouldn't work here, since here we see the closing tag first - and do not
// have any indication if its matching opening tag carries the dir attribute.
return UCharacter.DIRECTIONALITY_BOUNDARY_NEUTRAL;
}
if (lastChar == '>') {
break;
}
if (lastChar == '"' || lastChar == '\'') {
// Skip over a quoted attribute value inside the tag.
char quote = lastChar;
while (charIndex > 0 && (lastChar = text.charAt(--charIndex)) != quote) {}
}
}
// The original '>' wasn't the end of a tag after all.
charIndex = initialCharIndex;
lastChar = '>';
return UCharacter.DIRECTIONALITY_OTHER_NEUTRALS;
}
示例2: skipEntityBackward
/**
* Advances charIndex backward through an HTML character entity tag (after the closing ; has
* already been read) and returns UCharacter.DIRECTIONALITY_WHITESPACE. It would be best to
* figure out the actual character and return its dirtype, but this is good enough. If there is
* no matching &, does not change charIndex and returns
* UCharacter.DIRECTIONALITY_OTHER_NEUTRALS (for the ';' that did not start an entity after
* all). Nevertheless, the running time for calling skipEntityBackward() in a loop remains
* linear in the size of the text, even for a text like ";;;;;;;", because skipTagBackward()
* also stops looking for a matching & when it encounters another ;.
*/
private byte skipEntityBackward() {
int initialCharIndex = charIndex;
while (charIndex > 0) {
lastChar = text.charAt(--charIndex);
if (lastChar == '&') {
return UCharacter.DIRECTIONALITY_WHITESPACE;
}
if (lastChar == ';') {
break;
}
}
charIndex = initialCharIndex;
lastChar = ';';
return UCharacter.DIRECTIONALITY_OTHER_NEUTRALS;
}
示例3: skipTagForward
/**
* Advances charIndex forward through an HTML tag (after the opening < has already been read)
* and returns an appropriate dirtype for the tag. If there is no matching >, does not change
* charIndex and returns UCharacter.DIRECTIONALITY_OTHER_NEUTRALS (for the < that hadn't been
* part of a tag after all).
*/
private byte skipTagForward() {
int initialCharIndex = charIndex;
while (charIndex < length) {
lastChar = text.charAt(charIndex++);
if (lastChar == '>') {
// The end of the tag.
// We return BN because the tags we really expect to encounter - and know how to handle
// best - are inline ones like <span>, <b>, <i>, <a>, etc. These do not connote a word
// break (as would WS) or punctuation (as would ON), but really are most similar to
// control codes. Ideally, we should check the actual tag and return B for <br> and the
// block element tags, but perfecting handling of multi-paragraph input isn't very
// important since estimating one directionality over several paragraphs is futile anyway:
// each one should be allowed its own. More importantly, we should check for the dir
// attribute and return an appropriate embedding, override, or isolate initiator bidi
// class, and its closing dirtype for the closing tag, but finding the closing tag is
// not so easy. A poor man's approach that should be good enough without needing a stack
// could ignore the dir attribute on elements nested in an element with a dir attribute,
// and find its closing tag by counting the nesting only of its type. Still, this wouldn't
// work in skipTagBackward() - see note there.
// TODO(user): Consider checking the tag and returning BN, B, or one of the explicit
// directional formatting dirtypes, as appropriate.
return UCharacter.DIRECTIONALITY_BOUNDARY_NEUTRAL;
}
if (lastChar == '"' || lastChar == '\'') {
// Skip over a quoted attribute value inside the tag.
char quote = lastChar;
while (charIndex < length && (lastChar = text.charAt(charIndex++)) != quote) {}
}
}
// The original '<' wasn't the start of a tag after all.
charIndex = initialCharIndex;
lastChar = '<';
return UCharacter.DIRECTIONALITY_OTHER_NEUTRALS;
}