java.lang.String#indexOf ( )源码实例Demo

下面列出了java.lang.String#indexOf ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: hottub   文件: Messages.java
/**
 * Returns the message text corresponding to the passed msgkey
 * string.  The message text is assumed to require the insertion
 * of a single argument, supplied by the "parm" parameter.
 * If the message text does not contain the meta characters "%1"
 * that indicate where to place the argument, the passed argument
 * is appended at the end of the message text.
 * <p>
 * If the msgkey cannot be found, its value is used as the
 * message text.
 */
public static final String msg (String msgkey, String parm) {

    if (loadNeeded)
        loadDefaultProperties ();
    String msgtext = m.getProperty (msgkey, msgkey);
    int i = msgtext.indexOf ("%1");
    if (i >= 0) {
        String ending = "";
        if ((i+2) < msgtext.length ())
            ending = msgtext.substring (i+2);
        return msgtext.substring (0, i) + parm + ending;
    } else
        msgtext += " " + parm;
    return msgtext;

}
 
源代码2 项目: TencentKona-8   文件: Messages.java
/**
 * Returns the message text corresponding to the passed msgkey
 * string.  The message text is assumed to require the insertion
 * of a single argument, supplied by the "parm" parameter.
 * If the message text does not contain the meta characters "%1"
 * that indicate where to place the argument, the passed argument
 * is appended at the end of the message text.
 * <p>
 * If the msgkey cannot be found, its value is used as the
 * message text.
 */
public static final String msg (String msgkey, String parm) {

    if (loadNeeded)
        loadDefaultProperties ();
    String msgtext = m.getProperty (msgkey, msgkey);
    int i = msgtext.indexOf ("%1");
    if (i >= 0) {
        String ending = "";
        if ((i+2) < msgtext.length ())
            ending = msgtext.substring (i+2);
        return msgtext.substring (0, i) + parm + ending;
    } else
        msgtext += " " + parm;
    return msgtext;

}
 
源代码3 项目: TencentKona-8   文件: Messages.java
/**
 * Returns the message text corresponding to the passed msgkey
 * string.  The message text is assumed to require the insertion
 * of two arguments, supplied by the "parm1" and "parm2" parameters.
 * If the message text does not contain the meta characters "%1" and
 * "%2" that indicate where to place the arguments, the passed arguments
 * are appended at the end of the message text.
 * <p>
 * If the msgkey cannot be found, its value is used as the
 * message text.
 */
public static final String msg (String msgkey, String parm1, String parm2) {

    if (loadNeeded)
        loadDefaultProperties ();
    String result = m.getProperty (msgkey, msgkey);
    String ending = "";
    int i = result.indexOf ("%1");
    if (i >= 0) {
        if ((i+2) < result.length ())
            ending = result.substring (i+2);
        result = result.substring (0, i) + parm1 + ending;
    } else
        result += " " + parm1;
    i = result.indexOf ("%2");
    if (i >= 0) {
        ending = "";
        if ((i+2) < result.length ())
            ending = result.substring (i+2);
        result = result.substring (0, i) + parm2 + ending;
    } else
        result += " " + parm2;
    return result;

}
 
源代码4 项目: jdk8u60   文件: Messages.java
/**
 * Returns the message text corresponding to the passed msgkey
 * string.  The message text is assumed to require the insertion
 * of a single argument, supplied by the "parm" parameter.
 * If the message text does not contain the meta characters "%1"
 * that indicate where to place the argument, the passed argument
 * is appended at the end of the message text.
 * <p>
 * If the msgkey cannot be found, its value is used as the
 * message text.
 */
public static final String msg (String msgkey, String parm) {

    if (loadNeeded)
        loadDefaultProperties ();
    String msgtext = m.getProperty (msgkey, msgkey);
    int i = msgtext.indexOf ("%1");
    if (i >= 0) {
        String ending = "";
        if ((i+2) < msgtext.length ())
            ending = msgtext.substring (i+2);
        return msgtext.substring (0, i) + parm + ending;
    } else
        msgtext += " " + parm;
    return msgtext;

}
 
源代码5 项目: openjdk-8-source   文件: Messages.java
private static String substituteString(String orig, int paramNum,
                 String subst){
    String result = orig;
    String paramSubst = "%"+ paramNum;
    int len = paramSubst.length();
    int index = result.indexOf (paramSubst);
    String ending = "";
    if (index >= 0) {
        if ((index+len) < result.length ())
            ending = result.substring (index+len);
        result = result.substring (0, index) + subst + ending;
    }
    else result += " " + subst;

     return result;
}
 
源代码6 项目: openjdk-8-source   文件: Messages.java
/**
 * Returns the message text corresponding to the passed msgkey
 * string.  The message text is assumed to require the insertion
 * of a single argument, supplied by the "parm" parameter.
 * If the message text does not contain the meta characters "%1"
 * that indicate where to place the argument, the passed argument
 * is appended at the end of the message text.
 * <p>
 * If the msgkey cannot be found, its value is used as the
 * message text.
 */
public static final String msg (String msgkey, String parm) {

    if (loadNeeded)
        loadDefaultProperties ();
    String msgtext = m.getProperty (msgkey, msgkey);
    int i = msgtext.indexOf ("%1");
    if (i >= 0) {
        String ending = "";
        if ((i+2) < msgtext.length ())
            ending = msgtext.substring (i+2);
        return msgtext.substring (0, i) + parm + ending;
    } else
        msgtext += " " + parm;
    return msgtext;

}
 
源代码7 项目: openjdk-8   文件: Messages.java
private static String substituteString(String orig, int paramNum,
                 String subst){
    String result = orig;
    String paramSubst = "%"+ paramNum;
    int len = paramSubst.length();
    int index = result.indexOf (paramSubst);
    String ending = "";
    if (index >= 0) {
        if ((index+len) < result.length ())
            ending = result.substring (index+len);
        result = result.substring (0, index) + subst + ending;
    }
    else result += " " + subst;

     return result;
}
 
源代码8 项目: openjdk-jdk9   文件: Messages.java
private static String substituteString(String orig, int paramNum,
                 String subst){
    String result = orig;
    String paramSubst = "%"+ paramNum;
    int len = paramSubst.length();
    int index = result.indexOf (paramSubst);
    String ending = "";
    if (index >= 0) {
        if ((index+len) < result.length ())
            ending = result.substring (index+len);
        result = result.substring (0, index) + subst + ending;
    }
    else result += " " + subst;

     return result;
}
 
源代码9 项目: openjdk-jdk8u   文件: Messages.java
private static String substituteString(String orig, int paramNum,
                 String subst){
    String result = orig;
    String paramSubst = "%"+ paramNum;
    int len = paramSubst.length();
    int index = result.indexOf (paramSubst);
    String ending = "";
    if (index >= 0) {
        if ((index+len) < result.length ())
            ending = result.substring (index+len);
        result = result.substring (0, index) + subst + ending;
    }
    else result += " " + subst;

     return result;
}
 
源代码10 项目: openjdk-8   文件: Messages.java
/**
 * Returns the message text corresponding to the passed msgkey
 * string.  The message text is assumed to require the insertion
 * of a single argument, supplied by the "parm" parameter.
 * If the message text does not contain the meta characters "%1"
 * that indicate where to place the argument, the passed argument
 * is appended at the end of the message text.
 * <p>
 * If the msgkey cannot be found, its value is used as the
 * message text.
 */
public static final String msg (String msgkey, String parm) {

    if (loadNeeded)
        loadDefaultProperties ();
    String msgtext = m.getProperty (msgkey, msgkey);
    int i = msgtext.indexOf ("%1");
    if (i >= 0) {
        String ending = "";
        if ((i+2) < msgtext.length ())
            ending = msgtext.substring (i+2);
        return msgtext.substring (0, i) + parm + ending;
    } else
        msgtext += " " + parm;
    return msgtext;

}
 
源代码11 项目: openjdk-8-source   文件: Messages.java
/**
 * Returns the message text corresponding to the passed msgkey
 * string.  The message text is assumed to require the insertion
 * of two arguments, supplied by the "parm1" and "parm2" parameters.
 * If the message text does not contain the meta characters "%1" and
 * "%2" that indicate where to place the arguments, the passed arguments
 * are appended at the end of the message text.
 * <p>
 * If the msgkey cannot be found, its value is used as the
 * message text.
 */
public static final String msg (String msgkey, String parm1, String parm2) {

    if (loadNeeded)
        loadDefaultProperties ();
    String result = m.getProperty (msgkey, msgkey);
    String ending = "";
    int i = result.indexOf ("%1");
    if (i >= 0) {
        if ((i+2) < result.length ())
            ending = result.substring (i+2);
        result = result.substring (0, i) + parm1 + ending;
    } else
        result += " " + parm1;
    i = result.indexOf ("%2");
    if (i >= 0) {
        ending = "";
        if ((i+2) < result.length ())
            ending = result.substring (i+2);
        result = result.substring (0, i) + parm2 + ending;
    } else
        result += " " + parm2;
    return result;

}
 
源代码12 项目: openjdk-jdk9   文件: Messages.java
/**
 * Returns the message text corresponding to the passed msgkey
 * string.  The message text is assumed to require the insertion
 * of a single argument, supplied by the "parm" parameter.
 * If the message text does not contain the meta characters "%1"
 * that indicate where to place the argument, the passed argument
 * is appended at the end of the message text.
 * <p>
 * If the msgkey cannot be found, its value is used as the
 * message text.
 */
public static final String msg (String msgkey, String parm) {

    if (loadNeeded)
        loadDefaultProperties ();
    String msgtext = m.getProperty (msgkey, msgkey);
    int i = msgtext.indexOf ("%1");
    if (i >= 0) {
        String ending = "";
        if ((i+2) < msgtext.length ())
            ending = msgtext.substring (i+2);
        return msgtext.substring (0, i) + parm + ending;
    } else
        msgtext += " " + parm;
    return msgtext;

}
 
源代码13 项目: hottub   文件: Messages.java
/**
 * Returns the message text corresponding to the passed msgkey
 * string.  The message text is assumed to require the insertion
 * of two arguments, supplied by the "parm1" and "parm2" parameters.
 * If the message text does not contain the meta characters "%1" and
 * "%2" that indicate where to place the arguments, the passed arguments
 * are appended at the end of the message text.
 * <p>
 * If the msgkey cannot be found, its value is used as the
 * message text.
 */
public static final String msg (String msgkey, String parm1, String parm2) {

    if (loadNeeded)
        loadDefaultProperties ();
    String result = m.getProperty (msgkey, msgkey);
    String ending = "";
    int i = result.indexOf ("%1");
    if (i >= 0) {
        if ((i+2) < result.length ())
            ending = result.substring (i+2);
        result = result.substring (0, i) + parm1 + ending;
    } else
        result += " " + parm1;
    i = result.indexOf ("%2");
    if (i >= 0) {
        ending = "";
        if ((i+2) < result.length ())
            ending = result.substring (i+2);
        result = result.substring (0, i) + parm2 + ending;
    } else
        result += " " + parm2;
    return result;

}
 
源代码14 项目: jdk8u60   文件: Messages.java
/**
 * This method was introduced to fix defect #26964.  For Java 1.0.2
 * on Win NT, the escape sequence \u0020 was not being handled
 * correctly by the Java Properties class when it was the final
 * character of a line.  Instead the trailing blank was dropped
 * and the next line was swallowed as a continuation.  To work
 * around the problem, we introduced our own metasymbol to represent
 * a trailing blank.  Hence:
 *
 * Performs substitution for any metasymbols in the message
 * templates.  So far only %B is needed.  This was introduced
 * to make it more convenient for .properties files to
 * contain message templates with leading or trailing blanks
 * (although %B may actually occur anywhere in a template).
 * Subsequently, checking for '\n' has also been added.  Now,
 * wherever '\n' occurs in a message template, it is replaced
 * with the value of System.getProperty ("line.separator").
 */
private static final void fixMessages (Properties p) {

    Enumeration keys = p.keys ();
    Enumeration elems = p.elements ();
    while (keys.hasMoreElements ()) {
        String key = (String) keys.nextElement ();
        String elem = (String) elems.nextElement ();
        int i = elem.indexOf (LTB);
        boolean changed = false;
        while (i != -1) {
            if (i == 0)
                elem = " " + elem.substring (2);
            else
                elem = elem.substring (0, i) + " " + elem.substring (i+2);
            changed = true;
            i = elem.indexOf (LTB);
        }
        int lsIncr = lineSeparator.length () - 1;
        for (i=0; i<elem.length (); i++) {
            if (elem.charAt (i) == NL) {
                elem = elem.substring (0, i) +
                    lineSeparator + elem.substring (i+1);
                i += lsIncr;
                changed = true;
            }
        }
        if (changed)
            p.put (key, elem);
    }

}
 
源代码15 项目: openjdk-jdk8u   文件: Messages.java
/**
 * This method was introduced to fix defect #26964.  For Java 1.0.2
 * on Win NT, the escape sequence \u0020 was not being handled
 * correctly by the Java Properties class when it was the final
 * character of a line.  Instead the trailing blank was dropped
 * and the next line was swallowed as a continuation.  To work
 * around the problem, we introduced our own metasymbol to represent
 * a trailing blank.  Hence:
 *
 * Performs substitution for any metasymbols in the message
 * templates.  So far only %B is needed.  This was introduced
 * to make it more convenient for .properties files to
 * contain message templates with leading or trailing blanks
 * (although %B may actually occur anywhere in a template).
 * Subsequently, checking for '\n' has also been added.  Now,
 * wherever '\n' occurs in a message template, it is replaced
 * with the value of System.getProperty ("line.separator").
 */
private static final void fixMessages (Properties p) {

    Enumeration keys = p.keys ();
    Enumeration elems = p.elements ();
    while (keys.hasMoreElements ()) {
        String key = (String) keys.nextElement ();
        String elem = (String) elems.nextElement ();
        int i = elem.indexOf (LTB);
        boolean changed = false;
        while (i != -1) {
            if (i == 0)
                elem = " " + elem.substring (2);
            else
                elem = elem.substring (0, i) + " " + elem.substring (i+2);
            changed = true;
            i = elem.indexOf (LTB);
        }
        int lsIncr = lineSeparator.length () - 1;
        for (i=0; i<elem.length (); i++) {
            if (elem.charAt (i) == NL) {
                elem = elem.substring (0, i) +
                    lineSeparator + elem.substring (i+1);
                i += lsIncr;
                changed = true;
            }
        }
        if (changed)
            p.put (key, elem);
    }

}
 
源代码16 项目: openjdk-jdk8u-backup   文件: Messages.java
/**
 * This method was introduced to fix defect #26964.  For Java 1.0.2
 * on Win NT, the escape sequence \u0020 was not being handled
 * correctly by the Java Properties class when it was the final
 * character of a line.  Instead the trailing blank was dropped
 * and the next line was swallowed as a continuation.  To work
 * around the problem, we introduced our own metasymbol to represent
 * a trailing blank.  Hence:
 *
 * Performs substitution for any metasymbols in the message
 * templates.  So far only %B is needed.  This was introduced
 * to make it more convenient for .properties files to
 * contain message templates with leading or trailing blanks
 * (although %B may actually occur anywhere in a template).
 * Subsequently, checking for '\n' has also been added.  Now,
 * wherever '\n' occurs in a message template, it is replaced
 * with the value of System.getProperty ("line.separator").
 */
private static final void fixMessages (Properties p) {

    Enumeration keys = p.keys ();
    Enumeration elems = p.elements ();
    while (keys.hasMoreElements ()) {
        String key = (String) keys.nextElement ();
        String elem = (String) elems.nextElement ();
        int i = elem.indexOf (LTB);
        boolean changed = false;
        while (i != -1) {
            if (i == 0)
                elem = " " + elem.substring (2);
            else
                elem = elem.substring (0, i) + " " + elem.substring (i+2);
            changed = true;
            i = elem.indexOf (LTB);
        }
        int lsIncr = lineSeparator.length () - 1;
        for (i=0; i<elem.length (); i++) {
            if (elem.charAt (i) == NL) {
                elem = elem.substring (0, i) +
                    lineSeparator + elem.substring (i+1);
                i += lsIncr;
                changed = true;
            }
        }
        if (changed)
            p.put (key, elem);
    }

}
 
源代码17 项目: openjdk-8   文件: Messages.java
/**
 * This method was introduced to fix defect #26964.  For Java 1.0.2
 * on Win NT, the escape sequence \u0020 was not being handled
 * correctly by the Java Properties class when it was the final
 * character of a line.  Instead the trailing blank was dropped
 * and the next line was swallowed as a continuation.  To work
 * around the problem, we introduced our own metasymbol to represent
 * a trailing blank.  Hence:
 *
 * Performs substitution for any metasymbols in the message
 * templates.  So far only %B is needed.  This was introduced
 * to make it more convenient for .properties files to
 * contain message templates with leading or trailing blanks
 * (although %B may actually occur anywhere in a template).
 * Subsequently, checking for '\n' has also been added.  Now,
 * wherever '\n' occurs in a message template, it is replaced
 * with the value of System.getProperty ("line.separator").
 */
private static final void fixMessages (Properties p) {

    Enumeration keys = p.keys ();
    Enumeration elems = p.elements ();
    while (keys.hasMoreElements ()) {
        String key = (String) keys.nextElement ();
        String elem = (String) elems.nextElement ();
        int i = elem.indexOf (LTB);
        boolean changed = false;
        while (i != -1) {
            if (i == 0)
                elem = " " + elem.substring (2);
            else
                elem = elem.substring (0, i) + " " + elem.substring (i+2);
            changed = true;
            i = elem.indexOf (LTB);
        }
        int lsIncr = lineSeparator.length () - 1;
        for (i=0; i<elem.length (); i++) {
            if (elem.charAt (i) == NL) {
                elem = elem.substring (0, i) +
                    lineSeparator + elem.substring (i+1);
                i += lsIncr;
                changed = true;
            }
        }
        if (changed)
            p.put (key, elem);
    }

}
 
源代码18 项目: hottub   文件: Messages.java
/**
 * This method was introduced to fix defect #26964.  For Java 1.0.2
 * on Win NT, the escape sequence \u0020 was not being handled
 * correctly by the Java Properties class when it was the final
 * character of a line.  Instead the trailing blank was dropped
 * and the next line was swallowed as a continuation.  To work
 * around the problem, we introduced our own metasymbol to represent
 * a trailing blank.  Hence:
 *
 * Performs substitution for any metasymbols in the message
 * templates.  So far only %B is needed.  This was introduced
 * to make it more convenient for .properties files to
 * contain message templates with leading or trailing blanks
 * (although %B may actually occur anywhere in a template).
 * Subsequently, checking for '\n' has also been added.  Now,
 * wherever '\n' occurs in a message template, it is replaced
 * with the value of System.getProperty ("line.separator").
 */
private static final void fixMessages (Properties p) {

    Enumeration keys = p.keys ();
    Enumeration elems = p.elements ();
    while (keys.hasMoreElements ()) {
        String key = (String) keys.nextElement ();
        String elem = (String) elems.nextElement ();
        int i = elem.indexOf (LTB);
        boolean changed = false;
        while (i != -1) {
            if (i == 0)
                elem = " " + elem.substring (2);
            else
                elem = elem.substring (0, i) + " " + elem.substring (i+2);
            changed = true;
            i = elem.indexOf (LTB);
        }
        int lsIncr = lineSeparator.length () - 1;
        for (i=0; i<elem.length (); i++) {
            if (elem.charAt (i) == NL) {
                elem = elem.substring (0, i) +
                    lineSeparator + elem.substring (i+1);
                i += lsIncr;
                changed = true;
            }
        }
        if (changed)
            p.put (key, elem);
    }

}
 
源代码19 项目: openjdk-jdk9   文件: Messages.java
/**
 * This method was introduced to fix defect #26964.  For Java 1.0.2
 * on Win NT, the escape sequence \u0020 was not being handled
 * correctly by the Java Properties class when it was the final
 * character of a line.  Instead the trailing blank was dropped
 * and the next line was swallowed as a continuation.  To work
 * around the problem, we introduced our own metasymbol to represent
 * a trailing blank.  Hence:
 *
 * Performs substitution for any metasymbols in the message
 * templates.  So far only %B is needed.  This was introduced
 * to make it more convenient for .properties files to
 * contain message templates with leading or trailing blanks
 * (although %B may actually occur anywhere in a template).
 * Subsequently, checking for '\n' has also been added.  Now,
 * wherever '\n' occurs in a message template, it is replaced
 * with the value of System.getProperty ("line.separator").
 */
private static final void fixMessages (Properties p) {

    Enumeration keys = p.keys ();
    Enumeration elems = p.elements ();
    while (keys.hasMoreElements ()) {
        String key = (String) keys.nextElement ();
        String elem = (String) elems.nextElement ();
        int i = elem.indexOf (LTB);
        boolean changed = false;
        while (i != -1) {
            if (i == 0)
                elem = " " + elem.substring (2);
            else
                elem = elem.substring (0, i) + " " + elem.substring (i+2);
            changed = true;
            i = elem.indexOf (LTB);
        }
        int lsIncr = lineSeparator.length () - 1;
        for (i=0; i<elem.length (); i++) {
            if (elem.charAt (i) == NL) {
                elem = elem.substring (0, i) +
                    lineSeparator + elem.substring (i+1);
                i += lsIncr;
                changed = true;
            }
        }
        if (changed)
            p.put (key, elem);
    }

}
 
源代码20 项目: wandora   文件: UserManagerAction.java
@Override
protected HashMap<String, Object> getTemplateContext(Template template, HttpServletRequest req, HttpMethod method, String action, User user) throws ActionException {
    String editAction=req.getParameter("editaction");
    if(editAction==null || editAction.length()==0) editAction="userlist";
    
    HashMap<String,Object> params=super.getTemplateContext(template, req, method, action, user);
    
    String userName=req.getParameter("user");
    if(userName!=null) userName=userName.trim();
    if(userName!=null && userName.length()==0) userName=null;
    
    User userObject=null;
    String view="userlist";
    String error=null;
    try{
        if(editAction.equals("userlist")){
            // no side effects, do nothing
        }
        else if(editAction.equals("viewuser")){
            view="user";
            // just check that the user is valid
            if(userName!=null) userObject=userStore.getUser(userName);
        }
        else if(editAction.equals("edituser") || editAction.equals("edituserlist")){
            view="user";
            if(editAction.equals("edituserlist")) view="userlist";

            if(userName!=null) {
                userObject=userStore.getUser(userName);
                if(userObject!=null){

                    Enumeration<String> paramNames=req.getParameterNames();
                    while(paramNames.hasMoreElements()){
                        String key=paramNames.nextElement();
                        String[] values=req.getParameterValues(key);
                        for(String value : values){
                            value=value.trim();
                            if(key.equals("setoption")){
                                int ind=value.indexOf("=");
                                if(ind<0) userObject.setOption(value, "");
                                else {
                                    String k=value.substring(0,ind);
                                    String v=value.substring(ind+1);
                                    userObject.setOption(k,v);
                                }
                            }
                            else if(key.equals("removeoption")){
                                userObject.removeOption(value);
                            }
                            else if(key.equals("addrole")){
                                userObject.addRole(value);
                            }
                            else if(key.equals("removerole")){
                                userObject.removeRole(value);
                            }
                        }
                    }
                    if(!userObject.saveUser()) error="NOEDIT";
                }
            }
        }
        else if(editAction.equals("deleteuser")){
            if(userName!=null) {
                if(!userStore.deleteUser(userName)) error="NODELETE";
            }
        }
        else if(editAction.equals("newuser")){
            view="user";
            if(userName!=null) {
                userObject=userStore.newUser(userName);
                if(userObject==null) error="NONEW";
            }
        }
        else return null;
        
        if(view.equals("user") && userObject==null) {
            if(error==null) error="INVALIDUSER";
            view="userlist";
        }

        if(view.equals("userlist")){
            params.put("allUsers",userStore.getAllUsers());
        }
        else {
            params.put("user",userObject);
        }
        
    }catch(UserStoreException use){
        if(error==null) error="USERSTORE";
    }
            
    params.put("editView",view);
    params.put("error",error);
    
    return params;
}