Skip to content

Commit 01971b0

Browse files
committed
Cleanup
1 parent f050ad7 commit 01971b0

File tree

2 files changed

+7
-33
lines changed

2 files changed

+7
-33
lines changed

src/main/java/build/buf/protovalidate/Ipv4.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,7 @@ boolean addressPrefix() {
8080
private boolean prefixLength() {
8181
int start = this.index;
8282

83-
while (true) {
84-
if (this.index >= this.str.length() || !this.digit()) {
85-
break;
86-
}
87-
83+
while (this.index < this.str.length() && this.digit()) {
8884
if (this.index - start > 2) {
8985
// max prefix-length is 32 bits, so anything more than 2 digits is invalid
9086
return false;
@@ -138,11 +134,7 @@ private boolean addressPart() {
138134
private boolean decOctet() {
139135
int start = this.index;
140136

141-
while (true) {
142-
if (this.index >= this.str.length() || !this.digit()) {
143-
break;
144-
}
145-
137+
while (this.index < this.str.length() && this.digit()) {
146138
if (this.index - start > 3) {
147139
// decimal octet can be three characters at most
148140
return false;

src/main/java/build/buf/protovalidate/Ipv6.java

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,7 @@ private long[] getBits() {
6262

6363
// handle double colon, fill pieces with 0
6464
if (this.doubleColonSeen) {
65-
while (true) {
66-
if (p16.size() >= 8) {
67-
break;
68-
}
65+
while (p16.size() < 8) {
6966
p16.add(this.doubleColonAt, 0x00000000);
7067
}
7168
}
@@ -128,10 +125,7 @@ boolean addressPrefix() {
128125
private boolean prefixLength() {
129126
int start = this.index;
130127

131-
while (true) {
132-
if (this.index >= this.str.length() || !this.digit()) {
133-
break;
134-
}
128+
while (this.index < this.str.length() && this.digit()) {
135129
if (this.index - start > 3) {
136130
return false;
137131
}
@@ -167,10 +161,7 @@ private boolean prefixLength() {
167161

168162
// Stores dotted notation for right-most 32 bits in `dottedRaw` / `dottedAddr` if found.
169163
private boolean addressPart() {
170-
while (true) {
171-
if (this.index >= this.str.length()) {
172-
break;
173-
}
164+
while (this.index < this.str.length()) {
174165
// dotted notation for right-most 32 bits, e.g. 0:0:0:0:0:ffff:192.1.56.10
175166
if ((this.doubleColonSeen || this.pieces.size() == 6) && this.dotted()) {
176167
Ipv4 dotted = new Ipv4(this.dottedRaw);
@@ -249,12 +240,7 @@ private boolean dotted() {
249240

250241
this.dottedRaw = "";
251242

252-
while (true) {
253-
if (this.index < this.str.length() && (this.digit() || this.take('.'))) {
254-
continue;
255-
}
256-
break;
257-
}
243+
while (this.index < this.str.length() && (this.digit() || this.take('.'))) {}
258244

259245
if (this.index - start >= 7) {
260246
this.dottedRaw = this.str.substring(start, this.index);
@@ -279,11 +265,7 @@ private boolean dotted() {
279265
private boolean h16() {
280266
int start = this.index;
281267

282-
while (true) {
283-
if (this.index >= this.str.length() || !this.hexDig()) {
284-
break;
285-
}
286-
}
268+
while (this.index < this.str.length() && this.hexDig()) {}
287269

288270
String str = this.str.substring(start, this.index);
289271

0 commit comments

Comments
 (0)