aui icon indicating copy to clipboard operation
aui copied to clipboard

Implement AStringView as AByteBufferView

Open Alex2772 opened this issue 3 years ago • 2 comments

Alex2772 avatar Jul 24 '22 17:07 Alex2772

Issues

While implementing AStringView I have encountered the following design issues:

  1. Should use char16_t instead of wchar_t because size of wchar_t differs on Windows and Linux, causing incompatibility.
  2. Since AString is a wchar_t storage, AStringView is expected to be a wchar_t storage too, which forces to use widechar string literals (L"" instead of "").
  3. Construction of AString from const char* always performs expensive utf8 parsing.

Possible solutions

  1. Switch AString to basic char string and implement utf8 iterator, however text field and font rendering implementation may require a special 32-bit AString.
  2. Use AStringView only for substrings and trims.
  3. Implement string COW instead of AStringView

Existing solutions

  1. Qt, C#, Java, Kotlin use UTF-16 in their strings, also Qt implements copy on write (COW).
  2. GTK uses UTF-8.

Alex2772 avatar Jul 27 '22 16:07 Alex2772

Another possible solution: store a global std::unordered_map from const char* to const char16_t*.

Alex2772 avatar Nov 17 '22 21:11 Alex2772