aslze / asl

A compact C++ cross-platform library including JSON, XML, HTTP, Sockets, WebSockets, threads, processes, logs, file system, CSV, INI files, vectors and matrices, etc.
Other
69 stars 17 forks source link

fix count problem #18

Closed dezashibi closed 1 year ago

dezashibi commented 1 year ago

the count method calculates the number of actual character wrong in different situations such as one or many emojis, though the chars() works correctly and creates correct array of codepoints, so considering the functionality of chars() I've modified the count() function to fix this.

aslze commented 1 year ago

Thank you!

I prefer a function of that size to be in String.cpp instead of in the header, though.

BTW, I think I understand why that failed. wcslen() gives the number of wchar_t, which here are UTF16 code units. So that will fail outside the BMP (e.g. emojis).

dezashibi commented 1 year ago

sure will move the function to String.cpp now

dezashibi commented 1 year ago

Done

aslze commented 1 year ago

Thinking again. Maybe that was intentional (it's old code): maybe we sometimes need the length in wchar_t units to pass it to functions using wide char strings (like the Windows API and others).

I'll merge this but analyze it again to see if we might need two functions, one for code points and one for wchar_t (UTF16 code units).

Thanks.

dezashibi commented 1 year ago

Sure, I'm going to be using this for a project, so it'll be many real world usecases and I'll be watching that

P.S. I already tested that in linux and windows, worked correctly