[[feature-stackdir]] Factor out property-saving logic.

This allows the same logic to be used for internal properties, custom
property sets, and shared properties.
[[feature-stackdir]] Save shared properties.
[[feature-stackdir]] Make sure that even short UTF-8 data is stored as string.