AndHow! Java Configuration .
  • AndHow!
  • Live-Code Quickstart
  • Simple Usage Examples
  • User Guide
    • Key Concepts
    • AndHow Properties
    • Loaders & Load Order
    • Testing
    • AndHow Initialization
    • Configuring AndHow
    • Whitespace Handling
    • Integration and Exports
    • Changing the Load Order
    • Java9 and Above
    • Best Practices
  • Developer Guide
    • How to Contribute
    • First Checkout with Git
    • Project Branching Structure
    • New Workstation Setup
    • Background
    • Framework Testing
    • Conventions
    • Release Plan
    • HowTo Release
    • Troubleshooting
    • References
  • Help / Questions
  • Release Notes
    • Release 0.4.2
  • FAQs
  • Other
    • JUnit Extension Registration
Powered by GitBook
On this page
  • Non-String Property Trimming
  • String Property Trimming

Was this helpful?

  1. User Guide

Whitespace Handling

AndHow generally removes leading and trailing whitespace from values as they are loaded, and each Property has a Trimmer instance to do the trimming.

Depending on where values are loaded from (i.e. which loader is used) trimming of String type values maybe enabled or disabled. For instance, if a String value is loaded from JNDI (the StdJndiLoader) or as a fixed value in code (StdFixedValueLoader), no trimming is done for String values because it is assumed that the value is in its final form. Non-String values are always trimmed as they are loaded.

Non-String Property Trimming

The TrimToNullTrimmer is used by most non-text properties and simply removes all whitespace on either end of a value. If the result is a zero length string, it becomes null.

String Property Trimming

StrProp, and likely most other text based properties, use a special QuotedSpacePreservingTrimmer (QSPT). The QSPT first trims to null, then, if the remaining text begins and ends with double quotes, those quotes are removed and the string inside the quotes, including whitespace, is preserved as the actual value.

Here are a few examples of the QSPT trimming behavior, using dots (●)to represent whitespace and -> to separate the raw value on the left from the trimmed value on the right:

Raw Value
QSPT Trimmed Value
Notes

●

[null]

An all whitespace raw value is trimmed to null

●●●abc●●●

abc

whitespace on either side of text removed

"●abc●"

●abc●

Quotes are removed and all characters inside preserved

●"●abc●"●

●abc●

same result - whitespace outside the quotes is removed

●a "word" here●

a "word" here

No special quote handling here - there is text outside the quotes

●"●a "word" here●"●

●a "word" here●

After trimming outer whitespace, leading and trailing double quotes were found

●""●

[empty string]

Using quotes, it is possible to assign an empty string

The trimmer for a Property can be changed if a different behaviour is needed:

StrProp TRIM_ME_TO_NULL =
    StrProp.builder.trimmer(TrimToNullTrimmer.instance()).build();
PreviousConfiguring AndHowNextIntegration and Exports

Last updated 3 years ago

Was this helpful?