What is the ustring parser for? Assuming you load a valid unicode text file (which in this day and age is every text file) wouldn't it just match everything?
Best guess, this is for something like validating correct binary encoding of JSON files? But is it actually possible to load a non-valid unicode text file into a string in JavaScript?
I was expecting I'd use this for, say, keywords.
But then the "success" example in the documentation says:
Note that the index is 12, which is correct, since every hieroglyph here takes 3 bytes.
String operations in JS generally operate in ranges of code points:

So these numbers aren't useful for error reporting, or any subsequent string operation in JS really.
Text editors usually measure positions in code points as well:

The documentation itself explains:
This parser is very similar to the string parser, except it takes a bit hacky (though performant) approach, that is based on counting length of the given match string in bytes. It then subslices and compares string slice with that match string.
"hacky though performant", but it seems like this is doing a lot of unnecessary work to figure out a string position that isn't useful for most common use cases, like just matching a keyword or symbol, isn't it?
What I was expecting was a simpler parser that would use String.prototype.includes, which ought to be the fastest native way to check for a specific string at a specific offset, I think?
EDIT: oh, whoops, now I get it! I avoided string, because it it specifically says this will match "ASCII", which is incorrect. It would in fact match whatever Unicode characters you put in the string. Looks like a documentation problem.
But I don't see any other parser for simple strings - and nothing relevant in the codebase calling includes.
EDIT: looks like maybe there is room for a small optimization here to avoid copying.
It's also difficult to think of a name for such a parser, now that string is taken. 😅
(I know I'm submitting a lot of feedback! I am already somewhat invested in this lovely library, and I do want to help out - if you want me to submit PRs for anything, let me know.)
EDIT: let me know if you'd like me to correct the documentation and/or try the minor optimization/simplification with includes in the string parser.
What is the
ustringparser for? Assuming you load a valid unicode text file (which in this day and age is every text file) wouldn't it just match everything?Best guess, this is for something like validating correct binary encoding of JSON files? But is it actually possible to load a non-valid unicode text file into a string in JavaScript?
I was expecting I'd use this for, say, keywords.
But then the "success" example in the documentation says:
String operations in JS generally operate in ranges of code points:
So these numbers aren't useful for error reporting, or any subsequent string operation in JS really.
Text editors usually measure positions in code points as well:
The documentation itself explains:
"hacky though performant", but it seems like this is doing a lot of unnecessary work to figure out a string position that isn't useful for most common use cases, like just matching a keyword or symbol, isn't it?
What I was expecting was a simpler parser that would useString.prototype.includes, which ought to be the fastest native way to check for a specific string at a specific offset, I think?EDIT: oh, whoops, now I get it! I avoided
string, because it it specifically says this will match "ASCII", which is incorrect. It would in fact match whatever Unicode characters you put in the string. Looks like a documentation problem.But I don't see any other parser for simple strings - and nothing relevant in the codebase callingincludes.EDIT: looks like maybe there is room for a small optimization here to avoid copying.
It's also difficult to think of a name for such a parser, now that😅stringis taken.(I know I'm submitting a lot of feedback! I am already somewhat invested in this lovely library, and I do want to help out - if you want me to submit PRs for anything, let me know.)
EDIT: let me know if you'd like me to correct the documentation and/or try the minor optimization/simplification with
includesin thestringparser.