Dictionaries are unordered. If I have text that is:
\r\n\r\r\n
And the \r -> \n replacement runs first, I get
\n\n\n\n\n
When \r\n replacement runs, nothing changes (no \r).
Now if the operation runs in reverse (\r\n -> \n first):
\r\n\r\r\n
becomes
\n\r\n
And then I suspect
\n\n
Which is different. Isn't that a pretty evil bug? Why are we using
dictionaries?
Ah, by looking at text_replaced, I am seeing we iterate over
replacements.items() sorted by length, but I don't think that's the
right way to do it.. if we have clauses that do
Dictionaries are unordered. If I have text that is:
\r\n\r\r\n
And the \r -> \n replacement runs first, I get
\n\n\n\n\n
When \r\n replacement runs, nothing changes (no \r).
Now if the operation runs in reverse (\r\n -> \n first):
\r\n\r\r\n
becomes
\n\r\n
And then I suspect
\n\n
Which is different. Isn't that a pretty evil bug? Why are we using
dictionaries?
Ah, by looking at text_replaced, I am seeing we iterate over items() sorted by length, but I don't think that's the
replacements.
right way to do it.. if we have clauses that do
\n -> \r
\r -> \x
\x -> \n
Then the ordering matters very much.