Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * 08/06/2004
 *
 * RSyntaxUtilities.java - Utility methods used by RSyntaxTextArea and its
 * views.
 * 
 * This library is distributed under a modified BSD license.  See the included
 * RSyntaxTextArea.License.txt file for details.
 */

public class Main {
    /**
     * Integer constant representing a Windows-variant OS.
     */
    public static final int OS_WINDOWS = 1;
    /**
     * Integer constant representing Mac OS X.
     */
    public static final int OS_MAC_OSX = 2;
    /**
     * Integer constant representing Linux.
     */
    public static final int OS_LINUX = 4;
    /**
     * Integer constant representing an "unknown" OS.  99.99% of the
     * time, this means some UNIX variant (AIX, SunOS, etc.).
     */
    public static final int OS_OTHER = 8;

    /**
     * Returns an integer constant representing the OS.  This can be handy for
     * special case situations such as Mac OS-X (special application
     * registration) or Windows (allow mixed case, etc.).
     *
     * @return An integer constant representing the OS.
     */
    private static final int getOSImpl() {
        int os = OS_OTHER;
        String osName = System.getProperty("os.name");
        if (osName != null) { // Should always be true.
            osName = osName.toLowerCase();
            if (osName.indexOf("windows") > -1)
                os = OS_WINDOWS;
            else if (osName.indexOf("mac os x") > -1)
                os = OS_MAC_OSX;
            else if (osName.indexOf("linux") > -1)
                os = OS_LINUX;
            else
                os = OS_OTHER;
        }
        return os;
    }

    /**
     * If the character is an upper-case US-ASCII letter, it returns the
     * lower-case version of that letter; otherwise, it just returns the
     * character.
     *
     * @param ch The character to lower-case (if it is a US-ASCII upper-case
     *        character).
     * @return The lower-case version of the character.
     */
    public static final char toLowerCase(char ch) {
        // We can logical OR with 32 because A-Z are 65-90 in the ASCII table
        // and none of them have the 6th bit (32) set, and a-z are 97-122 in
        // the ASCII table, which is 32 over from A-Z.
        // We do it this way as we'd need to do two conditions anyway (first
        // to check that ch<255 so it can index into our table, then whether
        // that table position has the upper-case mask).
        if (ch >= 'A' && ch <= 'Z')
            return (char) (ch | 0x20);
        return ch;
    }
}