News for hackers. Stuff that matters.
Re:Rapidstring: Maybe the fastest string library ever by rurban on Tuesday July 31, 2018 @08:14AM (#17652521)
I like the stack trick.

But it's still just a membuf library, without any string support. No encoding, no Unicode, no upper/lower/fc/norm support, which would be important to compare or find strings. And coreutils (e.g grep) still have no unicode support. It's 2018, not the seventies anymore. Unicode strings need to be normalized to be able to be found.

Re:Rapidstring: Maybe the fastest string library ever by abenedic on Tuesday July 31, 2018 @08:00PM (#17658432)
I don't really know why you are being downvoted. There are a lot of string libraries that do not work well with Unicode strings. If you natively speak any non-European language it can be hard to use those libraries to effectively solve your problems. Not to bad mouth this project, but we don't really need a fast incomplete library.
Re:Rapidstring: Maybe the fastest string library ever by MrEldritch on Tuesday July 31, 2018 @08:41PM (#17658660)
In the modern development environment, I think it's genuinely fair to say that something which doesn't support Unicode strings cannot be claimed to support strings.

It's like saying you have the fastest integer math library ever written, with the minor caveat that it only supports numbers smaller than 256 because it achieves that speed by being simply a hardcoded lookup table, and crashes if you give it anything else.

Re:Rapidstring: Maybe the fastest string library ever by dwheeler on Wednesday August 01, 2018 @12:34AM (#17659709)
It appears to support Unicode just fine, you just have to use UTF-8. I find that in most cases you should only use UTF-8 anyway, so in most cases that is not a problem.
Re:Rapidstring: Maybe the fastest string library ever by rurban on Wednesday August 01, 2018 @04:51AM (#17660690)
Nope, big mistake. You cannot just search for "Café" in "Café", as there are multiple representations for the same character. Think of Cyrillic vs Greek, Han vs Hangul. The popular garbage-in, garbage-out doesn't apply to unicode identifiers. That's why the Mac filesystem normalization was correct, and the unix filesystems are all broken. If it's not identifiable it's no identifier. That's why java and cperl are the only languages with proper and safe unicode support. Python 3 is a bit better than Python 2, Perl6 better than Perl5 and the rest, but still don't apply unicode security guidelines for identifiers. It's much better for browsers and email clients.

And with case-insensitivity it gets worse, as there are some locale dependent additional rules, for Turkish and Lithuania. And this depends on "some" global settings.

http://perl11.org/blog/foldcase.html

Re:Rapidstring: Maybe the fastest string library ever by iforgotpassword on Wednesday August 01, 2018 @06:28AM (#17661215)
Japanese is also great. While there are general rules when you use hiragana vs. katakana, sometimes for stylistic reasons the "wrong" one is used, or some kanji is "spelled out" as hiragana, and depending on context, you might or might not want to include these in your search results.

Tbh I just stopped caring and now happily live in my little world where utf8 is the solution to everything, doesn't yield any problems ever, and anyone telling me differently gets completely ignored.

Re:Rapidstring: Maybe the fastest string library ever by vbezhenar on Wednesday August 01, 2018 @01:34AM (#17659952)
If you're using WinAPI, you have to use UCS-16. Converting strings for every call would be abysmal to performance.
Re:Rapidstring: Maybe the fastest string library ever by hrydgard on Wednesday August 01, 2018 @02:02AM (#17660066)
For most software it's perfectly fine to convert. What Windows API call that takes string input do you call so often that it would be an issue?
Re:Rapidstring: Maybe the fastest string library ever by flohofwoe on Wednesday August 01, 2018 @03:44AM (#17660386)
There are only very few WinAPI functions which use UCS-2 vs ASCII, and none of them are performance-critical. It's totally fine to convert from/to UTF-8 on the fly, especially since the conversion is extremely cheap (and the rest of the world has moved on to UTF-8 anyway).
Re:Rapidstring: Maybe the fastest string library ever by iforgotpassword on Wednesday August 01, 2018 @06:23AM (#17661203)
All winapi functions use UCS2. The "ASCII" versions are just wrappers that implicitly convert from the current locale (latin1, ShiftJIS, BIG5, ...) to UCS2. Try passing some Japanese text to the ASCII version of a function on a system that's set to eg. German and see what happens...
Re:Rapidstring: Maybe the fastest string library ever by flohofwoe on Wednesday August 01, 2018 @06:45AM (#17661304)
Most Win32 API functions don't even take string parameters, so there's no separate ASCII or UCS-2 version of those.

Of the functions that take strings, the old ...A() versions should never be called anyway since they depend on the obsolete concept of code pages. The proper way to work with strings on Windows (IMHO) is to encode all string data to UTF-8, only encode/decode from/to UCS-2 when needed, and call the ...W() functions explicitely (don't use the global UNICODE define).

Also see: http://utf8everywhere.org/

Re:Rapidstring: Maybe the fastest string library ever by mehrdadn on Tuesday July 31, 2018 @09:58PM (#17659040)
Does this library crash like in your example though? There's a difference between "not having Unicode-specific features" and "failing when given Unicode input".
Re:Rapidstring: Maybe the fastest string library ever by mamcx on Tuesday July 31, 2018 @08:18PM (#17658537)
I think instead is better to title this as "maybe the fastest ascii string library"
Re:Rapidstring: Maybe the fastest string library ever by slavik81 on Wednesday August 01, 2018 @12:55AM (#17659812)
I don't see anything encoding-specific in there. It may not be a Unicode string library, but it's also not an ASCII string library. Rurban was right. It's really just a nice membuf library—but there's nothing wrong with that! You could build a great Unicode or ASCII string library on top of this.
Re:Rapidstring: Maybe the fastest string library ever by johnboyer on Tuesday July 31, 2018 @10:07PM (#17659088)
Unicode is supported with UTF-8, only different character types aren't supported because generics are messy in C. I thought of accepting void* to support wchar_t and others, but some performance penalties came with it so I decided against it.
Re:Rapidstring: Maybe the fastest string library ever by lifthrasiir on Tuesday July 31, 2018 @10:43PM (#17659237)
No, having different character types (I believe you are referring to C11's `char16_t` and `char32_t`?) is not a requirement for Unicode support. At the very least you need to have a single function or two that...

* Receives a string expected to be encoded in UTF-8, and an offset to it expected to be a UTF-8 sequence boundary.

* Scans forward or backward for the next or previous UTF-8 sequence boundary.

* Optionally returns the code point for the scanned UTF-8 sequence.

* Has proper error handling for every imaginable cases: out of boundary, not a boundary, not a valid UTF-8 sequence. (OOB case needs to be handled because it will be the end condition of the iteration. Preferably should be distinct from other error conditions.)

Every other functionality can build upon this little function, in particular the iteration and UTF-8 validation will be trivial. The full Unicode support including case mapping, folding, normalization and property lookup will of course require a not-so-small table but is not strictly necessary anyway.

Björn Höhrmann's Flexible and Economical UTF-8 Decoder [1] will be handy for a concise implementation.

[1] https://bjoern.hoehrmann.de/utf-8/decoder/dfa/

Re:Rapidstring: Maybe the fastest string library ever by flohofwoe on Wednesday August 01, 2018 @03:42AM (#17660377)
I don't see any functions in the OP's library that would require dedicated UTF-8 handling. The string length is given in bytes, not characters or codepoints. There's no functionality to give you the character at n-th location etc... you can easily implement all UNICODE-specific functionality in a separate library and use it together with the OPs library. IMHO that's even preferable.
Re:Rapidstring: Maybe the fastest string library ever by rurban on Wednesday August 01, 2018 @04:40AM (#17660620)
Yes, but don't call it string library then. Strings should handle strings, and strings are unicode now. Unicode needs to be normalized and needs case-insensitive support.

And it's not easy. I implemented the third of its kind. First there was ICU, which is overly bloated. You don't need 30MB for a simple string libc. Then there is libunistring which has overly slow iterators, so not usable for coreutils. And then there's my safelibc, which is small and fast, but only for wide-chars, not utf-8.

I fixed and updated the musl case-mapping, making it 2x faster, but this is not in yet. And there's not even a properly spec'ed wcscmp/wcsicmp to find strings. glibc is an overall mess. I won't touch that. wcsicmp/wcsfc/wcsnorm are not even in POSIX.

Re:Rapidstring: Maybe the fastest string library ever by sundarurfriend on Wednesday August 01, 2018 @08:13AM (#17661745)
How does the utf8proc[1] library that Julia uses compare to these?

[1] http://juliastrings.github.io/utf8proc/doc/

Re:Rapidstring: Maybe the fastest string library ever by zlynx on Wednesday August 01, 2018 @05:15PM (#17667059)
Why try to redefine the word "string?"

In computer jargon I believe CISC and the PDP-11 have seniority. That's why all multi-word functions like memcpy are in C's string.h header.

Re:Rapidstring: Maybe the fastest string library ever by lifthrasiir on Thursday August 02, 2018 @01:25AM (#17669386)
Hey, even C contains a locale-dependent string comparison, namely `strcoll` (since 1990!).

I admit two words "string" and "text" are now interchangable. But that doesn't make strings have less requirements, people are just expecting more out of strings.

Re:Rapidstring: Maybe the fastest string library ever by whyever on Wednesday August 01, 2018 @03:32AM (#17660347)
> But it's still just a membuf library, without any string support.

Just like the strings in the C and C++ standard library.

Re:Rapidstring: Maybe the fastest string library ever by rurban on Wednesday August 01, 2018 @04:55AM (#17660714)
Exactly. POSIX and the C/C++ standards don't support strings and utf-8 yet neither. coreutils and grep neither. Most computer languages neither.

It's a mess and a big security risk. We are still in the stone age of string support.

Re:Rapidstring: Maybe the fastest string library ever by flohofwoe on Wednesday August 01, 2018 @06:38AM (#17661272)
At least on Mac the command line utils support international text just fine, all text files are encoded as UTF-8 by convention, and (for instance) grep's case-insensitive search works for non-ASCII characters.
Re:Rapidstring: Maybe the fastest string library ever by burntsushi on Wednesday August 01, 2018 @08:10AM (#17661728)
It's the same on Linux. GNU grep supports Unicode just fine, assuming, of course, your system's locale settings are configured correctly. :-)