MCPcopy Create free account
hub / github.com/MenoData/Time4J / parse

Method parse

base/src/main/java/net/time4j/calendar/EastAsianME.java:172–274  ·  view source on GitHub ↗
(
        CharSequence text,
        ParsePosition status,
        AttributeQuery attributes
    )

Source from the content-addressed store, hash-verified

170 }
171
172 @Override
173 public EastAsianMonth parse(
174 CharSequence text,
175 ParsePosition status,
176 AttributeQuery attributes
177 ) {
178
179 Locale loc = attributes.get(Attributes.LANGUAGE, Locale.ROOT);
180 int len = text.length();
181 int start = status.getIndex();
182
183 if (start >= len) {
184 status.setErrorIndex(len);
185 return null;
186 }
187
188 boolean leap = false;
189 EastAsianMonth eam;
190
191 if (attributes.contains(DualFormatElement.COUNT_OF_PATTERN_SYMBOLS)) { // numeric case
192 Map<String, String> textForms = CalendarText.getInstance("generic", loc).getTextForms();
193 NumberSystem numsys = attributes.get(Attributes.NUMBER_SYSTEM, NumberSystem.ARABIC);
194 int pos = start;
195 char zeroDigit = attributes.get(Attributes.ZERO_DIGIT, numsys.getDigits().charAt(0));
196
197 boolean trailing =
198 attributes.get(EastAsianMonth.LEAP_MONTH_IS_TRAILING, "R".equals(textForms.get("leap-alignment")));
199 char indicator =
200 attributes.get(EastAsianMonth.LEAP_MONTH_INDICATOR, textForms.get("leap-indicator").charAt(0));
201
202 if (!trailing && (text.charAt(pos) == indicator)) {
203 pos++;
204 leap = true;
205 }
206
207 if (numsys.isDecimal()) {
208 // ignore possible padding
209 while ((pos < len) && (text.charAt(pos) == zeroDigit)) {
210 pos++;
211 }
212 }
213
214 int m = 0;
215
216 for (int num = 12; (num >= 1) && (m == 0); num--) {
217 String display = DualFormatElement.toNumeral(numsys, zeroDigit, num);
218 int numlen = display.length();
219 for (int i = 0; ; i++) {
220 if ((len > pos + i) && (text.charAt(pos + i) != display.charAt(i))) {
221 break;
222 } else if (i + 1 == numlen) {
223 m = num;
224 pos += numlen;
225 break;
226 }
227 }
228 }
229

Callers

nothing calls this directly

Calls 15

getInstanceMethod · 0.95
getDigitsMethod · 0.95
isDecimalMethod · 0.95
toNumeralMethod · 0.95
valueOfMethod · 0.95
parseMethod · 0.95
getValueMethod · 0.95
withLeapMethod · 0.95
getStdMonthsMethod · 0.80
getMethod · 0.65
containsMethod · 0.65
lengthMethod · 0.45

Tested by

no test coverage detected