src/share/classes/com/sun/tools/javac/util/StringUtils.java

changeset 2415
7ceaee0e497b
parent 2413
fe033d997ddf
child 2525
2eb010b6cb22
     1.1 --- a/src/share/classes/com/sun/tools/javac/util/StringUtils.java	Thu Dec 19 11:38:45 2013 -0500
     1.2 +++ b/src/share/classes/com/sun/tools/javac/util/StringUtils.java	Thu May 29 10:48:00 2014 +0200
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -26,6 +26,8 @@
    1.11  package com.sun.tools.javac.util;
    1.12  
    1.13  import java.util.Locale;
    1.14 +import java.util.regex.Matcher;
    1.15 +import java.util.regex.Pattern;
    1.16  
    1.17  /** A collection of utilities for String manipulation.
    1.18   *
    1.19 @@ -50,4 +52,19 @@
    1.20          return source.toUpperCase(Locale.US);
    1.21      }
    1.22  
    1.23 +    /**Case insensitive version of {@link String#indexOf(java.lang.String)}. Equivalent to
    1.24 +     * {@code text.indexOf(str)}, except the matching is case insensitive.
    1.25 +     */
    1.26 +    public static int indexOfIgnoreCase(String text, String str) {
    1.27 +        return indexOfIgnoreCase(text, str, 0);
    1.28 +    }
    1.29 +
    1.30 +    /**Case insensitive version of {@link String#indexOf(java.lang.String, int)}. Equivalent to
    1.31 +     * {@code text.indexOf(str, startIndex)}, except the matching is case insensitive.
    1.32 +     */
    1.33 +    public static int indexOfIgnoreCase(String text, String str, int startIndex) {
    1.34 +        Matcher m = Pattern.compile(Pattern.quote(str), Pattern.CASE_INSENSITIVE).matcher(text);
    1.35 +        return m.find(startIndex) ? m.start() : -1;
    1.36 +    }
    1.37 +
    1.38  }

mercurial