Comments (2)
I found the following nice explanation of [The Java Properties File Format] in addition to java.util.Properties.load(java.io.Reader) :
The Java Properties File Format
A Java style properties file contains key value pairs (properties) in a file with ISO-8859-1 encoding (code page 28591). The file usually has a “.properties” file extension and consists of a series of lines (terminated by CRLF or CR or LF) each a key value pair, a comment or a blank line.
Leading whitespace (spaces, tabs ‘\t’, form feeds ‘\f’) are ignored at the start of any line – and a line that is empty or contains only whitespace is treated as blank and ignored.
A line where the first non-whitespace character is a ‘#’ or ‘!’ is a comment line and the rest of the line is ignored.
If the first non-whitespace character is not ‘#’ or ‘!’ then it is the start of a key. A key is all the characters up to the first whitespace or a key/value separator (‘=’ or ‘:’). The separator is optional. Any whitespace after the key or after the separator (if present) is ignored.
The first non-whitespace character after the separator (or after the key if no separator) begins the value. The value may include whitespace, separators, or comment characters.
The following special cases are defined:
'\t' - horizontal tab.
'\f' - form feed.
'\r' - return
'\n' - new line
'\\' - add escape character.
'\ ' - add space in a key or at the start of a value.
'\!', '\#' - add comment markers at the start of a key.
'\=', '\:' - add a separator in a key.
Any Unicode character may be inserted in either key or value using the following escape:
'\uXXXX' - where XXXX represents the unicode character code as 4 hexadecimal digits.
Finally, longer lines can be broken by putting an escape at the very end of the line. Any leading space (unless escaped) is skipped at the beginning of the following line.
Examples
a-key = a-value
a-key : a-value
a-key=a-value
a-key a-value
All the above will result in the same key/value pair – key “a-key” and value “a-value”.
! comment...
# another comment...
The above are two examples of comments. Yes, you can add comments to Java .properties files – so please do!
Hong\ Kong = Near China
The above shows how to embed a space in a key – the key is “Hong Kong” and the value is “Near China”. Without the ‘\’ escape, the key is “Hong” and the value is “Kong = Near China” (it wouldn’t be the first time I’ve seen it done…).
a-longer-key-example = a really long value that is \
split over two lines.
An example of a long line split into two.
from celix.
According to the above article, I found white space at the start of a value is not escaped correctly by our implementation.
The following modified test case will fail on keyA
(note the value is " valueA" rather than "valueA"):
TEST_F(PropertiesTestSuite, StoreTest) {
const char* propertiesFile = "resources-test/properties_out.txt";
celix_autoptr(celix_properties_t) properties = celix_properties_create();
celix_properties_set(properties, "keyA", " valueA");
celix_properties_set(properties, "keyB", "valueB");
celix_properties_store(properties, propertiesFile, nullptr);
celix_autoptr(celix_properties_t) properties2 = celix_properties_load(propertiesFile);
EXPECT_EQ(celix_properties_size(properties), celix_properties_size(properties2));
EXPECT_STREQ(celix_properties_get(properties, "keyA", ""), celix_properties_get(properties2, "keyA", ""));
EXPECT_STREQ(celix_properties_get(properties, "keyB", ""), celix_properties_get(properties2, "keyB", ""));
}
from celix.
Related Issues (20)
- Bundle Management API Usability Improvement HOT 3
- CXX Remote Service stack-uffer-underflow
- Ensure the build containers keeps working
- Annotation of Consumer/Provider Type HOT 1
- celix 2.4.0 installation problem HOT 3
- macOS Build Timeout HOT 3
- How to debug bundles with GDB HOT 9
- Use-after-free in RemoteServicesIntegrationTestSuite.InvokeRemoteCalcService HOT 1
- Self-Contained Apache Celix Executable for Simplified Installation and Deployment1 HOT 1
- Minimize over-inclusion to reduce accidental complexity in header files HOT 1
- Discovery Zeroconf Portability
- General Dynamic IP Resolution for RSA
- Precise Definitions of DFI Argument Types HOT 4
- Unified Error Codes for libdfi
- Memory Leaks Caused By realloc Failure
- Unlimited Spin of Glibc's Read-write-lock Implementation HOT 4
- #include style
- run_test_rsa_dfi failure
- Codecov report uploader throttled HOT 2
- Event Admin test failure
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from celix.