Search in sources :

Example 46 with StreamTokenizer

use of java.io.StreamTokenizer in project robovm by robovm.

the class OldStreamTokenizerTest method test_harmonyRegressionTest2.

public void test_harmonyRegressionTest2() {
    byte[] data = new byte[] { (byte) '"', (byte) 'H', (byte) 'e', (byte) 'l', (byte) 'l', (byte) 'o', (byte) '"' };
    StreamTokenizer tokenizer = new StreamTokenizer(new ByteArrayInputStream(data));
    try {
        tokenizer.nextToken();
    } catch (Exception e) {
        e.printStackTrace();
    }
    String result = tokenizer.toString();
    Assert.assertEquals("Token[Hello], line 1", result);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) StreamTokenizer(java.io.StreamTokenizer) IOException(java.io.IOException)

Example 47 with StreamTokenizer

use of java.io.StreamTokenizer in project robovm by robovm.

the class StreamTokenizerTest method testLowerCase.

public void testLowerCase() throws Exception {
    Locale.setDefault(Locale.US);
    StreamTokenizer st = new StreamTokenizer(new StringReader("aIb aIb"));
    st.lowerCaseMode(true);
    st.nextToken();
    assertEquals("aib", st.sval);
    Locale.setDefault(new Locale("tr", "TR"));
    st.nextToken();
    assertEquals("aıb", st.sval);
}
Also used : Locale(java.util.Locale) StringReader(java.io.StringReader) StreamTokenizer(java.io.StreamTokenizer)

Example 48 with StreamTokenizer

use of java.io.StreamTokenizer in project siena by mandubian.

the class FullText method addWords.

/**
     * Add all words in the given text to the hash set.
     *
     * @param setting the fulltext settings
     * @param set the hash set
     * @param reader the reader
     */
protected static void addWords(FullTextSettings setting, HashSet<String> set, Reader reader) {
    StreamTokenizer tokenizer = new StreamTokenizer(reader);
    tokenizer.resetSyntax();
    tokenizer.wordChars(' ' + 1, 255);
    for (char ch : " \t\n\r\f+\"*%&/()=?'!,.;:-_#@|^~`{}[]".toCharArray()) {
        tokenizer.whitespaceChars(ch, ch);
    }
    try {
        while (true) {
            int token = tokenizer.nextToken();
            if (token == StreamTokenizer.TT_EOF) {
                break;
            } else if (token == StreamTokenizer.TT_WORD) {
                String word = tokenizer.sval;
                word = setting.convertWord(word);
                if (word != null) {
                    set.add(word);
                }
            }
        }
    } catch (IOException e) {
        throw DbException.convertIOException(e, "Tokenizer error");
    }
}
Also used : IOException(java.io.IOException) StreamTokenizer(java.io.StreamTokenizer)

Example 49 with StreamTokenizer

use of java.io.StreamTokenizer in project intellij-community by JetBrains.

the class InspectionTestUtil method compareDescriptions.

static boolean compareDescriptions(Element reportedProblem, Element expectedProblem) throws Exception {
    String expectedDescription = expectedProblem.getChildText("description");
    String reportedDescription = reportedProblem.getChildText("description");
    if (expectedDescription.equals(reportedDescription))
        return true;
    StreamTokenizer tokenizer = new StreamTokenizer(new CharArrayReader(expectedDescription.toCharArray()));
    tokenizer.quoteChar('\'');
    int idx = 0;
    while (tokenizer.nextToken() != StreamTokenizer.TT_EOF) {
        String word;
        if (tokenizer.sval != null) {
            word = tokenizer.sval;
        } else if (tokenizer.ttype == StreamTokenizer.TT_NUMBER) {
            word = Double.toString(tokenizer.nval);
        } else {
            continue;
        }
        idx = reportedDescription.indexOf(word, idx);
        if (idx == -1)
            return false;
        idx += word.length();
    }
    return true;
}
Also used : CharArrayReader(java.io.CharArrayReader) StreamTokenizer(java.io.StreamTokenizer)

Example 50 with StreamTokenizer

use of java.io.StreamTokenizer in project XobotOS by xamarin.

the class TypedProperties method initTokenizer.

/**
     * Instantiates a {@link java.io.StreamTokenizer} and sets its syntax tables
     * appropriately for the {@code TypedProperties} file format.
     *
     * @param r The {@code Reader} that the {@code StreamTokenizer} will read from
     * @return a newly-created and initialized {@code StreamTokenizer}
     */
static StreamTokenizer initTokenizer(Reader r) {
    StreamTokenizer st = new StreamTokenizer(r);
    // Treat everything we don't specify as "ordinary".
    st.resetSyntax();
    /* The only non-quoted-string words we'll be reading are:
         * - property names: [._$a-zA-Z0-9]
         * - type names: [a-zS]
         * - number literals: [-0-9.eExXA-Za-z]  ('x' for 0xNNN hex literals. "NaN", "Infinity")
         * - "true" or "false" (case insensitive): [a-zA-Z]
         */
    st.wordChars('0', '9');
    st.wordChars('A', 'Z');
    st.wordChars('a', 'z');
    st.wordChars('_', '_');
    st.wordChars('$', '$');
    st.wordChars('.', '.');
    st.wordChars('-', '-');
    st.wordChars('+', '+');
    // Single-character tokens
    st.ordinaryChar('=');
    // Other special characters
    st.whitespaceChars(' ', ' ');
    st.whitespaceChars('\t', '\t');
    st.whitespaceChars('\n', '\n');
    st.whitespaceChars('\r', '\r');
    st.quoteChar('"');
    // Java-style comments
    st.slashStarComments(true);
    st.slashSlashComments(true);
    return st;
}
Also used : StreamTokenizer(java.io.StreamTokenizer)

Aggregations

StreamTokenizer (java.io.StreamTokenizer)58 IOException (java.io.IOException)22 StringReader (java.io.StringReader)16 BufferedReader (java.io.BufferedReader)9 FileReader (java.io.FileReader)8 Reader (java.io.Reader)7 ArrayList (java.util.ArrayList)7 Pattern (java.util.regex.Pattern)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 InputStreamReader (java.io.InputStreamReader)4 Support_StringReader (tests.support.Support_StringReader)4 HashMap (java.util.HashMap)3 FileOutputStream (java.io.FileOutputStream)2 ParseException (java.text.ParseException)2 Locale (java.util.Locale)2 Attribute (smile.data.Attribute)2 DateAttribute (smile.data.DateAttribute)2 NominalAttribute (smile.data.NominalAttribute)2 NumericAttribute (smile.data.NumericAttribute)2 StringAttribute (smile.data.StringAttribute)2