Properly do lexographic comparison of ascii strings #516
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There are two changes here to the way that assets are compared:
In order to align better with how Stellar Core sorts assets (that is to say, in no special way besides the default), we rely on the actual, raw, XDR asset type (
xdr.AssetType
) value to distinguish based on type. The logic is still the same, but is much easier to understand since there are no convoluted branching string comparisons.JavaScript's
String.prototype.localeCompare
function will sort strings with lowercase letters as having lower preference to those with uppercase ones (proof: RunKit). This is not how the ASCII table sorts them, nor is it how Stellar Core will sort them as it essentially looks at the raw byte values for ordering.For (2), we introduce
asciiCompare
, which hard-codes theen
locale rather than leaving it system specific and also forces uppercase letters to take precedence.Closes #515.