Skip to content

Conversation

@mina86
Copy link

@mina86 mina86 commented Jul 9, 2025

Provide custom implementation of the serilaize_string function found in cssparser which takes more care to use shortest possible string representation. This is done with through two changes.

Firstly, the function figures out whether double or single quotes are better. For example, Holmes never said "Elementary, my dear Watson." is best quoted using apostrophes to avoid escaping the double quotes inside.

Secondly, the function avoids unnecessary space after hex encoding of control characters. For example, \x01Z is escaped as "\1Z" rather than "\1 Z".

To make this all more consistent throughout the code-base, introduce serialize module with symbols corresponding to serialise_* functions in cssparse crate.

Provide custom implementation of the serilaize_string function found
in cssparser which takes more care to use shortest possible string
representation.  This is done with through two changes.

Firstly, the function figures out whether double or single quotes are
better.  For example, `Holmes never said "Elementary, my dear
Watson."` is best quoted using apostrophes to avoid escaping the
double quotes inside.

Secondly, the function avoids unnecessary space after hex encoding of
control characters.  For example, `\x01Z` is escaped as `"\1Z"` rather
than `"\1 Z"`.

To make this all more consistent throughout the code-base, introduce
serialize module with symbols corresponding to serialise_* functions
in cssparse crate.
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.

1 participant