当前位置: 首页>>代码示例>>Java>>正文


Java ParsePosition.setErrorIndex方法代码示例

本文整理汇总了Java中java.text.ParsePosition.setErrorIndex方法的典型用法代码示例。如果您正苦于以下问题:Java ParsePosition.setErrorIndex方法的具体用法?Java ParsePosition.setErrorIndex怎么用?Java ParsePosition.setErrorIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.text.ParsePosition的用法示例。


在下文中一共展示了ParsePosition.setErrorIndex方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseZoneID

import java.text.ParsePosition; //导入方法依赖的package包/类
/**
 * Parse a zone ID.
 * @param text the text contains a time zone ID string at the position.
 * @param pos the position.
 * @return The zone ID parsed.
 */
private static String parseZoneID(String text, ParsePosition pos) {
    String resolvedID = null;
    if (ZONE_ID_TRIE == null) {
        synchronized (TimeZoneFormat.class) {
            if (ZONE_ID_TRIE == null) {
                // Build zone ID trie
                TextTrieMap<String> trie = new TextTrieMap<String>(true);
                String[] ids = TimeZone.getAvailableIDs();
                for (String id : ids) {
                    trie.put(id, id);
                }
                ZONE_ID_TRIE = trie;
            }
        }
    }

    int[] matchLen = new int[] {0};
    Iterator<String> itr = ZONE_ID_TRIE.get(text, pos.getIndex(), matchLen);
    if (itr != null) {
        resolvedID = itr.next();
        pos.setIndex(pos.getIndex() + matchLen[0]);
    } else {
        // TODO
        // We many need to handle rule based custom zone ID (See ZoneMeta.parseCustomID),
        // such as GM+05:00. However, the public parse method in this class also calls
        // parseOffsetLocalizedGMT and custom zone IDs are likely supported by the parser,
        // so we might not need to handle them here.
        pos.setErrorIndex(pos.getIndex());
    }
    return resolvedID;
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:38,代码来源:TimeZoneFormat.java

示例2: parseShortZoneID

import java.text.ParsePosition; //导入方法依赖的package包/类
/**
 * Parse a short zone ID.
 * @param text the text contains a time zone ID string at the position.
 * @param pos the position.
 * @return The zone ID for the parsed short zone ID.
 */
private static String parseShortZoneID(String text, ParsePosition pos) {
    String resolvedID = null;
    if (SHORT_ZONE_ID_TRIE == null) {
        synchronized (TimeZoneFormat.class) {
            if (SHORT_ZONE_ID_TRIE == null) {
                // Build short zone ID trie
                TextTrieMap<String> trie = new TextTrieMap<String>(true);
                Set<String> canonicalIDs = TimeZone.getAvailableIDs(SystemTimeZoneType.CANONICAL, null, null);
                for (String id : canonicalIDs) {
                    String shortID = ZoneMeta.getShortID(id);
                    if (shortID != null) {
                        trie.put(shortID, id);
                    }
                }
                // Canonical list does not contain Etc/Unknown
                trie.put(UNKNOWN_SHORT_ZONE_ID, UNKNOWN_ZONE_ID);
                SHORT_ZONE_ID_TRIE = trie;
            }
        }
    }

    int[] matchLen = new int[] {0};
    Iterator<String> itr = SHORT_ZONE_ID_TRIE.get(text, pos.getIndex(), matchLen);
    if (itr != null) {
        resolvedID = itr.next();
        pos.setIndex(pos.getIndex() + matchLen[0]);
    } else {
        pos.setErrorIndex(pos.getIndex());
    }

    return resolvedID;
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:39,代码来源:TimeZoneFormat.java

示例3: parseExemplarLocation

import java.text.ParsePosition; //导入方法依赖的package包/类
/**
 * Parse an exemplar location string.
 * @param text the text contains an exemplar location string at the position.
 * @param pos the position.
 * @return The zone ID for the parsed exemplar location.
 */
private String parseExemplarLocation(String text, ParsePosition pos) {
    int startIdx = pos.getIndex();
    int parsedPos = -1;
    String tzID = null;

    EnumSet<NameType> nameTypes = EnumSet.of(NameType.EXEMPLAR_LOCATION);
    Collection<MatchInfo> exemplarMatches = _tznames.find(text, startIdx, nameTypes);
    if (exemplarMatches != null) {
        MatchInfo exemplarMatch = null;
        for (MatchInfo match : exemplarMatches) {
            if (startIdx + match.matchLength() > parsedPos) {
                exemplarMatch = match;
                parsedPos = startIdx + match.matchLength();
            }
        }
        if (exemplarMatch != null) {
            tzID = getTimeZoneID(exemplarMatch.tzID(), exemplarMatch.mzID());
            pos.setIndex(parsedPos);
        }
    }
    if (tzID == null) {
        pos.setErrorIndex(startIdx);
    }

    return tzID;
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:33,代码来源:TimeZoneFormat.java

示例4: parseChoiceArgument

import java.text.ParsePosition; //导入方法依赖的package包/类
private static double parseChoiceArgument(
        MessagePattern pattern, int partIndex,
        String source, ParsePosition pos) {
    // find the best number (defined as the one with the longest parse)
    int start = pos.getIndex();
    int furthest = start;
    double bestNumber = Double.NaN;
    double tempNumber = 0.0;
    while (pattern.getPartType(partIndex) != Part.Type.ARG_LIMIT) {
        tempNumber = pattern.getNumericValue(pattern.getPart(partIndex));
        partIndex += 2;  // skip the numeric part and ignore the ARG_SELECTOR
        int msgLimit = pattern.getLimitPartIndex(partIndex);
        int len = matchStringUntilLimitPart(pattern, partIndex, msgLimit, source, start);
        if (len >= 0) {
            int newIndex = start + len;
            if (newIndex > furthest) {
                furthest = newIndex;
                bestNumber = tempNumber;
                if (furthest == source.length()) {
                    break;
                }
            }
        }
        partIndex = msgLimit + 1;
    }
    if (furthest == start) {
        pos.setErrorIndex(start);
    } else {
        pos.setIndex(furthest);
    }
    return bestNumber;
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:33,代码来源:MessageFormat.java

示例5: parseUnresolved0

import java.text.ParsePosition; //导入方法依赖的package包/类
private DateTimeParseContext parseUnresolved0(CharSequence text, ParsePosition position) {
    Objects.requireNonNull(text, "text");
    Objects.requireNonNull(position, "position");
    DateTimeParseContext context = new DateTimeParseContext(this);
    int pos = position.getIndex();
    pos = printerParser.parse(context, text, pos);
    if (pos < 0) {
        position.setErrorIndex(~pos);  // index not updated from input
        return null;
    }
    position.setIndex(pos);  // errorIndex not updated from input
    return context;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:14,代码来源:DateTimeFormatter.java

示例6: parseOffsetLocalizedGMT

import java.text.ParsePosition; //导入方法依赖的package包/类
/**
     * Returns offset from GMT(UTC) in milliseconds for the given localized GMT
     * offset format string. When the given string cannot be parsed, this method
     * sets the current position as the error index to <code>ParsePosition pos</code>
     * and returns 0.
     *
     * @param text the text contains a localized GMT offset string at the position.
     * @param pos the position.
     * @param isShort true if this parser to try the short format first
     * @param hasDigitOffset receiving if the parsed zone string contains offset digits.
     * @return the offset from GMT(UTC) in milliseconds for the given localized GMT
     * offset format string.
     */
    private int parseOffsetLocalizedGMT(String text, ParsePosition pos, boolean isShort, Output<Boolean> hasDigitOffset) {
        int start = pos.getIndex();
        int offset = 0;
        int[] parsedLength = {0};

        if (hasDigitOffset != null) {
            hasDigitOffset.value = false;
        }

        offset = parseOffsetLocalizedGMTPattern(text, start, isShort, parsedLength);

        // For now, parseOffsetLocalizedGMTPattern handles both long and short
        // formats, no matter isShort is true or false. This might be changed in future
        // when strict parsing is necessary, or different set of patterns are used for
        // short/long formats.
//        if (parsedLength[0] == 0) {
//            offset = parseOffsetLocalizedGMTPattern(text, start, !isShort, parsedLength);
//        }

        if (parsedLength[0] > 0) {
            if (hasDigitOffset != null) {
                hasDigitOffset.value = true;
            }
            pos.setIndex(start + parsedLength[0]);
            return offset;
        }

        // Try the default patterns
        offset = parseOffsetDefaultLocalizedGMT(text, start, parsedLength);
        if (parsedLength[0] > 0) {
            if (hasDigitOffset != null) {
                hasDigitOffset.value = true;
            }
            pos.setIndex(start + parsedLength[0]);
            return offset;
        }

        // Check if this is a GMT zero format
        if (text.regionMatches(true, start, _gmtZeroFormat, 0, _gmtZeroFormat.length())) {
            pos.setIndex(start + _gmtZeroFormat.length());
            return 0;
        }

        // Check if this is a default GMT zero format
        for (String defGMTZero : ALT_GMT_STRINGS) {
            if (text.regionMatches(true, start, defGMTZero, 0, defGMTZero.length())) {
                pos.setIndex(start + defGMTZero.length());
                return 0;
            }
        }

        // Nothing matched
        pos.setErrorIndex(start);
        return 0;
    }
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:69,代码来源:TimeZoneFormat.java

示例7: parseOffsetISO8601

import java.text.ParsePosition; //导入方法依赖的package包/类
/**
 * Returns offset from GMT(UTC) in milliseconds for the given ISO 8601 time zone string
 * (basic format, extended format, or UTC indicator). When the given string is not an ISO 8601 time
 * zone string, this method sets the current position as the error index
 * to <code>ParsePosition pos</code> and returns 0.
 *
 * @param text the text contains ISO 8601 style time zone string (e.g. "-08", "-08:00", "Z")
 * at the position.
 * @param pos the position.
 * @param extendedOnly <code>true</code> if parsing the text as ISO 8601 extended offset format (e.g. "-08:00"),
 *                     or <code>false</code> to evaluate the text as basic format.
 * @param hasDigitOffset receiving if the parsed zone string contains offset digits.
 * @return the offset from GMT(UTC) in milliseconds for the given ISO 8601 style
 * time zone string.
 */
private static int parseOffsetISO8601(String text, ParsePosition pos, boolean extendedOnly, Output<Boolean> hasDigitOffset) {
    if (hasDigitOffset != null) {
        hasDigitOffset.value = false;
    }
    int start = pos.getIndex();
    if (start >= text.length()) {
        pos.setErrorIndex(start);
        return 0;
    }

    char firstChar = text.charAt(start);
    if (Character.toUpperCase(firstChar) == ISO8601_UTC.charAt(0)) {
        // "Z" - indicates UTC
        pos.setIndex(start + 1);
        return 0;
    }

    int sign;
    if (firstChar == '+') {
        sign = 1;
    } else if (firstChar == '-') {
        sign = -1;
    } else {
        // Not an ISO 8601 offset string
        pos.setErrorIndex(start);
        return 0;
    }
    ParsePosition posOffset = new ParsePosition(start + 1);
    int offset = parseAsciiOffsetFields(text, posOffset, ':', OffsetFields.H, OffsetFields.HMS);
    if (posOffset.getErrorIndex() == -1 && !extendedOnly && (posOffset.getIndex() - start <= 3)) {
        // If the text is successfully parsed as extended format with the options above, it can be also parsed
        // as basic format. For example, "0230" can be parsed as offset 2:00 (only first digits are valid for
        // extended format), but it can be parsed as offset 2:30 with basic format. We use longer result.
        ParsePosition posBasic = new ParsePosition(start + 1);
        int tmpOffset = parseAbuttingAsciiOffsetFields(text, posBasic, OffsetFields.H, OffsetFields.HMS, false);
        if (posBasic.getErrorIndex() == -1 && posBasic.getIndex() > posOffset.getIndex()) {
            offset = tmpOffset;
            posOffset.setIndex(posBasic.getIndex());
        }
    }

    if (posOffset.getErrorIndex() != -1) {
        pos.setErrorIndex(start);
        return 0;
    }

    pos.setIndex(posOffset.getIndex());
    if (hasDigitOffset != null) {
        hasDigitOffset.value = true;
    }
    return sign * offset;
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:68,代码来源:TimeZoneFormat.java

示例8: parse

import java.text.ParsePosition; //导入方法依赖的package包/类
/**
 * Parses a date/time string according to the given parse position.  For
 * example, a time text "07/10/96 4:5 PM, PDT" will be parsed into a Date
 * that is equivalent to Date(837039928046).
 *
 * <p> By default, parsing is lenient: If the input is not in the form used
 * by this object's format method but can still be parsed as a date, then
 * the parse succeeds.  Clients may insist on strict adherence to the
 * format by calling setLenient(false).
 *
 * <p> Note that the normal date formats associated with some calendars - such
 * as the Chinese lunar calendar - do not specify enough fields to enable
 * dates to be parsed unambiguously. In the case of the Chinese lunar
 * calendar, while the year within the current 60-year cycle is specified,
 * the number of such cycles since the start date of the calendar (in the
 * ERA field of the Calendar object) is not normally part of the format,
 * and parsing may assume the wrong era. For cases such as this it is
 * recommended that clients parse using the parse method that takes a Calendar
 * with the Calendar passed in set to the current date, or to a date
 * within the era/cycle that should be assumed if absent in the format.
 *
 * @see #setLenient(boolean)
 *
 * @param text  The date/time string to be parsed
 *
 * @param pos   On input, the position at which to start parsing; on
 *              output, the position at which parsing terminated, or the
 *              start position if the parse failed.
 *
 * @return      A Date, or null if the input could not be parsed
 * @stable ICU 2.0
 */
public Date parse(String text, ParsePosition pos) {
    Date result = null;
    int start = pos.getIndex();
    TimeZone tzsav = calendar.getTimeZone();
    calendar.clear();
    parse(text, calendar, pos);
    if (pos.getIndex() != start) {
        try {
            result = calendar.getTime();
        } catch (IllegalArgumentException e) {
            // This occurs if the calendar is non-lenient and there is
            // an out-of-range field.  We don't know which field was
            // illegal so we set the error index to the start.
            pos.setIndex(start);
            pos.setErrorIndex(start);
        }
    }
    // Restore TimeZone
    calendar.setTimeZone(tzsav);
    return result;
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:54,代码来源:DateFormat.java

示例9: parseObject

import java.text.ParsePosition; //导入方法依赖的package包/类
/**
 * <p>Parsing is not supported.</p>
 * 
 * @param source  the string to parse
 * @param pos  the parsing position
 * @return <code>null</code> as not supported
 */
public Object parseObject(String source, ParsePosition pos) {
    pos.setIndex(0);
    pos.setErrorIndex(0);
    return null;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:13,代码来源:FastDateFormat.java


注:本文中的java.text.ParsePosition.setErrorIndex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。