Search in sources :

Example 16 with StringCharacterIterator

use of java.text.StringCharacterIterator in project jena by apache.

the class N3JenaWriterCommon method checkPrefixPart.

/* http://www.w3.org/TeamSubmission/turtle/#sec-grammar-grammar
     * [27]    qname           ::=     prefixName? ':' name?
     * [30]    nameStartChar   ::=     [A-Z] | "_" | [a-z] | [#x00C0-#x00D6] | [#x00D8-#x00F6] | [#x00F8-#x02FF] | [#x0370-#x037D] | [#x037F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
     * [31]    nameChar        ::=     nameStartChar | '-' | [0-9] | #x00B7 | [#x0300-#x036F] | [#x203F-#x2040]
     * [32]    name            ::=     nameStartChar nameChar*
     * [33]    prefixName      ::=     ( nameStartChar - '_' ) nameChar*
     */
protected static boolean checkPrefixPart(String s) {
    if (s.length() == 0)
        return true;
    CharacterIterator cIter = new StringCharacterIterator(s);
    char ch = cIter.first();
    if (!checkNameStartChar(ch))
        return false;
    if (// Can't start with _ (bnodes labels handled separately) 
    ch == '_')
        return false;
    return checkNameTail(cIter);
}
Also used : StringCharacterIterator(java.text.StringCharacterIterator) CharacterIterator(java.text.CharacterIterator) StringCharacterIterator(java.text.StringCharacterIterator)

Example 17 with StringCharacterIterator

use of java.text.StringCharacterIterator in project jena by apache.

the class RegexUtils method noMetaChars.

/** check for any regular expression metacharacters between the index point (inclusive,exclusive) */
public static boolean noMetaChars(String string, int fromIndex, int endIndex) {
    StringCharacterIterator iter = new StringCharacterIterator(string, fromIndex, endIndex, fromIndex);
    char ch;
    while ((ch = iter.next()) != StringCharacterIterator.DONE) {
        for (char mc : metaChars) {
            if (mc == ch)
                return false;
        }
    }
    return true;
}
Also used : StringCharacterIterator(java.text.StringCharacterIterator)

Example 18 with StringCharacterIterator

use of java.text.StringCharacterIterator in project ha-bridge by bwssytems.

the class TextStringFormatter method forJSON.

/**
	   Escapes characters for text appearing as data in the 
	   <a href='http://www.json.org/'>Javascript Object Notation</a>
	   (JSON) data interchange format.
	   
	   <P>The following commonly used control characters are escaped :
	   <table border='1' cellpadding='3' cellspacing='0'>
	   <tr><th> Character </th><th> Escaped As </th></tr>
	   <tr><td> " </td><td> \" </td></tr>
	   <tr><td> \ </td><td> \\ </td></tr>
	   <tr><td> / </td><td> \/ </td></tr>
	   <tr><td> back space </td><td> \b </td></tr> 
	   <tr><td> form feed </td><td> \f </td></tr>
	   <tr><td> line feed </td><td> \n </td></tr>
	   <tr><td> carriage return </td><td> \r </td></tr>
	   <tr><td> tab </td><td> \t </td></tr>
	   </table>
	   
	   <P>See <a href='http://www.ietf.org/rfc/rfc4627.txt'>RFC 4627</a> for more information.
	  */
public static String forJSON(String aText) {
    final StringBuilder result = new StringBuilder();
    StringCharacterIterator iterator = new StringCharacterIterator(aText);
    char character = iterator.current();
    while (character != StringCharacterIterator.DONE) {
        if (character == '\"') {
            result.append("\\\"");
        } else if (character == '\\') {
            result.append("\\\\");
        } else if (character == '/') {
            result.append("\\/");
        } else if (character == '\b') {
            result.append("\\b");
        } else if (character == '\f') {
            result.append("\\f");
        } else if (character == '\n') {
            result.append("\\n");
        } else if (character == '\r') {
            result.append("\\r");
        } else if (character == '\t') {
            result.append("\\t");
        } else {
            // the char is not a special one
            // add it to the result as is
            result.append(character);
        }
        character = iterator.next();
    }
    return result.toString();
}
Also used : StringCharacterIterator(java.text.StringCharacterIterator)

Example 19 with StringCharacterIterator

use of java.text.StringCharacterIterator in project ha-bridge by bwssytems.

the class TextStringFormatter method forHTML.

/**
    Escape characters for text appearing in HTML markup.
    
    <P>This method exists as a defence against Cross Site Scripting (XSS) hacks.
    The idea is to neutralize control characters commonly used by scripts, such that
    they will not be executed by the browser. This is done by replacing the control
    characters with their escaped equivalents.  
    See {@link hirondelle.web4j.security.SafeText} as well.
    
    <P>The following characters are replaced with corresponding 
    HTML character entities :
    <table border='1' cellpadding='3' cellspacing='0'>
    <tr><th> Character </th><th>Replacement</th></tr>
    <tr><td> < </td><td> &lt; </td></tr>
    <tr><td> > </td><td> &gt; </td></tr>
    <tr><td> & </td><td> &amp; </td></tr>
    <tr><td> " </td><td> &quot;</td></tr>
    <tr><td> \t </td><td> &#009;</td></tr>
    <tr><td> ! </td><td> &#033;</td></tr>
    <tr><td> # </td><td> &#035;</td></tr>
    <tr><td> $ </td><td> &#036;</td></tr>
    <tr><td> % </td><td> &#037;</td></tr>
    <tr><td> ' </td><td> &#039;</td></tr>
    <tr><td> ( </td><td> &#040;</td></tr> 
    <tr><td> ) </td><td> &#041;</td></tr>
    <tr><td> * </td><td> &#042;</td></tr>
    <tr><td> + </td><td> &#043; </td></tr>
    <tr><td> , </td><td> &#044; </td></tr>
    <tr><td> - </td><td> &#045; </td></tr>
    <tr><td> . </td><td> &#046; </td></tr>
    <tr><td> / </td><td> &#047; </td></tr>
    <tr><td> : </td><td> &#058;</td></tr>
    <tr><td> ; </td><td> &#059;</td></tr>
    <tr><td> = </td><td> &#061;</td></tr>
    <tr><td> ? </td><td> &#063;</td></tr>
    <tr><td> @ </td><td> &#064;</td></tr>
    <tr><td> [ </td><td> &#091;</td></tr>
    <tr><td> \ </td><td> &#092;</td></tr>
    <tr><td> ] </td><td> &#093;</td></tr>
    <tr><td> ^ </td><td> &#094;</td></tr>
    <tr><td> _ </td><td> &#095;</td></tr>
    <tr><td> ` </td><td> &#096;</td></tr>
    <tr><td> { </td><td> &#123;</td></tr>
    <tr><td> | </td><td> &#124;</td></tr>
    <tr><td> } </td><td> &#125;</td></tr>
    <tr><td> ~ </td><td> &#126;</td></tr>
    </table>
    
    <P>Note that JSTL's {@code <c:out>} escapes <em>only the first 
    five</em> of the above characters.
   */
public static String forHTML(String aText) {
    final StringBuilder result = new StringBuilder();
    final StringCharacterIterator iterator = new StringCharacterIterator(aText);
    char character = iterator.current();
    while (character != CharacterIterator.DONE) {
        if (character == '<') {
            result.append("&lt;");
        } else if (character == '>') {
            result.append("&gt;");
        } else if (character == '&') {
            result.append("&amp;");
        } else if (character == '\"') {
            result.append("&quot;");
        } else if (character == '\t') {
            addCharEntity(9, result);
        } else if (character == '!') {
            addCharEntity(33, result);
        } else if (character == '#') {
            addCharEntity(35, result);
        } else if (character == '$') {
            addCharEntity(36, result);
        } else if (character == '%') {
            addCharEntity(37, result);
        } else if (character == '\'') {
            addCharEntity(39, result);
        } else if (character == '(') {
            addCharEntity(40, result);
        } else if (character == ')') {
            addCharEntity(41, result);
        } else if (character == '*') {
            addCharEntity(42, result);
        } else if (character == '+') {
            addCharEntity(43, result);
        } else if (character == ',') {
            addCharEntity(44, result);
        } else if (character == '-') {
            addCharEntity(45, result);
        } else if (character == '.') {
            addCharEntity(46, result);
        } else if (character == '/') {
            addCharEntity(47, result);
        } else if (character == ':') {
            addCharEntity(58, result);
        } else if (character == ';') {
            addCharEntity(59, result);
        } else if (character == '=') {
            addCharEntity(61, result);
        } else if (character == '?') {
            addCharEntity(63, result);
        } else if (character == '@') {
            addCharEntity(64, result);
        } else if (character == '[') {
            addCharEntity(91, result);
        } else if (character == '\\') {
            addCharEntity(92, result);
        } else if (character == ']') {
            addCharEntity(93, result);
        } else if (character == '^') {
            addCharEntity(94, result);
        } else if (character == '_') {
            addCharEntity(95, result);
        } else if (character == '`') {
            addCharEntity(96, result);
        } else if (character == '{') {
            addCharEntity(123, result);
        } else if (character == '|') {
            addCharEntity(124, result);
        } else if (character == '}') {
            addCharEntity(125, result);
        } else if (character == '~') {
            addCharEntity(126, result);
        } else {
            // the char is not a special one
            // add it to the result as is
            result.append(character);
        }
        character = iterator.next();
    }
    return result.toString();
}
Also used : StringCharacterIterator(java.text.StringCharacterIterator)

Example 20 with StringCharacterIterator

use of java.text.StringCharacterIterator in project rabbitmq-java-client by rabbitmq.

the class JSONReader method read.

public Object read(String string) {
    it = new StringCharacterIterator(string);
    c = it.first();
    return read();
}
Also used : StringCharacterIterator(java.text.StringCharacterIterator)

Aggregations

StringCharacterIterator (java.text.StringCharacterIterator)41 CharacterIterator (java.text.CharacterIterator)20 Nullable (org.jetbrains.annotations.Nullable)3 ClsFormatException (com.intellij.util.cls.ClsFormatException)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Logger (com.intellij.openapi.diagnostic.Logger)1 Pair (com.intellij.openapi.util.Pair)1 Pair.pair (com.intellij.openapi.util.Pair.pair)1 StringUtil (com.intellij.openapi.util.text.StringUtil)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 LanguageLevel (com.intellij.pom.java.LanguageLevel)1 CommonClassNames (com.intellij.psi.CommonClassNames)1 PsiNameHelper (com.intellij.psi.PsiNameHelper)1 ModifierFlags (com.intellij.psi.impl.cache.ModifierFlags)1 TypeInfo (com.intellij.psi.impl.cache.TypeInfo)1 com.intellij.psi.impl.java.stubs (com.intellij.psi.impl.java.stubs)1 com.intellij.psi.impl.java.stubs.impl (com.intellij.psi.impl.java.stubs.impl)1 PsiFileStub (com.intellij.psi.stubs.PsiFileStub)1 StubElement (com.intellij.psi.stubs.StubElement)1