Java String Quote quoteIfCeylonKeyword(String name)

Here you can find the source of quoteIfCeylonKeyword(String name)

Description

Prefixes the given name with a "\i" if it is a Ceylon keyword

License

Apache License

Declaration

public static String quoteIfCeylonKeyword(String name) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    private static String[] keywords = new String[] { "abstracts", "alias",
            "assembly", "assert", "assign", "break", "case", "catch",
            "class", "continue", "dynamic", "else", "exists", "extends",
            "finally", "for", "function", "given", "if", "import", "in",
            "interface", "is", "let", "module", "new", "nonempty",
            "object", "of", "out", "outer", "package", "return",
            "satisfies", "super", "switch", "then", "this", "throw", "try",
            "value", "void", "while" };

    /** Prefixes the given name with a "\i" if it is a Ceylon keyword */
    public static String quoteIfCeylonKeyword(String name) {
        if (isCeylonKeyword(name))
            return "\\i" + name;
        return name;
    }//from  w  ww  .ja  v a 2  s . co  m

    public static boolean isCeylonKeyword(String token) {
        for (String keyword : keywords)
            if (keyword.equals(token))
                return true;
        return false;
    }

    public static boolean isCeylonKeyword(String string, int start, int end) {
        int length = end - start;
        OUTER: for (int i = 0; i < keywords.length; i++) {
            String token = keywords[i];
            if (token.length() != length)
                continue;
            for (int c = 0; c < length; c++) {
                if (string.charAt(c + start) != token.charAt(c))
                    continue OUTER;
            }
            return true;
        }
        return false;
    }
}

Related

  1. quoteIdentifier(String identifier, boolean isPedantic)
  2. quoteIdentifier(String identifier, boolean isPedantic)
  3. quoteIdentifier(String identifier, String quoteChar)
  4. quoteIdentifier(String s)
  5. quoteIdentifier(String s)
  6. quoteIfNeeded(String id)
  7. quoteIfNeeded(String input)
  8. quoteIfNeeded(String source)
  9. quoteIfNeeded(String value)