Guava Escaper - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Guava Escaper class.

This code example shows how to use the following methods:escape
    return ""; 
  } 
 
  @Override 
  public String html(Object value) {
    return value == null ? "" : HTML_ESCAPER.escape(value.toString());
  } 
 
  @Override 
  public String urlPathSegment(Object value) {
    return value == null ? "" : URL_PATH_SEGMENT_ESCAPER.escape(value.toString());
  } 
 
  @Override 
  public String urlParam(Object value) {
    return value == null ? "" : URL_PARAM_ESCAPER.escape(value.toString());
  } 
 
  //CHECKSTYLE:OFF 
  @SuppressWarnings("UnusedDeclaration") 
5
CodeRank
This code example shows how to use the following methods:escape
   * @param escaper the non-null escaper to test 
   * @throws IOException 
   */ 
  public static void assertBasic(Escaper escaper) throws IOException {
    // Escapers operate on characters: no characters, no escaping. 
    Assert.assertEquals("", escaper.escape(""));
    // Assert that escapers throw null pointer exceptions. 
    try { 
      escaper.escape((String) null);
      Assert.fail("exception not thrown when escaping a null string");
    } catch (NullPointerException e) {
      // pass 
    } 
  } 
 
  /** 
   * Asserts that an escaper escapes the given character into the expected 
   * string. 
   * 
   * @param escaper the non-null escaper to test 
4
CodeRank
This code example shows how to use the following methods:escape
        return this;
    } 
 
    public HtmlBuilder escapedText( final String text )
    { 
        return text( this.escaper.escape( text ) );
    } 
 
    public HtmlBuilder text( final String text )
    { 
        closeIfNeeded(); 
        this.str.append( text );
        this.addedInner = true;
        return this;
    } 
 
    @Override 
    public String toString()
    { 
        return this.str.toString();
4
CodeRank
This code example shows how to use the following methods:escape
    @ScalarFunction 
    @SqlType(StandardTypes.VARCHAR)
    public static Slice urlEncode(@SqlType(StandardTypes.VARCHAR) Slice value)
    { 
        Escaper escaper = UrlEscapers.urlFormParameterEscaper();
        return slice(escaper.escape(value.toStringUtf8()));
    } 
 
    @Description("unescape a URL-encoded string") 
    @ScalarFunction 
    @SqlType(StandardTypes.VARCHAR)
    public static Slice urlDecode(@SqlType(StandardTypes.VARCHAR) Slice value)
    { 
        try { 
            return slice(URLDecoder.decode(value.toStringUtf8(), UTF_8.name()));
        } 
        catch (UnsupportedEncodingException e) {
            throw new AssertionError(e);
        } 
        catch (IllegalArgumentException e) {
4
CodeRank
This code example shows how to use the following methods:escape
     * @return an encoded string 
     * @see ExpressionType#isRawExpand() 
     */ 
    protected final String pctEncode(final String s)
    { 
        return escaper.escape(s);
    } 
} 
 
3
CodeRank
This code example shows how to use the following methods:escape
This code example shows how to use the following methods:escape
        if (!omitNullValues || value != null) {
            s.append(' ').append(name).append('=');
            if (value != null) { 
                String stringValue = value.toString();
                if (NEEDS_QUOTING.matchesAnyOf(stringValue)) {
                    s.append('"').append(AS_QUOTED_VALUE.escape(stringValue)).append('"');
                } else { 
                    s.append(stringValue);
                } 
            } 
        } 
        return this;
    } 
 
    /** 
     * Add a key-value pair.  If the value is not null then value's string value 
     * is escaped and written in quotes. 
     * <p> 
     * A null value is handled in one of two ways: by default, a null value is 
     * equivalent to the empty string; however, if omitNullValues is specified 
4
CodeRank
See Code Examples for Guava Escaper Methods: