ICU-1533 incorporate Mark's review comments

X-SVN-Rev: 7100
This commit is contained in:
Alan Liu 2001-11-27 21:48:50 +00:00
parent e82e5f3e12
commit 2a7014c1a0
4 changed files with 84 additions and 76 deletions

View file

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/impl/Utility.java,v $
* $Date: 2001/11/21 22:22:10 $
* $Revision: 1.13 $
* $Date: 2001/11/27 21:48:50 $
* $Revision: 1.14 $
*
*****************************************************************************************
*/
@ -16,6 +16,10 @@ import com.ibm.text.UTF16;
public final class Utility {
// Other special characters
private static final char QUOTE = '\'';
private static final char ESCAPE_CHAR = '\\';
/**
* Convenience utility to compare two Object[]s.
* Ought to be in System
@ -1135,4 +1139,36 @@ public final class Utility {
}
return false;
}
/**
* Returns the index of the first character in a set, ignoring quoted text.
* For example, in the string "abc'hide'h", the 'h' in "hide" will not be
* found by a search for "h". Unlike String.indexOf(), this method searches
* not for a single character, but for any character of the string
* <code>setOfChars</code>.
* @param text text to be searched
* @param start the beginning index, inclusive; <code>0 <= start
* <= limit</code>.
* @param limit the ending index, exclusive; <code>start <= limit
* <= text.length()</code>.
* @param setOfChars string with one or more distinct characters
* @return Offset of the first character in <code>setOfChars</code>
* found, or -1 if not found.
* @see #indexOf
*/
public static int quotedIndexOf(String text, int start, int limit,
String setOfChars) {
for (int i=start; i<limit; ++i) {
char c = text.charAt(i);
if (c == ESCAPE_CHAR) {
++i;
} else if (c == QUOTE) {
while (++i < limit
&& text.charAt(i) != QUOTE) {}
} else if (setOfChars.indexOf(c) >= 0) {
return i;
}
}
return -1;
}
}

View file

@ -4,8 +4,8 @@
* Corporation and others. All Rights Reserved.
**********************************************************************
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/TransliteratorParser.java,v $
* $Date: 2001/11/27 21:43:00 $
* $Revision: 1.15 $
* $Date: 2001/11/27 21:48:31 $
* $Revision: 1.16 $
**********************************************************************
*/
package com.ibm.text;
@ -1129,7 +1129,7 @@ class TransliteratorParser {
* does not contain quantifiers or other special input-only elements.
*/
private boolean isValidOutput(String output) {
for (int i=0; i<output.length(); ++i) {
for (int i=0; i<output.length(); ) {
int c = UTF16.charAt(output, i);
i += UTF16.getCharCount(c);
if (parseData.lookupMatcher(c) != null) {
@ -1260,7 +1260,7 @@ class TransliteratorParser {
}
static final int ruleEnd(String rule, int start, int limit) {
int end = quotedIndexOf(rule, start, limit, ";");
int end = Utility.quotedIndexOf(rule, start, limit, ";");
if (end < 0) {
end = limit;
}
@ -1342,38 +1342,6 @@ class TransliteratorParser {
}
return data.getSegmentStandin(r);
}
/**
* Returns the index of the first character in a set, ignoring quoted text.
* For example, in the string "abc'hide'h", the 'h' in "hide" will not be
* found by a search for "h". Unlike String.indexOf(), this method searches
* not for a single character, but for any character of the string
* <code>setOfChars</code>.
* @param text text to be searched
* @param start the beginning index, inclusive; <code>0 <= start
* <= limit</code>.
* @param limit the ending index, exclusive; <code>start <= limit
* <= text.length()</code>.
* @param setOfChars string with one or more distinct characters
* @return Offset of the first character in <code>setOfChars</code>
* found, or -1 if not found.
* @see #indexOf
*/
private static int quotedIndexOf(String text, int start, int limit,
String setOfChars) {
for (int i=start; i<limit; ++i) {
char c = text.charAt(i);
if (c == ESCAPE) {
++i;
} else if (c == QUOTE) {
while (++i < limit
&& text.charAt(i) != QUOTE) {}
} else if (setOfChars.indexOf(c) >= 0) {
return i;
}
}
return -1;
}
}
//eof

View file

@ -4,8 +4,8 @@
* Corporation and others. All Rights Reserved.
**********************************************************************
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/text/Attic/TransliteratorParser.java,v $
* $Date: 2001/11/27 21:43:00 $
* $Revision: 1.15 $
* $Date: 2001/11/27 21:48:31 $
* $Revision: 1.16 $
**********************************************************************
*/
package com.ibm.text;
@ -1129,7 +1129,7 @@ class TransliteratorParser {
* does not contain quantifiers or other special input-only elements.
*/
private boolean isValidOutput(String output) {
for (int i=0; i<output.length(); ++i) {
for (int i=0; i<output.length(); ) {
int c = UTF16.charAt(output, i);
i += UTF16.getCharCount(c);
if (parseData.lookupMatcher(c) != null) {
@ -1260,7 +1260,7 @@ class TransliteratorParser {
}
static final int ruleEnd(String rule, int start, int limit) {
int end = quotedIndexOf(rule, start, limit, ";");
int end = Utility.quotedIndexOf(rule, start, limit, ";");
if (end < 0) {
end = limit;
}
@ -1342,38 +1342,6 @@ class TransliteratorParser {
}
return data.getSegmentStandin(r);
}
/**
* Returns the index of the first character in a set, ignoring quoted text.
* For example, in the string "abc'hide'h", the 'h' in "hide" will not be
* found by a search for "h". Unlike String.indexOf(), this method searches
* not for a single character, but for any character of the string
* <code>setOfChars</code>.
* @param text text to be searched
* @param start the beginning index, inclusive; <code>0 <= start
* <= limit</code>.
* @param limit the ending index, exclusive; <code>start <= limit
* <= text.length()</code>.
* @param setOfChars string with one or more distinct characters
* @return Offset of the first character in <code>setOfChars</code>
* found, or -1 if not found.
* @see #indexOf
*/
private static int quotedIndexOf(String text, int start, int limit,
String setOfChars) {
for (int i=start; i<limit; ++i) {
char c = text.charAt(i);
if (c == ESCAPE) {
++i;
} else if (c == QUOTE) {
while (++i < limit
&& text.charAt(i) != QUOTE) {}
} else if (setOfChars.indexOf(c) >= 0) {
return i;
}
}
return -1;
}
}
//eof

View file

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/util/Attic/Utility.java,v $
* $Date: 2001/11/21 22:22:10 $
* $Revision: 1.13 $
* $Date: 2001/11/27 21:48:50 $
* $Revision: 1.14 $
*
*****************************************************************************************
*/
@ -16,6 +16,10 @@ import com.ibm.text.UTF16;
public final class Utility {
// Other special characters
private static final char QUOTE = '\'';
private static final char ESCAPE_CHAR = '\\';
/**
* Convenience utility to compare two Object[]s.
* Ought to be in System
@ -1135,4 +1139,36 @@ public final class Utility {
}
return false;
}
/**
* Returns the index of the first character in a set, ignoring quoted text.
* For example, in the string "abc'hide'h", the 'h' in "hide" will not be
* found by a search for "h". Unlike String.indexOf(), this method searches
* not for a single character, but for any character of the string
* <code>setOfChars</code>.
* @param text text to be searched
* @param start the beginning index, inclusive; <code>0 <= start
* <= limit</code>.
* @param limit the ending index, exclusive; <code>start <= limit
* <= text.length()</code>.
* @param setOfChars string with one or more distinct characters
* @return Offset of the first character in <code>setOfChars</code>
* found, or -1 if not found.
* @see #indexOf
*/
public static int quotedIndexOf(String text, int start, int limit,
String setOfChars) {
for (int i=start; i<limit; ++i) {
char c = text.charAt(i);
if (c == ESCAPE_CHAR) {
++i;
} else if (c == QUOTE) {
while (++i < limit
&& text.charAt(i) != QUOTE) {}
} else if (setOfChars.indexOf(c) >= 0) {
return i;
}
}
return -1;
}
}