Skip to content

Commit e84dd7f

Browse files
committed
Fix for trailing , in picture
cb2xml was treating trailing ',' in a pictures as being part of the picture but it should be treated as white space i.e. the , in a picture like 99v99, should be ignored. This change fixes this
1 parent b98c2f4 commit e84dd7f

File tree

3 files changed

+75
-2
lines changed

3 files changed

+75
-2
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>net.sf</groupId>
77
<artifactId>cb2xml</artifactId>
8-
<version>1.01.08</version>
8+
<version>1.01.09</version>
99
<packaging>jar</packaging>
1010

1111
<name>cb2xml</name>

src/main/java/net/sf/cb2xml/analysis/PostProcess.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ void calculateLengths(Item curItem, String pictureString) {
183183
String ucCharacterString = pictureString.toUpperCase();
184184
for (int i = 0; i < pictureString.length(); i++) {
185185
char c = ucCharacterString.charAt(i);
186+
boolean lastChar = i == pictureString.length() -1;
186187
currSizeAdj = 0;
187188
switch (c) {
188189
case 'G':
@@ -247,10 +248,14 @@ void calculateLengths(Item curItem, String pictureString) {
247248
decimalCount += 1;
248249
}
249250
case '/':
250-
case ',':
251251
case 'X':
252252
displayLength++;
253253
break;
254+
case ',':
255+
if (! lastChar) {
256+
displayLength++;
257+
}
258+
break;
254259
case '(':
255260
int endParenPos = pictureString.indexOf(')', i + 1);
256261
int count = Integer.parseInt(pictureString.substring(i + 1,
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package net.sf.cb2xml.zTests.numeric;
2+
3+
import static org.junit.jupiter.api.Assertions.*;
4+
5+
import java.io.StringReader;
6+
import java.util.List;
7+
8+
import org.junit.jupiter.api.Test;
9+
10+
import net.sf.cb2xml.Cb2Xml3;
11+
import net.sf.cb2xml.def.IItem;
12+
13+
/**
14+
* This class ensures trailing commas in a picture clause are ignored
15+
* ie the comma in the following picture should be treated as white space
16+
* 05 CALC-SALES PIC 9(6)V99, VALUE 0
17+
*/
18+
class TestComma {
19+
20+
private static String commaCobolxx = ""
21+
+ " 01 CALC-COMMISSION-FIELDS.\n"
22+
+ " 05 EMP-TYPE PIC X.\n"
23+
+ " 05 CALC-SALES PIC 9(6)V99, VALUE 0.\n"
24+
+ " 05 CALC-COMMISSION PIC 9(5)V99 COMP-3 VALUE 0.";
25+
private static String commaCobol1 = ""
26+
+ " 01 CALC-COMMISSION-FIELDS.\n"
27+
+ " 05 CALC-SALES PIC 9(6)V99, VALUE 0.\n";
28+
@Test
29+
void test1() {
30+
List<? extends IItem> itemTree
31+
= Cb2Xml3.newBuilder(new StringReader(commaCobol1), "Commission")
32+
.asCobolItemTree().getChildItems();
33+
34+
// System.out.println(itemTree.size() + " " + itemTree.get(0).getDisplayLength() + " " + itemTree.get(0).getStorageLength());
35+
assertEquals(1, itemTree.size());
36+
IItem item = itemTree.get(0);
37+
assertEquals(8, item.getDisplayLength());
38+
assertEquals(8, item.getStorageLength());
39+
40+
assertEquals(1, itemTree.get(0).getChildItems().size());
41+
item = itemTree.get(0).getChildItems().get(0);
42+
assertEquals("CALC-SALES", item.getFieldName());
43+
assertEquals(8, item.getDisplayLength());
44+
assertEquals(8, item.getStorageLength());
45+
46+
}
47+
@Test
48+
void testXX() {
49+
List<? extends IItem> itemTree
50+
= Cb2Xml3.newBuilder(new StringReader(commaCobolxx), "Commission")
51+
.asCobolItemTree().getChildItems();
52+
53+
// System.out.println(itemTree.size() + " " + itemTree.get(0).getDisplayLength() + " " + itemTree.get(0).getStorageLength());
54+
assertEquals(1, itemTree.size());
55+
56+
IItem item = itemTree.get(0);
57+
assertEquals(16, item.getDisplayLength());
58+
assertEquals(13, item.getStorageLength());
59+
60+
assertEquals(3, itemTree.get(0).getChildItems().size());
61+
item = itemTree.get(0).getChildItems().get(1);
62+
assertEquals("CALC-SALES", item.getFieldName());
63+
assertEquals(8, item.getDisplayLength());
64+
assertEquals(8, item.getStorageLength());
65+
66+
}
67+
68+
}

0 commit comments

Comments
 (0)