Skip to content
This repository was archived by the owner on Jun 12, 2026. It is now read-only.

Fix html truncation#38

Open
epuzanov wants to merge 5 commits into
GSRS_DEVfrom
fixHtmlTruncation
Open

Fix html truncation#38
epuzanov wants to merge 5 commits into
GSRS_DEVfrom
fixHtmlTruncation

Conversation

@epuzanov

@epuzanov epuzanov commented Mar 8, 2021

Copy link
Copy Markdown
Contributor

This PR will fix truncate function in HTMLStringConverter class.The refPname property of SubstanceReference class will be truncated before storing in DB. The refPname property will be stored in RAW format which can be converted in Standard or HTML format (o.e getFormattedName for Alternative definitions). The getStandardName function added to Substance class an used for creation of _name JSON properties. The getName function of Substance class will return Display Name in RAW format. The Standard Name will be used as Page Title for Substance details page.

@dkatzel-ncats dkatzel-ncats 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.

I need to think about the refPname() changes a bit

public String truncate(String str, int maxBytes){
byte[] b = (str + " ").getBytes();
if(maxBytes >= b.length){
if(maxBytes >= str.length()){

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 think this will work. The previous code converts to bytes because some encodings take more than 1 byte (up to 4) for some characters. str.length is the number of characters which may be 1/4 the number of bytes in the worst case.

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'm using str.length() here because of str.charAt(i-1) in for loop.

}else{
lastComplete = false;
}
if (i > 0 && badLastChars.contains(str.charAt(i-1))) {

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.

This might be slower than the old way and looks like the old way was trying to count close tags? I assume this means we don't need that anymore

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.

check of close tags done by Tidy.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants