Skip to content
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

Trimming of input string upon conversion to Class, boolean or numeric types #181

Closed
wants to merge 4 commits into from

Conversation

yrodiere
Copy link
Contributor

@yrodiere yrodiere commented Nov 8, 2019

As discussed here.

I did not add trimming to the built-in converters for String, Character, or InetAddress, since that seemed dangerous.

I did not add any kind of warning when leading/trailing whitespaces are detected. Let me know if you want that, too.

Note that some types were already handling leading/trailing whitespaces correctly (Double.parse and Float.parse trim the string before parsing, in particular), but most did not (Integer, ...).

Please do not merge yet as @dmlloyd is preparing a large pull request. Just let me know when his PR is merged, I will rebase mine.

this.function = function;
}

public T convert(final String value) {
return function.convert(value);
final String cleanValue;
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe use a ternary operator instead? Then a new variable doesn't need to be allocated

@kenfinnigan
Copy link
Contributor

@dmlloyd @jmesnil can you both take a look at this too, thanks

}

Object writeReplace() {
return new Ser(id);
}
}

enum StringCleanup {
Copy link
Contributor

Choose a reason for hiding this comment

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

I can see that using an Enum vs a Boolean means we can easily expand the behavior in the future.

But I wonder whether we would need anything here beyond "trim" and "don't trim". Can you think of any string manipulation other than trim we might need in the future? If not, I'd lean towards just using a boolean

Copy link
Contributor

Choose a reason for hiding this comment

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

It might even make more sense to wrap the converter with a TrimmingConverter which could be reused.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's a cool idea, then it can be easily added/removed from converters by us, and used separately by others if desired

Copy link
Contributor

Choose a reason for hiding this comment

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

It overlaps with another change I was doing so I'll send a single PR which supercedes this one. /cc @yrodiere

Copy link
Contributor

Choose a reason for hiding this comment

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

Opened #185. I borrowed a commit from this PR.

@yrodiere
Copy link
Contributor Author

Superseded by #185, which fixes everything I was trying to fix. Closing.

@yrodiere yrodiere closed this Nov 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants