Skip to content

Commit 63e7a98

Browse files
committed
Rewrite and test layout formatter
1 parent 88ec354 commit 63e7a98

File tree

5 files changed

+69
-151
lines changed

5 files changed

+69
-151
lines changed
Lines changed: 10 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,25 @@
1-
/* Copyright (C) 2003-2011 JabRef contributors.
2-
This program is free software; you can redistribute it and/or modify
3-
it under the terms of the GNU General Public License as published by
4-
the Free Software Foundation; either version 2 of the License, or
5-
(at your option) any later version.
6-
7-
This program is distributed in the hope that it will be useful,
8-
but WITHOUT ANY WARRANTY; without even the implied warranty of
9-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10-
GNU General Public License for more details.
11-
12-
You should have received a copy of the GNU General Public License along
13-
with this program; if not, write to the Free Software Foundation, Inc.,
14-
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15-
*/
16-
///////////////////////////////////////////////////////////////////////////////
17-
// Filename: $RCSfile$
18-
// Purpose: Atom representation.
19-
// Language: Java
20-
// Compiler: JDK 1.4
21-
// Authors: Joerg K. Wegner
22-
// Version: $Revision$
23-
// $Date$
24-
// $Author$
25-
//
26-
// Copyright (c) Dept. Computer Architecture, University of Tuebingen, Germany
27-
//
28-
// This program is free software; you can redistribute it and/or modify
29-
// it under the terms of the GNU General Public License as published by
30-
// the Free Software Foundation version 2 of the License.
31-
//
32-
// This program is distributed in the hope that it will be useful,
33-
// but WITHOUT ANY WARRANTY; without even the implied warranty of
34-
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35-
// GNU General Public License for more details.
36-
///////////////////////////////////////////////////////////////////////////////
37-
381
package net.sf.jabref.exporter.layout.format;
392

403
import net.sf.jabref.exporter.layout.LayoutFormatter;
414

425
/**
436
* Remove brackets formatter.
7+
*
8+
* <example>
9+
* "{Stefan Kolb}" -> "Stefan Kolb"
10+
* </example>
4411
*/
4512
public class RemoveBrackets implements LayoutFormatter
4613
{
47-
4814
@Override
49-
public String format(String fieldText)
50-
{
51-
String fieldEntry = fieldText;
52-
StringBuilder sb = new StringBuilder(fieldEntry.length());
15+
public String format(String fieldText) {
16+
StringBuilder builder = new StringBuilder(fieldText.length());
5317

54-
for (int i = 0; i < fieldEntry.length(); i++)
55-
{
56-
//System.out.print(fieldEntry.charAt(i));
57-
if (fieldEntry.charAt(i) != '{' && fieldEntry.charAt(i) != '}')
58-
{
59-
//System.out.print(fieldEntry.charAt(i));
60-
sb.append(fieldEntry.charAt(i));
18+
for (char c: fieldText.toCharArray()) {
19+
if (c != '{' && c != '}') {
20+
builder.append(c);
6121
}
6222
}
63-
64-
fieldEntry = sb.toString();
65-
return fieldEntry;
23+
return builder.toString();
6624
}
6725
}
Lines changed: 10 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,22 @@
1-
/* Copyright (C) 2003-2011 JabRef contributors.
2-
This program is free software; you can redistribute it and/or modify
3-
it under the terms of the GNU General Public License as published by
4-
the Free Software Foundation; either version 2 of the License, or
5-
(at your option) any later version.
6-
7-
This program is distributed in the hope that it will be useful,
8-
but WITHOUT ANY WARRANTY; without even the implied warranty of
9-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10-
GNU General Public License for more details.
11-
12-
You should have received a copy of the GNU General Public License along
13-
with this program; if not, write to the Free Software Foundation, Inc.,
14-
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15-
*/
16-
///////////////////////////////////////////////////////////////////////////////
17-
// Filename: $RCSfile$
18-
// Purpose: Atom representation.
19-
// Language: Java
20-
// Compiler: JDK 1.4
21-
// Authors: Joerg K. Wegner
22-
// Version: $Revision$
23-
// $Date$
24-
// $Author$
25-
//
26-
// Copyright (c) Dept. Computer Architecture, University of Tuebingen, Germany
27-
//
28-
// This program is free software; you can redistribute it and/or modify
29-
// it under the terms of the GNU General Public License as published by
30-
// the Free Software Foundation version 2 of the License.
31-
//
32-
// This program is distributed in the hope that it will be useful,
33-
// but WITHOUT ANY WARRANTY; without even the implied warranty of
34-
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35-
// GNU General Public License for more details.
36-
///////////////////////////////////////////////////////////////////////////////
37-
381
package net.sf.jabref.exporter.layout.format;
392

403
import net.sf.jabref.exporter.layout.LayoutFormatter;
414

425
/**
436
* Remove brackets formatter.
447
*/
45-
public class RemoveBracketsAddComma implements LayoutFormatter
46-
{
47-
8+
public class RemoveBracketsAddComma implements LayoutFormatter {
489
@Override
49-
public String format(String fieldText)
50-
{
51-
String fieldEntry = fieldText;
52-
StringBuilder sb = new StringBuilder(fieldEntry.length());
53-
54-
for (int i = 0; i < fieldEntry.length(); i++)
55-
{
56-
//System.out.print(fieldEntry.charAt(i));
57-
if (fieldEntry.charAt(i) != '{' && fieldEntry.charAt(i) != '}')
58-
{
59-
//System.out.print(fieldEntry.charAt(i));
60-
sb.append(fieldEntry.charAt(i));
61-
}
62-
if (fieldEntry.charAt(i) == '}')
63-
{
64-
sb.append(',');
10+
public String format(String fieldText) {
11+
StringBuilder builder = new StringBuilder(fieldText.length());
12+
13+
for (char c: fieldText.toCharArray()) {
14+
if (c != '{' && c != '}') {
15+
builder.append(c);
16+
} else if (c == '}') {
17+
builder.append(',');
6518
}
6619
}
67-
68-
fieldEntry = sb.toString();
69-
return fieldEntry;
20+
return builder.toString();
7021
}
7122
}
Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,3 @@
1-
/* Copyright (C) 2003-2011 JabRef contributors.
2-
This program is free software; you can redistribute it and/or modify
3-
it under the terms of the GNU General Public License as published by
4-
the Free Software Foundation; either version 2 of the License, or
5-
(at your option) any later version.
6-
7-
This program is distributed in the hope that it will be useful,
8-
but WITHOUT ANY WARRANTY; without even the implied warranty of
9-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10-
GNU General Public License for more details.
11-
12-
You should have received a copy of the GNU General Public License along
13-
with this program; if not, write to the Free Software Foundation, Inc.,
14-
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15-
*/
16-
///////////////////////////////////////////////////////////////////////////////
17-
// Filename: $RCSfile$
18-
// Purpose: Atom representation.
19-
// Language: Java
20-
// Compiler: JDK 1.4
21-
// Authors: Joerg K. Wegner
22-
// Version: $Revision$
23-
// $Date$
24-
// $Author$
25-
//
26-
// Copyright (c) Dept. Computer Architecture, University of Tuebingen, Germany
27-
//
28-
// This program is free software; you can redistribute it and/or modify
29-
// it under the terms of the GNU General Public License as published by
30-
// the Free Software Foundation version 2 of the License.
31-
//
32-
// This program is distributed in the hope that it will be useful,
33-
// but WITHOUT ANY WARRANTY; without even the implied warranty of
34-
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35-
// GNU General Public License for more details.
36-
///////////////////////////////////////////////////////////////////////////////
37-
381
package net.sf.jabref.exporter.layout.format;
392

403
import net.sf.jabref.exporter.layout.LayoutFormatter;
@@ -45,10 +8,8 @@
458
* Useful for formatting Latex code.
469
*/
4710
public class RemoveTilde implements LayoutFormatter {
48-
4911
@Override
5012
public String format(String fieldText) {
51-
5213
StringBuilder result = new StringBuilder(fieldText.length());
5314

5415
char[] c = fieldText.toCharArray();
@@ -66,7 +27,6 @@ public String format(String fieldText) {
6627
result.append(' ');
6728
}
6829
}
69-
7030
return result.toString();
7131
}
7232
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package net.sf.jabref.export.layout.format;
2+
3+
import junit.framework.Assert;
4+
import net.sf.jabref.export.layout.LayoutFormatter;
5+
import org.junit.Before;
6+
import org.junit.Test;
7+
8+
import static org.junit.Assert.*;
9+
10+
public class RemoveBracketsAddCommaTest {
11+
private LayoutFormatter formatter;
12+
13+
@Before
14+
public void setup() {
15+
formatter = new RemoveBracketsAddComma();
16+
}
17+
18+
@Test
19+
public void testFormat() throws Exception {
20+
Assert.assertEquals("some text,", formatter.format("{some text}"));
21+
Assert.assertEquals("some text", formatter.format("{some text"));
22+
Assert.assertEquals("some text,", formatter.format("some text}"));
23+
}
24+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package net.sf.jabref.export.layout.format;
2+
3+
import junit.framework.Assert;
4+
import net.sf.jabref.export.layout.LayoutFormatter;
5+
import org.junit.Before;
6+
import org.junit.Test;
7+
8+
import static org.junit.Assert.*;
9+
10+
public class RemoveBracketsTest {
11+
private LayoutFormatter formatter;
12+
13+
@Before
14+
public void setup() {
15+
formatter = new RemoveBrackets();
16+
}
17+
18+
@Test
19+
public void testFormat() throws Exception {
20+
Assert.assertEquals("some text", formatter.format("{some text}"));
21+
Assert.assertEquals("some text", formatter.format("{some text"));
22+
Assert.assertEquals("some text", formatter.format("some text}"));
23+
Assert.assertEquals("\\some text\\", formatter.format("\\{some text\\}"));
24+
}
25+
}

0 commit comments

Comments
 (0)