1 /* |
1 /* |
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
24 */ |
24 */ |
25 |
25 |
26 package com.sun.tools.javac.util; |
26 package com.sun.tools.javac.util; |
27 |
27 |
28 import java.util.Locale; |
28 import java.util.Locale; |
|
29 import java.util.regex.Matcher; |
|
30 import java.util.regex.Pattern; |
29 |
31 |
30 /** A collection of utilities for String manipulation. |
32 /** A collection of utilities for String manipulation. |
31 * |
33 * |
32 * <p><b>This is NOT part of any supported API. |
34 * <p><b>This is NOT part of any supported API. |
33 * If you write code that depends on this, you do so at your own risk. |
35 * If you write code that depends on this, you do so at your own risk. |
48 */ |
50 */ |
49 public static String toUpperCase(String source) { |
51 public static String toUpperCase(String source) { |
50 return source.toUpperCase(Locale.US); |
52 return source.toUpperCase(Locale.US); |
51 } |
53 } |
52 |
54 |
|
55 /**Case insensitive version of {@link String#indexOf(java.lang.String)}. Equivalent to |
|
56 * {@code text.indexOf(str)}, except the matching is case insensitive. |
|
57 */ |
|
58 public static int indexOfIgnoreCase(String text, String str) { |
|
59 return indexOfIgnoreCase(text, str, 0); |
|
60 } |
|
61 |
|
62 /**Case insensitive version of {@link String#indexOf(java.lang.String, int)}. Equivalent to |
|
63 * {@code text.indexOf(str, startIndex)}, except the matching is case insensitive. |
|
64 */ |
|
65 public static int indexOfIgnoreCase(String text, String str, int startIndex) { |
|
66 Matcher m = Pattern.compile(Pattern.quote(str), Pattern.CASE_INSENSITIVE).matcher(text); |
|
67 return m.find(startIndex) ? m.start() : -1; |
|
68 } |
|
69 |
53 } |
70 } |