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

Method parse

base/src/main/java/net/time4j/calendar/Nengo.java:1450–1605  ·  view source on GitHub ↗
(
            CharSequence text,
            ParsePosition pp,
            AttributeQuery attributes
        )

Source from the content-addressed store, hash-verified

1448 }
1449
1450 @Override
1451 public Nengo parse(
1452 CharSequence text,
1453 ParsePosition pp,
1454 AttributeQuery attributes
1455 ) {
1456
1457 Locale locale = attributes.get(Attributes.LANGUAGE, Locale.ROOT);
1458 TextWidth width = attributes.get(Attributes.TEXT_WIDTH, TextWidth.WIDE);
1459 Map<String, String> textForms = CalendarText.getInstance("japanese", locale).getTextForms();
1460 int offset = pp.getIndex();
1461
1462 if (offset >= text.length()) {
1463 pp.setErrorIndex(offset);
1464 return null;
1465 }
1466
1467 String query = (locale.getLanguage().equals("ru") ? capitalize(text, offset) : hepburn(text, offset));
1468 Nengo candidate = null;
1469 int len = 0;
1470
1471 for (int i = 0; i < MODERN_KEYS.length; i++) {
1472 String key = MODERN_KEYS[i];
1473 if (width == TextWidth.NARROW) {
1474 key = key + "_n";
1475 }
1476 String test = textForms.get(key);
1477 if (query.startsWith(test)) {
1478 candidate = MODERN_NENGOS[i];
1479 len = test.length();
1480 if ((width != TextWidth.NARROW) && (candidate != SHOWA)) { // Shōwa is ambivalent!
1481 pp.setIndex(offset + len);
1482 return candidate;
1483 } else {
1484 break;
1485 }
1486 }
1487 }
1488
1489 if (query.length() < 2) { // NARROW
1490 if (candidate != null) {
1491 pp.setIndex(offset + 1);
1492 }
1493 return candidate;
1494 }
1495
1496 String prefix = null;
1497 int extra = 0;
1498 List<Nengo> candidates = Collections.emptyList();
1499
1500 switch (locale.getLanguage()) {
1501 case "ja": {
1502 int end = ((query.length() >= 4) ? 4 : 2);
1503 String test = query.substring(0, end);
1504 Nengo nengo = KANJI_TO_NENGO.get(test);
1505 if ((nengo == null) && (end == 4)) {
1506 test = query.substring(0, 2);
1507 nengo = KANJI_TO_NENGO.get(test);

Callers

nothing calls this directly

Calls 15

getInstanceMethod · 0.95
matchesMethod · 0.95
capitalizeMethod · 0.80
hepburnMethod · 0.80
getMethod · 0.65
containsMethod · 0.65
getTextFormsMethod · 0.45
getIndexMethod · 0.45
lengthMethod · 0.45
equalsMethod · 0.45
longestPrefixOfMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected