Skip to content

RTFchars fix#2097

Merged
lenhard merged 17 commits into
JabRef:masterfrom
mairdl:RTFCharsFix
Oct 5, 2016
Merged

RTFchars fix#2097
lenhard merged 17 commits into
JabRef:masterfrom
mairdl:RTFCharsFix

Conversation

@mairdl

@mairdl mairdl commented Sep 29, 2016

Copy link
Copy Markdown
Contributor

RTFcharsTest had some ignored test. So I looked into it and made the necessery changes. I added some of the tested but missing special characters. I also modified the expected and actual vaulues where needed (because to my understanding of this topic, some values were wrong). Since I am not 100% sure if everything is correct, comments are appreciated.

Also I added "translator" which takes the unicode and transforms it back into its root letter.
E.g. é - > \\u233e

My final change is that I removed duplicate keys inside the RTFCharMap.

  • Change in CHANGELOG.md described
  • Tests work for changes
  • internal qs
  • double check mappings

@mairdl

mairdl commented Sep 29, 2016

Copy link
Copy Markdown
Contributor Author

looks like i need some more testscases for my changes

@boceckts boceckts left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only minor comments from my side.

}
}
//if( <= c && c <= )
// return ""; No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove out commented code.

return new StringInt(format(res), part.length());
}

private String transformSpecialCharacter(long c) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a javadoc comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes sure

return "ss";
if(161 ==c)
return "!";
return "?";

@boceckts boceckts Oct 1, 2016

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the multiple return statements and no brackets. Please use a variable which gets returned once in the end of the method and use if else with brackets.

@mairdl mairdl Oct 1, 2016

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the way it is implemented now, has a better performance 👍

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can leave the return statements but please add the brackets.

@Siedlerchr

Copy link
Copy Markdown
Member

What about a switch Statement with case?
Am 01.10.2016 2:20 nachm. schrieb "Tobias Boceck" <notifications@github.com

:

@boceckts commented on this pull request.

Only minor comments from my side.

In src/main/java/net/sf/jabref/logic/layout/format/RTFChars.java
#2097 (review):

}
+//if( <= c && c <= )
+// return "";

Remove out commented code.

In src/main/java/net/sf/jabref/logic/layout/format/RTFChars.java
#2097 (review):

@@ -199,4 +199,100 @@ private StringInt getPart(String text, int i, boolean commandNestedInBraces) {
// the wrong "}" at the end is removed by "format(res)"
return new StringInt(format(res), part.length());
}
+

  • private String transformSpecialCharacter(long c) {

Please add a javadoc comment.

In src/main/java/net/sf/jabref/logic/layout/format/RTFChars.java
#2097 (review):

  •        return "z";
    
  •    if(198 == c)
    
  •        return "AE";
    
  •    if(230 == c)
    
  •        return "ae";
    
  •    if(338 == c)
    
  •        return "OE";
    
  •    if(339 == c)
    
  •        return "oe";
    
  •    if(222 == c)
    
  •        return "TH";
    
  •    if(223 == c)
    
  •        return "ss";
    
  •    if(161 ==c)
    
  •        return "!";
    
  •    return "?";
    

I don't like the multiple return statements and no brackets. Please use a
variable which gets returned once in the end of the method and use if else
with brackets.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#2097 (review),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AATi5O3n-NXgNbOgUcLHNA6IpTMdkdKCks5qvlASgaJpZM4KKFcO
.

@mairdl

mairdl commented Oct 1, 2016

Copy link
Copy Markdown
Contributor Author

I also thought about switch case, but i came to the conclusion it gets way to big 🎅

@tobiasdiez tobiasdiez left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't really judge the correctness of your changes (I have no experience with the RTF stuff), thus only a few general comments about the code.

return "ss";
if(161 ==c)
return "!";
return "?";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can leave the return statements but please add the brackets.

return "!";
return "?";
}
} No newline at end of file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't remove newlines at end.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add the brackets and the newline.

put("?i", "\\'ed");
put("?o", "\\'f3");
put("?u", "\\'fa");
put("'a", "\\'e1");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please explain the reason for this change (? -> ' )

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes sure, later in the RTFCharMap you would find "'a" assigned with unicode, so I thought why not just map it to the RTF value if it already exists.

// Use UNICODE characters for RTF-Chars which can not be found in the
// standard codepage

put("`A", "\\u192A"); // "Agrave"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you removed some of these mappings?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some keys got 2 values assigned, so I removed the double assignement. If a key got an RTF value I removed the unicode value.

Assert.assertEquals("R\\u233eflexions sur le timing de la quantit\\u233e {\\u230ae} should be \\u230ae",
formatter.format("Réflexions sur le timing de la quantité {\\ae} should be æ"));

Assert.assertEquals("h\\'e1ll{\\u339oe}", formatter.format("h\\'all{\\oe}"));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please only one assert per test method.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some test methods inside this test class have lots of assertions for single characters, can I leave it like that? I will split the longer ones like you recommend.

Assert.assertEquals("R\\u233eflexions sur le timing de la quantit\\u233e {\\u230ae} should be \\u230ae",
formatter.format("Réflexions sur le timing de la quantité {\\ae} should be æ"));

Assert.assertEquals("h\\'e1ll{\\u339oe}", formatter.format("h\\'all{\\oe}"));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please only one assert per test method.

@boceckts boceckts added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Oct 2, 2016
@boceckts boceckts changed the title [WIP] RTFchars fix RTFchars fix Oct 2, 2016
@lenhard

lenhard commented Oct 3, 2016

Copy link
Copy Markdown
Member

Code-wise this looks fine for me. Though I'll admit that I have not looked up the mapping table and would trust you on this.

I have one more question regarding code style that is not your fault, but could you improve it anyway? I do not like that RtfCharMap extends HashMap<String><String>, which is also completely unecessary. Through this, a malicious user could compromise the structure of the table itself. It would be better if RtfCharMap just used an internal HashMap. All you would need to offer to the outside is a get methods, because nothing more is used atm. If you add an internal private put method, you can also avoid rewriting the code.

@mairdl

mairdl commented Oct 3, 2016

Copy link
Copy Markdown
Contributor Author

I looked the mappings up and the ones in JabRef seemed to be fine, so I used them. I will double check my code at the end to be 100% sure the mappings are fine. Also I will improve the code quality like @lenhard mentioned.

@lenhard

lenhard commented Oct 4, 2016

Copy link
Copy Markdown
Member

This looks done, or is there something left? @mairdl If so, please merge master into your branch and we are ready to go.

@mairdl

mairdl commented Oct 4, 2016

Copy link
Copy Markdown
Contributor Author

I'm on it.

@mairdl

mairdl commented Oct 5, 2016

Copy link
Copy Markdown
Contributor Author

So can it be merged now?

@lenhard

lenhard commented Oct 5, 2016

Copy link
Copy Markdown
Member

Yes, thanks for your contribution!

@lenhard lenhard merged commit be390e4 into JabRef:master Oct 5, 2016
Siedlerchr added a commit that referenced this pull request Oct 9, 2016
* upstream/master: (102 commits)
  Removed unused test code (#2140)
  Fix main table bug when creating a duplicate (#2135)
  Remove explicit author and add SPDX-License-Identifier
  Remove GPL from README.md and CONTRIBUTING.md
  fix preview update (#2125)
  Remove some UnicodeToLatex uses (#2132)
  Fix mixup in french/farsi localization
  FetcherException should extend JabRefException
  Fix exception when opening preference dialog (#2127)
  Unify ParserException and ParseException (#2124)
  Small refactoring in Importer package (#2053)
  Implement Datepicker "none"-button (#2122)
  revert change from 816d30c
  Change title/tooltip of source panel in biblatex mode (#2120)
  Refactoring: completey typed metadata and add detailed travis output (#2112)
  RTFchars fix (#2097)
  Fix NPE in Medline fetcher on missing ISSN (#2113)
  Ctrl-s parsing error message (#2114)
  Fix bad web search error messages (#2034)
  parse error freeze (#2106)
  ...

# Conflicts:
#	src/main/java/net/sf/jabref/collab/FileUpdateMonitor.java
#	src/main/java/net/sf/jabref/gui/externalfiles/DownloadExternalFile.java
#	src/main/java/net/sf/jabref/gui/externalfiles/DroppedFileHandler.java
#	src/main/java/net/sf/jabref/gui/externalfiles/MoveFileAction.java
#	src/main/java/net/sf/jabref/logic/cleanup/RenamePdfCleanup.java
#	src/main/java/net/sf/jabref/logic/exporter/FileSaveSession.java
#	src/main/java/net/sf/jabref/logic/util/io/FileUtil.java
#	src/main/java/net/sf/jabref/preferences/JabRefPreferences.java
@mairdl mairdl deleted the RTFCharsFix branch October 11, 2016 12:41
zesaro pushed a commit to zesaro/jabref that referenced this pull request Nov 22, 2016
* Fix RTFChars

* Formatting, correcting wrong expected values

* add missing keys and clean up

* Improve formatting, fix minor issue

* Rework tests to fit, remove @ignore

* Remove duplicate keys

* Make test fit new keys, add new test for RTFChars

* Add additional complicated sentence

* add a javadoc, remove unneeded lines

* Add brackets to if statements

* Split asserts up

* use internal HashMap, remove extends HashMap

* remove unneeded values

* Add changes to CHANGELOG.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants