Guest User

Untitled

a guest
May 1st, 2024
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.06 KB | None | 0 0
  1. struct STRING {
  2.  
  3.     STRING() {
  4.         this->length = 0;
  5.         this->width = 0;
  6.         this->wtext[this->length] = L'\0';
  7.         this->utext[this->length] = (unsigned char)'\0';
  8.         this->text[this->length] = '\0';
  9.     }
  10.     STRING(const char c) {
  11.         this->length = 0;
  12.         this->width = 0;
  13.         this->wtext[this->length] = L'\0';
  14.         this->utext[this->length] = (unsigned char)'\0';
  15.         this->text[this->length] = '\0';
  16.         this->App(c);
  17.     }
  18.     STRING(const char text[]) {
  19.         this->length = 0;
  20.         this->width = 0;
  21.         this->wtext[this->length] = L'\0';
  22.         this->utext[this->length] = (unsigned char)'\0';
  23.         this->text[this->length] = '\0';
  24.         this->Write(text);
  25.     }
  26.     STRING(char* text) {
  27.         this->length = 0;
  28.         this->width = 0;
  29.         this->wtext[this->length] = L'\0';
  30.         this->utext[this->length] = (unsigned char)'\0';
  31.         this->text[this->length] = '\0';
  32.         this->Write(text);
  33.     }
  34.     STRING(wchar_t* text) {
  35.         this->length = 0;
  36.         this->width = 0;
  37.         this->wtext[this->length] = L'\0';
  38.         this->utext[this->length] = (unsigned char)'\0';
  39.         this->text[this->length] = '\0';
  40.         this->Write<wchar_t>(text);
  41.  
  42.     }
  43.     STRING(const std::string string) {
  44.         this->length = 0;
  45.         this->width = 0;
  46.         this->wtext[this->length] = L'\0';
  47.         this->utext[this->length] = (unsigned char)'\0';
  48.         this->text[this->length] = '\0';
  49.         this->Write(string.c_str());
  50.     }
  51.  
  52.     DINT length, width;
  53.     wchar_t wtext[ENGINE_TEXT_MAX_LENGTH];
  54.     char text[ENGINE_TEXT_MAX_LENGTH];
  55.     unsigned char utext[ENGINE_TEXT_MAX_LENGTH];
  56.  
  57.     char operator[] (int position) {
  58.         return this->text[position];
  59.     }
  60.  
  61.     template<typename T = const char>
  62.     void Write(T text[]) {
  63.         for (this->length = 0; text[this->length] != '\0'; this->length++) {
  64.             this->text[this->length] = (char)text[this->length];
  65.             this->wtext[this->length] = (wchar_t)text[this->length];
  66.             this->utext[this->length] = (unsigned char)text[this->length];
  67.         }
  68.         this->text[this->length] = '\0';
  69.         this->wtext[this->length] = L'\0';
  70.         this->utext[this->length] = (unsigned char)'\0';
  71.     }
  72.  
  73.     template<typename T = const char>
  74.     void Append(T text[]) {
  75.         for (int t = 0; text[t] != '\0'; t++) {
  76.             this->text[this->length] = (char)text[t];
  77.             this->wtext[this->length] = (wchar_t)text[t];
  78.             this->utext[this->length] = (unsigned char)text[t];
  79.             this->length++;
  80.         }
  81.         this->text[this->length] = '\0';
  82.         this->wtext[this->length] = L'\0';
  83.         this->utext[this->length] = (unsigned char)'\0';
  84.     }
  85.  
  86.     template<typename T = const char>
  87.     void Space(T text[]) {
  88.         this->App(' ');
  89.         this->Append(text);
  90.     }
  91.  
  92.     template<typename T = const char>
  93.     void App(T c) {
  94.         this->text[this->length] = (char)c;
  95.         this->wtext[this->length] = (wchar_t)c;
  96.         this->utext[this->length] = (unsigned char)c;
  97.         this->length++;
  98.         this->text[this->length] = '\0';
  99.         this->wtext[this->length] = L'\0';
  100.         this->utext[this->length] = (unsigned char)'\0';
  101.     }
  102.  
  103.     bool Has(const char character) {
  104.         for (int i = 0; i < this->length; i++) {
  105.             if (this->text[i] == character) return true;
  106.         }
  107.         return false;
  108.     }
  109.     void _dump() {
  110.         std::cout << "\n>STRING: [" << this->width << ", " << this->length << "] " << this->text;
  111.     }
  112. };
Advertisement
Add Comment
Please, Sign In to add comment