1 /*
2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
3834 if (position > length) {
3835 throw new IndexOutOfBoundsException();
3836 }
3837 if (position == length) {
3838 return ~position;
3839 }
3840
3841 // handle fixed time-zone IDs
3842 char nextChar = text.charAt(position);
3843 if (nextChar == '+' || nextChar == '-') {
3844 return parseOffsetBased(context, text, position, position, OffsetIdPrinterParser.INSTANCE_ID_Z);
3845 } else if (length >= position + 2) {
3846 char nextNextChar = text.charAt(position + 1);
3847 if (context.charEquals(nextChar, 'U') && context.charEquals(nextNextChar, 'T')) {
3848 if (length >= position + 3 && context.charEquals(text.charAt(position + 2), 'C')) {
3849 return parseOffsetBased(context, text, position, position + 3, OffsetIdPrinterParser.INSTANCE_ID_ZERO);
3850 }
3851 return parseOffsetBased(context, text, position, position + 2, OffsetIdPrinterParser.INSTANCE_ID_ZERO);
3852 } else if (context.charEquals(nextChar, 'G') && length >= position + 3 &&
3853 context.charEquals(nextNextChar, 'M') && context.charEquals(text.charAt(position + 2), 'T')) {
3854 return parseOffsetBased(context, text, position, position + 3, OffsetIdPrinterParser.INSTANCE_ID_ZERO);
3855 }
3856 }
3857
3858 // parse
3859 PrefixTree tree = getTree(context);
3860 ParsePosition ppos = new ParsePosition(position);
3861 String parsedZoneId = tree.match(text, ppos);
3862 if (parsedZoneId == null) {
3863 if (context.charEquals(nextChar, 'Z')) {
3864 context.setParsed(ZoneOffset.UTC);
3865 return position + 1;
3866 }
3867 return ~position;
3868 }
3869 context.setParsed(ZoneId.of(parsedZoneId));
3870 return ppos.getIndex();
3871 }
3872
3873 /**
|
1 /*
2 * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
3834 if (position > length) {
3835 throw new IndexOutOfBoundsException();
3836 }
3837 if (position == length) {
3838 return ~position;
3839 }
3840
3841 // handle fixed time-zone IDs
3842 char nextChar = text.charAt(position);
3843 if (nextChar == '+' || nextChar == '-') {
3844 return parseOffsetBased(context, text, position, position, OffsetIdPrinterParser.INSTANCE_ID_Z);
3845 } else if (length >= position + 2) {
3846 char nextNextChar = text.charAt(position + 1);
3847 if (context.charEquals(nextChar, 'U') && context.charEquals(nextNextChar, 'T')) {
3848 if (length >= position + 3 && context.charEquals(text.charAt(position + 2), 'C')) {
3849 return parseOffsetBased(context, text, position, position + 3, OffsetIdPrinterParser.INSTANCE_ID_ZERO);
3850 }
3851 return parseOffsetBased(context, text, position, position + 2, OffsetIdPrinterParser.INSTANCE_ID_ZERO);
3852 } else if (context.charEquals(nextChar, 'G') && length >= position + 3 &&
3853 context.charEquals(nextNextChar, 'M') && context.charEquals(text.charAt(position + 2), 'T')) {
3854 if (length >= position + 4 && context.charEquals(text.charAt(position + 3), '0')) {
3855 context.setParsed(ZoneId.of("GMT0"));
3856 return position + 4;
3857 }
3858 return parseOffsetBased(context, text, position, position + 3, OffsetIdPrinterParser.INSTANCE_ID_ZERO);
3859 }
3860 }
3861
3862 // parse
3863 PrefixTree tree = getTree(context);
3864 ParsePosition ppos = new ParsePosition(position);
3865 String parsedZoneId = tree.match(text, ppos);
3866 if (parsedZoneId == null) {
3867 if (context.charEquals(nextChar, 'Z')) {
3868 context.setParsed(ZoneOffset.UTC);
3869 return position + 1;
3870 }
3871 return ~position;
3872 }
3873 context.setParsed(ZoneId.of(parsedZoneId));
3874 return ppos.getIndex();
3875 }
3876
3877 /**
|