VinGarcia

tinyutf8 first impressions

May 15th, 2017
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. Hello Jake. I'm just posting some of my first impressions on your library.
  2.  
  3. Also, I'm glad that you are developing this project I really miss some easy to use C++ library for working with utf-8 and unicode in general.
  4.  
  5. My considerations:
  6.  
  7. I missed a short example of a use case to figure out the most interesting facilities your library has to offer, a short example on the summary page would suffice.
  8.  
  9. I have some doubts:
  10. - Can I convert other encodings to utf-8 and back? If yes which encodings? This would be great to make my library work on non-utf8 environments.
  11. - What is the return type of `operator[]`.
  12.  
  13. You commented in the summary that this library is designed for C++11 projects but I tested a little hello world example using `g++ tinyutf8.cpp main.cpp && a.out` that worked fine, which is good =].
  14.  
  15. ```C++
  16. #include <iostream>
  17. #include <string>
  18.  
  19. #include "tinyutf8.h"
  20.  
  21. int main(int argc, char* argv[]) {
  22. utf8_string str = "coração";
  23. std::cout << str.size() << std::endl; // 9
  24. std::cout << str.c_str() << std::endl; // "coração"
  25. std::cout << sizeof(str[4]) << std::endl; // 16
  26. }
  27. ```
  28.  
  29. A suggestion: It might be interesting to add a function like this:
  30.  
  31. ```C++
  32. std::ostream& operator<<(std::ostream& os, const utf8_string& t);
  33. ```
  34.  
  35. So that I could print out the string easily with `std::cout << str << std::endl;`. Outputting the c_str() representation of the string might be enough and would probably make easier to make short examples using the library. However, I understand that there are some encoding concerns regarding the behavior of this function, maybe it is not the right time to implement it.
  36.  
  37. Lastly, about your question on adapting the library for new types like `wchar_t` and `char32_t` or making it header only, I would vote for adapting it to use `char32_t` in special, since `wchar_t` implementations vary too much to use safely.
  38.  
  39. I hope these suggestions help, I will finish reading the header and maybe I will use it.
Advertisement
Add Comment
Please, Sign In to add comment