fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <cstdint>
  5.  
  6. /**/
  7. class UnicodeOne {
  8. public:
  9. int Parse(const char8_t X[]) {
  10. C[0] = X[0];
  11. if ((X[0] & (1 << 7)) != 0) { return 1; }
  12. C[1] = X[1];
  13. C[2] = 0;
  14. if ((X[1] & (1 << 7)) != 0) { return 2; }
  15. C[2] = X[2];
  16. return 3;
  17. }
  18.  
  19. std::size_t Size() {
  20. if (C[0] == 0 && C[1] != 0) { return 0; }
  21. if ((C[0] & (1 << 7)) != 0) { return 1; }
  22. if ((C[1] & (1 << 7)) != 0) { return 2; }
  23. return 3;
  24. }
  25.  
  26. std::int8_t& operator [](std::size_t i) {
  27. return C[i];
  28. }
  29.  
  30. protected:
  31. std::int8_t C[3] = {};
  32. };
  33. std::ostream& operator<<(std::ostream& OS,UnicodeOne C) {
  34.  
  35. if ((C[1] & (1 << 7)) != 0) { C[2] = u8'\0'; }
  36.  
  37. //const char8_t X[4] = { C[0],C[1],C[2],u8'\0' };
  38. const std::int8_t X[4] = { C[0],C[1],C[2],u8'\0' };
  39. OS << X;
  40. return OS;
  41. }
  42. /**/
  43.  
  44.  
  45. /**/
  46. int main() {
  47. UnicodeOne UO;
  48.  
  49. const char8_t A[] = u8"あ\0";
  50. const char8_t B[] = u8"え\0";
  51. char8_t C[] = u8"あ";
  52. UO.Parse(C);
  53. std::cout << UO <<":"<<A << std::endl;
  54.  
  55. return 0;
  56. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:9:18: error: ‘char8_t’ does not name a type; did you mean ‘char16_t’?
  int Parse(const char8_t X[]) {
                  ^~~~~~~
                  char16_t
prog.cpp: In function ‘std::ostream& operator<<(std::ostream&, UnicodeOne)’:
prog.cpp:35:40: error: ‘u8’ was not declared in this scope
   if ((C[1] & (1 << 7)) != 0) { C[2] = u8'\0'; }
                                        ^~
prog.cpp:38:45: error: ‘u8’ was not declared in this scope
   const std::int8_t X[4] = { C[0],C[1],C[2],u8'\0' };
                                             ^~
prog.cpp:38:47: error: expected ‘}’ before '\x0'
   const std::int8_t X[4] = { C[0],C[1],C[2],u8'\0' };
                            ~                  ^~~~
prog.cpp:38:52: warning: no return statement in function returning non-void [-Wreturn-type]
   const std::int8_t X[4] = { C[0],C[1],C[2],u8'\0' };
                                                    ^
prog.cpp: At global scope:
prog.cpp:39:3: error: ‘OS’ does not name a type
   OS << X;
   ^~
prog.cpp:40:3: error: expected unqualified-id before ‘return’
   return OS;
   ^~~~~~
prog.cpp:41:2: error: expected declaration before ‘}’ token
  }
  ^
stdout
Standard output is empty