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

Method parse

base/src/main/java/net/time4j/range/YearParser.java:42–165  ·  view source on GitHub ↗
(
        CharSequence text,
        ParseLog status,
        AttributeQuery attributes
    )

Source from the content-addressed store, hash-verified

40 //~ Methoden ----------------------------------------------------------
41
42 @Override
43 public Integer parse(
44 CharSequence text,
45 ParseLog status,
46 AttributeQuery attributes
47 ) {
48
49 Leniency leniency = attributes.get(Attributes.LENIENCY, Leniency.SMART);
50
51 int effectiveMin = 1;
52 int effectiveMax = 9;
53
54 if (!leniency.isLax()) {
55 effectiveMin = 4;
56 }
57
58 int len = text.length();
59 int start = status.getPosition();
60 int pos = start;
61
62 int protectedChars =
63 attributes.get(Attributes.PROTECTED_CHARACTERS, 0).intValue();
64
65 if (protectedChars > 0) {
66 len -= protectedChars;
67 }
68
69 if (pos >= len) {
70 status.setError(start, "Missing digits for: " + this.name());
71 status.setWarning();
72 return null;
73 }
74
75 boolean negative = false;
76 char sign = text.charAt(pos);
77
78 if (
79 (sign == '-')
80 || (sign == '+')
81 ) {
82 negative = (sign == '-');
83 pos++;
84 start++;
85 }
86
87 if (pos >= len) {
88 status.setError(start, "Missing digits for: " + this.name());
89 return null;
90 }
91
92 int minPos = pos + effectiveMin;
93 int maxPos = Math.min(len, pos + effectiveMax);
94 int total = 0;
95 boolean first = true;
96
97 while (pos < maxPos) {
98 int digit = text.charAt(pos) - '0';
99

Callers

nothing calls this directly

Calls 11

isLaxMethod · 0.95
isStrictMethod · 0.95
setErrorMethod · 0.80
setWarningMethod · 0.80
getMethod · 0.65
nameMethod · 0.65
lengthMethod · 0.45
getPositionMethod · 0.45
minMethod · 0.45
setPositionMethod · 0.45
valueOfMethod · 0.45

Tested by

no test coverage detected