⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 propertystring.java

📁 FuncPlotter is a combined Java application and applet for displaying two-dimensional plots of explic
💻 JAVA
字号:
/*====================================================================*\PropertyString.javaProperty string class.------------------------------------------------------------------------This file is part of FuncPlotter, a combined Java application and appletfor plotting explicit functions in one variable.Copyright 2005-2007 Andy Morgan-Richards.FuncPlotter is free software: you can redistribute it and/or modify itunder the terms of the GNU General Public License as published by theFree Software Foundation, either version 3 of the License, or (at youroption) any later version.This program is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public License alongwith this program.  If not, see <http://www.gnu.org/licenses/>.\*====================================================================*/// PACKAGEpackage util;//----------------------------------------------------------------------// IMPORTSimport java.io.File;//----------------------------------------------------------------------// PROPERTY STRING CLASSpublic class PropertyString{//////////////////////////////////////////////////////////////////////////  Constants////////////////////////////////////////////////////////////////////////    public static final     String  KEY_PREFIX  = "${";    public static final     String  KEY_SUFFIX  = "}";    public static final     String  USER_HOME_PREFIX    = "~";    private static final    int KEY_PREFIX_LENGTH   = KEY_PREFIX.length( );    private static final    int KEY_SUFFIX_LENGTH   = KEY_SUFFIX.length( );    private static final    String  ENV_PREFIX_KEY  = "app.envPrefix";    private static final    String  DEFAULT_ENV_PREFIX  = "env.";//////////////////////////////////////////////////////////////////////////  Constructors////////////////////////////////////////////////////////////////////////    private PropertyString( )    {    }    //------------------------------------------------------------------//////////////////////////////////////////////////////////////////////////  Class methods////////////////////////////////////////////////////////////////////////    public static String parse( String str )    {        if ( str == null )            return null;        if ( envPrefix == null )        {            envPrefix = DEFAULT_ENV_PREFIX;            try            {                String value = System.getProperty( ENV_PREFIX_KEY );                if ( value != null )                    envPrefix = value + ".";            }            catch ( SecurityException e )            {                // ignore            }        }        StringBuilder buffer = new StringBuilder( str );        int index = 0;        while ( index < buffer.length( ) )        {            index = buffer.indexOf( KEY_PREFIX, index );            if ( index < 0 )                break;            index += KEY_PREFIX_LENGTH;            int startIndex = index;            index = buffer.indexOf( KEY_SUFFIX, index );            if ( index < 0 )                index = startIndex;            else            {                String propertyValue = new String( );                if ( index > startIndex )                {                    boolean env = false;                    String key = buffer.substring( startIndex, index );                    if ( key.startsWith( envPrefix ) )                    {                        key = key.substring( envPrefix.length( ) );                        env = true;                    }                    try                    {                        String value = env ? System.getenv( key ) : System.getProperty( key );                        if ( value != null )                            propertyValue = value;                    }                    catch ( SecurityException e )                    {                        // ignore                    }                }                buffer.replace( startIndex - KEY_PREFIX_LENGTH, index + KEY_SUFFIX_LENGTH, propertyValue );                index = startIndex - KEY_PREFIX_LENGTH + propertyValue.length( );            }        }        return buffer.toString( );    }    //------------------------------------------------------------------    public static String parsePathname( String str )    {        if ( str.startsWith( USER_HOME_PREFIX ) )        {            int prefixLength = USER_HOME_PREFIX.length( );            if ( (str.length( ) == prefixLength) || (str.charAt( prefixLength ) == File.separatorChar) ||                 (str.charAt( prefixLength ) == '/') )            try            {                String pathname = System.getProperty( "user.home" );                if ( pathname != null )                    str = pathname + str.substring( prefixLength );            }            catch ( SecurityException e )            {                // ignore            }        }        return parse( str );    }    //------------------------------------------------------------------//////////////////////////////////////////////////////////////////////////  Class variables////////////////////////////////////////////////////////////////////////    private static  String  envPrefix;}//----------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -