-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Normalize pages formatter not replacing dashes #7243
Merged
Merged
Changes from 9 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
afc0ff9
Fix Normalize pages fornatter not replacing dashes
Siedlerchr a127881
add to existing regexes
Siedlerchr 55be2f8
Simplify NormalizePagesFormatter and add UnprotectTermsFormatter
koppor edd430c
Merge branch 'master' into fixNormalizePagesFormatter
koppor ed1f74c
Fix checkstyle
koppor 0ac8c19
fix failing test and checkstlye
Siedlerchr 3d33430
try to fix l10n
Siedlerchr 428aea1
fix l10n again
Siedlerchr 361cb5d
hopefully last l10n fix
Siedlerchr 1b7c150
Add new test cases
koppor 76329c0
Adapt localization
koppor 37e4d0c
Merge branch 'fixNormalizePagesFormatter' of github.com:JabRef/jabref…
koppor c536b38
Remove obsolete translation
koppor 61567f8
Handle more special cases (and also add examples to tests)
koppor 93d7028
Add missing tests
koppor 05c01ed
Merge branch 'master' into fixNormalizePagesFormatter
koppor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/main/java/org/jabref/logic/formatter/casechanger/UnprotectTermsFormatter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.jabref.logic.formatter.casechanger; | ||
|
||
import java.util.Objects; | ||
|
||
import org.jabref.logic.cleanup.Formatter; | ||
import org.jabref.logic.l10n.Localization; | ||
|
||
/** | ||
* Remove {} brackets around words | ||
* | ||
* Related formatter: {@link ProtectTermsFormatter} | ||
*/ | ||
public class UnprotectTermsFormatter extends Formatter { | ||
|
||
@Override | ||
public String format(String text) { | ||
// similar implementation at {@link org.jabref.logic.formatter.bibtexfields.RemoveBracesFormatter.hasNegativeBraceCount} | ||
Objects.requireNonNull(text); | ||
if (text.isEmpty()) { | ||
return text; | ||
} | ||
StringBuilder result = new StringBuilder(); | ||
int level = 0; | ||
int index = 0; | ||
do { | ||
char charAtIndex = text.charAt(index); | ||
if (charAtIndex == '{') { | ||
level++; | ||
} else if (charAtIndex == '}') { | ||
level--; | ||
} else { | ||
result.append(charAtIndex); | ||
} | ||
index++; | ||
} while (index < text.length() && level >= 0); | ||
if (level != 0) { | ||
// in case of unbalanced braces, the original text is returned unmodified | ||
return text; | ||
} | ||
return result.toString(); | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return Localization.lang( | ||
"Removes all {} brackets around words."); | ||
koppor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
@Override | ||
public String getExampleInput() { | ||
return "{In} {CDMA}"; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return Localization.lang("Unprotect terms"); | ||
} | ||
|
||
@Override | ||
public String getKey() { | ||
return "unprotect_terms"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/test/java/org/jabref/logic/formatter/casechanger/UnprotectTermsFormatterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.jabref.logic.formatter.casechanger; | ||
|
||
import java.io.IOException; | ||
import java.util.stream.Stream; | ||
|
||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
/** | ||
* Tests in addition to the general tests from {@link org.jabref.logic.formatter.FormatterTest} | ||
*/ | ||
public class UnprotectTermsFormatterTest { | ||
|
||
private UnprotectTermsFormatter formatter = new UnprotectTermsFormatter(); | ||
|
||
private static Stream<Arguments> terms() throws IOException { | ||
return Stream.of( | ||
Arguments.of("VLSI", "{VLSI}"), | ||
Arguments.of("VLsI", "VLsI"), | ||
Arguments.of("VLSI", "VLSI"), | ||
Arguments.of("VLSI VLSI", "{VLSI} {VLSI}"), | ||
Arguments.of("BPEL", "{BPEL}"), | ||
Arguments.of("3GPP 3G", "{3GPP} {3G}"), | ||
Arguments.of("{A} and {B}}", "{A} and {B}}"), | ||
Arguments.of("Testing BPEL Engine Performance: A Survey", "{Testing BPEL Engine Performance: A Survey}"), | ||
Arguments.of("Testing BPEL Engine Performance: A Survey", "Testing {BPEL} Engine Performance: A Survey"), | ||
Arguments.of("Testing BPEL Engine Performance: A Survey", "{Testing {BPEL} Engine Performance: A Survey}"), | ||
Arguments.of("In CDMA", new UnprotectTermsFormatter().getExampleInput())); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("terms") | ||
public void test(String expected, String toFormat) { | ||
assertEquals(expected, formatter.format(toFormat)); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also not sure if
I-X
is correct orI--X
for roman page numbers.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Result of test-driven-development 😇. I will think more about it now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This reads more as a page range, too. Roman 9 is written IX (and not I-X), isn't it?