/** * {@linkplain #decode(CharSequence) Decodes} the specified text after collapsing its {@linkplain #isWhiteSpace(char) white space}. * <p> * All leading and trailing white space is omitted, and any sections of internal white space are replaced by a single space. * <p> * The result is how the text would normally be rendered by a * <a target="_blank" href="http://www.w3.org/TR/html401/conform.html#didx-user_agent">user agent</a>, * assuming it does not contain any tags. * <p> * If the static {@link Config#ConvertNonBreakingSpaces} property is set to <code>true</code> (the default), * then all non-breaking space ({@link CharacterEntityReference#_nbsp &nbsp;}) character entity references are converted to normal spaces. * For consistency with the rendered output of most user agents these converted spaces are not treated as white space, * so they are not collapsed and not trimmed. * <p> * <a href="#Unterminated">Unterminated</a> character references are dealt with according to the rules for * text outside of attribute values in the {@linkplain Config#CurrentCompatibilityMode current compatibility mode}. * See the discussion of the <code>insideAttributeValue</code> parameter of the {@link #decode(CharSequence, boolean insideAttributeValue)} * method for a more detailed explanation of this topic. * * @param text the source text * @return the decoded text with collapsed white space. * @see FormControl#getPredefinedValues() */ public static String decodeCollapseWhiteSpace(final CharSequence text) { return decodeCollapseWhiteSpace(text,Config.ConvertNonBreakingSpaces); }
private static String getOptionLabel(final Element optionElement) { final String labelAttributeValue=optionElement.getAttributeValue("label"); if (labelAttributeValue!=null) return labelAttributeValue; return CharacterReference.decodeCollapseWhiteSpace(optionElement.getContent()); } private final class OptionElementIterator implements Iterator<Element> {
public SelectFormControl(final Element element) { super(element,element.getAttributes().get(Attribute.MULTIPLE)!=null ? FormControlType.SELECT_MULTIPLE : FormControlType.SELECT_SINGLE,false); final List<Element> optionElements=element.getAllElements(HTMLElementName.OPTION); optionElementContainers=new ElementContainer[optionElements.size()]; int x=0; for (Element optionElement : optionElements) { final ElementContainer optionElementContainer=new ElementContainer(optionElement,true); if (optionElementContainer.predefinedValue==null) // use the content of the element if it has no value attribute optionElementContainer.predefinedValue=CharacterReference.decodeCollapseWhiteSpace(optionElementContainer.element.getContent()); optionElementContainers[x++]=optionElementContainer; } } public String getPredefinedValue() {
private void appendNonPreformattedSegment(final int begin, final int end) throws IOException { assert begin<end; assert begin>=renderedIndex; final String text=CharacterReference.decodeCollapseWhiteSpace(source.subSequence(begin,end),convertNonBreakingSpaces); if (text.length()==0) { // collapsed text is zero length but original segment wasn't, meaning it consists purely of white space. if (!ignoreInitialWhiteSpace) lastCharWhiteSpace=true; return; } appendNonPreformattedText(text,Segment.isWhiteSpace(source.charAt(begin)),Segment.isWhiteSpace(source.charAt(end-1))); }
final String decodedText=CharacterReference.decodeCollapseWhiteSpace(sb,convertNonBreakingSpaces); return decodedText;