diff options
Diffstat (limited to 'java/src/IceInternal/StringUtil.java')
-rw-r--r-- | java/src/IceInternal/StringUtil.java | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/java/src/IceInternal/StringUtil.java b/java/src/IceInternal/StringUtil.java new file mode 100644 index 00000000000..8a64798de37 --- /dev/null +++ b/java/src/IceInternal/StringUtil.java @@ -0,0 +1,78 @@ +// ********************************************************************** +// +// Copyright (c) 2002 +// Mutable Realms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +package IceInternal; + +public final class StringUtil +{ + // + // Return the index of the first character in str to + // appear in match, starting from 0. Returns -1 if none is + // found. + // + public static int + findFirstOf(String str, String match) + { + return findFirstOf(str, match, 0); + } + + // + // Return the index of the first character in str to + // appear in match, starting from start. Returns -1 if none is + // found. + // + public static int + findFirstOf(String str, String match, int start) + { + final int len = str.length(); + for(int i = start; i < len; i++) + { + char ch = str.charAt(i); + if(match.indexOf(ch) != -1) + { + return i; + } + } + + return -1; + } + + // + // Return the index of the first character in str which does + // not appear in match, starting from 0. Returns -1 if none is + // found. + // + public static int + findFirstNotOf(String str, String match) + { + return findFirstNotOf(str, match, 0); + } + + // + // Return the index of the first character in str which does + // not appear in match, starting from start. Returns -1 if none is + // found. + // + public static int + findFirstNotOf(String str, String match, int start) + { + final int len = str.length(); + for(int i = start; i < len; i++) + { + char ch = str.charAt(i); + if(match.indexOf(ch) == -1) + { + return i; + } + } + + return -1; + } +} |