com.ibm.icu.text.Replaceable Java Examples

The following examples show how to use com.ibm.icu.text.Replaceable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReplaceableUCharacterIterator.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
/**
 * Public constructor
 * @param replaceable text which the iterator will be based on
 */
public ReplaceableUCharacterIterator(Replaceable replaceable){
    if(replaceable==null){
        throw new IllegalArgumentException();
    }
    this.replaceable  = replaceable;
    this.currentIndex = 0;
}
 
Example #2
Source File: ReplaceableUCharacterIterator.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Public constructor
 * @param replaceable text which the iterator will be based on
 */
public ReplaceableUCharacterIterator(Replaceable replaceable){
    if(replaceable==null){
        throw new IllegalArgumentException();
    }
    this.replaceable  = replaceable;
    this.currentIndex = 0;
}
 
Example #3
Source File: Utility.java    From fitnotifications with Apache License 2.0 4 votes vote down vote up
/**
 * Parse a pattern string within the given Replaceable and a parsing
 * pattern.  Characters are matched literally and case-sensitively
 * except for the following special characters:
 *
 * ~  zero or more Pattern_White_Space chars
 *
 * If end of pattern is reached with all matches along the way,
 * pos is advanced to the first unparsed index and returned.
 * Otherwise -1 is returned.
 * @param pat pattern that controls parsing
 * @param text text to be parsed, starting at index
 * @param index offset to first character to parse
 * @param limit offset after last character to parse
 * @return index after last parsed character, or -1 on parse failure.
 */
public static int parsePattern(String pat,
        Replaceable text,
        int index,
        int limit) {
    int ipat = 0;

    // empty pattern matches immediately
    if (ipat == pat.length()) {
        return index;
    }

    int cpat = Character.codePointAt(pat, ipat);

    while (index < limit) {
        int c = text.char32At(index);

        // parse \s*
        if (cpat == '~') {
            if (PatternProps.isWhiteSpace(c)) {
                index += UTF16.getCharCount(c);
                continue;
            } else {
                if (++ipat == pat.length()) {
                    return index; // success; c unparsed
                }
                // fall thru; process c again with next cpat
            }
        }

        // parse literal
        else if (c == cpat) {
            int n = UTF16.getCharCount(c);
            index += n;
            ipat += n;
            if (ipat == pat.length()) {
                return index; // success; c parsed
            }
            // fall thru; get next cpat
        }

        // match failure of literal
        else {
            return -1;
        }

        cpat = UTF16.charAt(pat, ipat);
    }

    return -1; // text ended before end of pat
}
 
Example #4
Source File: UtilityExtensions.java    From fitnotifications with Apache License 2.0 4 votes vote down vote up
/**
 * Convenience method.
 */
public static String formatInput(Replaceable input,
                                 Transliterator.Position pos) {
    return formatInput((ReplaceableString) input, pos);
}
 
Example #5
Source File: UtilityExtensions.java    From fitnotifications with Apache License 2.0 4 votes vote down vote up
/**
 * Convenience method.
 */
public static StringBuffer formatInput(StringBuffer appendTo,
                                       Replaceable input,
                                       Transliterator.Position pos) {
    return formatInput(appendTo, (ReplaceableString) input, pos);
}
 
Example #6
Source File: Utility.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Parse a pattern string within the given Replaceable and a parsing
 * pattern.  Characters are matched literally and case-sensitively
 * except for the following special characters:
 *
 * ~  zero or more Pattern_White_Space chars
 *
 * If end of pattern is reached with all matches along the way,
 * pos is advanced to the first unparsed index and returned.
 * Otherwise -1 is returned.
 * @param pat pattern that controls parsing
 * @param text text to be parsed, starting at index
 * @param index offset to first character to parse
 * @param limit offset after last character to parse
 * @return index after last parsed character, or -1 on parse failure.
 */
public static int parsePattern(String pat,
        Replaceable text,
        int index,
        int limit) {
    int ipat = 0;

    // empty pattern matches immediately
    if (ipat == pat.length()) {
        return index;
    }

    int cpat = Character.codePointAt(pat, ipat);

    while (index < limit) {
        int c = text.char32At(index);

        // parse \s*
        if (cpat == '~') {
            if (PatternProps.isWhiteSpace(c)) {
                index += UTF16.getCharCount(c);
                continue;
            } else {
                if (++ipat == pat.length()) {
                    return index; // success; c unparsed
                }
                // fall thru; process c again with next cpat
            }
        }

        // parse literal
        else if (c == cpat) {
            int n = UTF16.getCharCount(c);
            index += n;
            ipat += n;
            if (ipat == pat.length()) {
                return index; // success; c parsed
            }
            // fall thru; get next cpat
        }

        // match failure of literal
        else {
            return -1;
        }

        cpat = UTF16.charAt(pat, ipat);
    }

    return -1; // text ended before end of pat
}