4 ms·
> Also, suffers from the exact same problem I see pretty much every text search tool suffer: doesn't support other UTF encodings like UTF-16, meaning you'll mis
by burntsushi 7y ago
> Also, suffers from the exact same problem I see pretty much every text search tool suffer: doesn't support other UTF encodings like UTF-16, meaning you'll miss files.
Did you try it? ripgrep supports UTF-16 just fine. It even supports it automatically and transparently, via BOM detection. If there's no BOM, then you must specify the encoding explicitly.
- mehrdadn 7y agoYes, I tried it. Without a BOM, because you can't rely on BOMs being there.
- burntsushi 7y agoAt that point, you don't know the encoding, so the only thing available to you is heuristics (including needing to guess the byte order). Either way, I don't think it's accurate to claim that ripgrep doesn't support UTF-16.
- mehrdadn 7y ago> At that point, you don't know the encoding, so the only thing available to you is heuristics (including needing to guess the byte order). That's emphatically not the case though. I explained how you could handle it here without requiring BOM or byte order knowledge or heuristics: https://news.ycombinator.com/item?id=20198208 https://news.ycombinator.com/item?id=20198208 > Either way, I don't think it's accurate to claim that ripgrep doesn't support UTF-16. Having UTF-16 text in a file doesn't imply the file has have a BOM, and when I tried it rga didn't work on UTF-16 that didn't have a BOM. If that's still "ripgrep supports UTF-16" in your view then I'm not sure how else to word it, but the wording is hardly my concern. At the end of the day I was just trying to convey a particular fact, not argue over its wording.
- burntsushi 7y ago> I explained how you could handle it here without requiring BOM or byte order knowledge or heuristics: Yes, that's an absurd amount of development effort and would result in a serious performance regression. (To the point that it's likely nobody would use ripgrep at all, so your approach would need to be put behind a flag, which seriously hinders the feature since it's no longer automatic.) Moreover, that only covers match detection, but does not actually cover output. Once you find the match, you have to determine how to print it, and the device you're printing to very likely does not support things like UTF-32 or even UTF-16 in many cases. Moreover, there are many operations that ripgrep does in a post-processing step (like limiting the output to a certain number of characters per line) that require knowing the presumed encoding (which is always UTF-8 by that point, since the data will have been transcoded to UTF-8 if UTF-16 were detected). > UTF-16 doesn't require BOMs You cannot decode UTF-16 without knowing its byte order. The BOM tells you that. If there is no BOM, then you need to get the byte order from some other source (or guess it). ripgrep requires the user to tell it what it is. This seems entirely reasonable to me, especially since most or all UTF-16 files I've seen include a BOM. Notably, ripgrep's support for UTF-16 is good enough for VS Code, which has a pretty sizable Windows user base. > your view then I'm not sure how else to word it, but the wording is hardly my concern. At the end of the day I was just trying to convey a fact, not argue over its wording or semantics. At the end of the day, my concern is to correct misleading claims about what ripgrep can and can't do. ripgrep clearly has support for UTF-16, and this is actually one of its marquee features that sets it apart from other search tools. For example, grep doesn't (and literally can't) support UTF-16 at all. The only way to search UTF-16 encoded files with grep is to transcode the file to UTF-8 first or to set the locale to C, and search for the binary encoding directly. ripgrep does a lot better than that, so to lump it in with "pretty much every text search tool" is pretty misleading from my perspective.
- mehrdadn 7y ago> ripgrep's support for UTF-16 is good enough for VS Code, which has a pretty sizable Windows user base. > At the end of the day, my concern is to correct misleading claims about what ripgrep can and can't do. > ripgrep does a lot better than that, so to lump it in with "pretty much every text search tool" is pretty misleading from my perspective. Man... it's impossible to offer criticism these days. You're taking all this way too personally, and it's also making you misread what I'm saying. phireski understood what I was saying quite well and immediately opened an issue (which I very much appreciate), but somehow you took it differently. I didn't even realize you're here. I have nothing against you (I don't even know you). And I certainly was not misleading anyone. I was just trying to help by explaining what I've been consistently looking for in text search tools since grep, and trying to offer solutions on how one could potentially handle these situations. Here's no reason to get upset and offended. I'm not attacking you, just offering an honest criticism—with a solution too. And I would've been happy to address your further concerns here just like I did in the last comment, if you'd be more open to it and wouldn't take it so personally. If you don't care or it's too much work—I understand; there's no need to argue in that case. We can just move on.