-
Notifications
You must be signed in to change notification settings - Fork 13
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
Allow specifying whitespace on save #148
Conversation
a985e77
to
c5d4aa5
Compare
36599c5
to
7249946
Compare
@cmyr are you actively working on XML declaration single quote support? If not, I will have a shot at it based on the changes in this PR |
This lets the user optionally customize the whitespace used during serialization. The implementation is slightly annoying. the `quick_xml` and `rust-plist` crates specify whitespace in different ways; `quick_xml` takes a (u8, usize) pair (the byte and its count) and `rust-plist` takes a `Cow<'static str>`. Additionally, in our own glyph serialization code we need to write whitespace directly when appending the 'lib' section. Anyway: you *create* a `WriteOptions` object by passing it a string, and then we figure out what the appropriate (u8, usize) pair is. The reason we want to think about this is because eventually writing out a UFO should be parallelized, and that could mean cloning `WriteOptions` once for each glyph; we would like to make sure this isn't allocating. So this seems to work, even if some of the internals are a bit gross.
@chrissimpkins I took a peek haven't implemented anything, but let's merge this first, so we can use I also think that it's worth being slightly fancier and doing the replacement before the initial write, it just feels more principled, and will be more portable (the write-then-rewrite approach may be slower on older storage media, or on other platforms.) |
@chrissimpkins to elaborate on what I would propose:
Thinking about this, I think the first option is totally reasonable. The second option is probably marginally more 'efficient', but I don't think it matters; the main thing we want to avoid is closing and reopening all the file handles. edit: broke this out into an issue, #156 |
This lets the user optionally customize the whitespace used during
serialization.
The implementation is slightly annoying. the
quick_xml
andrust-plist
crates specify whitespace in different ways;
quick_xml
takes a (u8,usize) pair (the byte and its count) and
rust-plist
takes aCow<'static str>
. Additionally, in our own glyph serialization code weneed to write whitespace directly when appending the 'lib' section.
Anyway: you create a
WriteOptions
object by passing it a string, andthen we figure out what the appropriate (u8, usize) pair is. The reason
we want to think about this is because eventually writing out a UFO
should be parallelized, and that could mean cloning
WriteOptions
oncefor each glyph; we would like to make sure this isn't allocating.
So this seems to work, even if some of the internals are a bit gross.
this is based off of #147, which should go in first.