Преглед на файлове

cmCursesStringWidget: remove manual delete

- Relpace `char*` operations with `std::string`
Tushar Maheshwari преди 6 години
родител
ревизия
0833486d62
променени са 2 файла, в които са добавени 13 реда и са изтрити 24 реда
  1. 12 20
      Source/CursesDialog/cmCursesStringWidget.cxx
  2. 1 4
      Source/CursesDialog/cmCursesStringWidget.h

+ 12 - 20
Source/CursesDialog/cmCursesStringWidget.cxx

@@ -9,7 +9,6 @@
 #include "cmStateTypes.h"
 #include "cmStateTypes.h"
 
 
 #include <cstdio>
 #include <cstdio>
-#include <cstring>
 
 
 inline int ctrl(int z)
 inline int ctrl(int z)
 {
 {
@@ -35,13 +34,13 @@ void cmCursesStringWidget::OnTab(cmCursesMainForm* /*unused*/,
 
 
 void cmCursesStringWidget::OnReturn(cmCursesMainForm* fm, WINDOW* /*unused*/)
 void cmCursesStringWidget::OnReturn(cmCursesMainForm* fm, WINDOW* /*unused*/)
 {
 {
-  FORM* form = fm->GetForm();
   if (this->InEdit) {
   if (this->InEdit) {
     cmCursesForm::LogMessage("String widget leaving edit.");
     cmCursesForm::LogMessage("String widget leaving edit.");
     this->InEdit = false;
     this->InEdit = false;
     fm->PrintKeys();
     fm->PrintKeys();
-    delete[] this->OriginalString;
+    this->OriginalString.clear();
     // trick to force forms to update the field buffer
     // trick to force forms to update the field buffer
+    FORM* form = fm->GetForm();
     form_driver(form, REQ_NEXT_FIELD);
     form_driver(form, REQ_NEXT_FIELD);
     form_driver(form, REQ_PREV_FIELD);
     form_driver(form, REQ_PREV_FIELD);
     this->Done = true;
     this->Done = true;
@@ -49,9 +48,7 @@ void cmCursesStringWidget::OnReturn(cmCursesMainForm* fm, WINDOW* /*unused*/)
     cmCursesForm::LogMessage("String widget entering edit.");
     cmCursesForm::LogMessage("String widget entering edit.");
     this->InEdit = true;
     this->InEdit = true;
     fm->PrintKeys();
     fm->PrintKeys();
-    char* buf = field_buffer(this->Field, 0);
-    this->OriginalString = new char[strlen(buf) + 1];
-    strcpy(this->OriginalString, buf);
+    this->OriginalString = field_buffer(this->Field, 0);
   }
   }
 }
 }
 
 
@@ -75,7 +72,7 @@ bool cmCursesStringWidget::HandleInput(int& key, cmCursesMainForm* fm,
     return false;
     return false;
   }
   }
 
 
-  this->OriginalString = nullptr;
+  this->OriginalString.clear();
   this->Done = false;
   this->Done = false;
 
 
   char debugMessage[128];
   char debugMessage[128];
@@ -113,7 +110,7 @@ bool cmCursesStringWidget::HandleInput(int& key, cmCursesMainForm* fm,
                key == ctrl('p') || key == KEY_NPAGE || key == ctrl('d') ||
                key == ctrl('p') || key == KEY_NPAGE || key == ctrl('d') ||
                key == KEY_PPAGE || key == ctrl('u')) {
                key == KEY_PPAGE || key == ctrl('u')) {
       this->InEdit = false;
       this->InEdit = false;
-      delete[] this->OriginalString;
+      this->OriginalString.clear();
       // trick to force forms to update the field buffer
       // trick to force forms to update the field buffer
       form_driver(form, REQ_NEXT_FIELD);
       form_driver(form, REQ_NEXT_FIELD);
       form_driver(form, REQ_PREV_FIELD);
       form_driver(form, REQ_PREV_FIELD);
@@ -125,7 +122,7 @@ bool cmCursesStringWidget::HandleInput(int& key, cmCursesMainForm* fm,
         this->InEdit = false;
         this->InEdit = false;
         fm->PrintKeys();
         fm->PrintKeys();
         this->SetString(this->OriginalString);
         this->SetString(this->OriginalString);
-        delete[] this->OriginalString;
+        this->OriginalString.clear();
         touchwin(w);
         touchwin(w);
         wrefresh(w);
         wrefresh(w);
         return true;
         return true;
@@ -188,23 +185,18 @@ bool cmCursesStringWidget::PrintKeys()
   }
   }
   if (this->InEdit) {
   if (this->InEdit) {
     char fmt_s[] = "%s";
     char fmt_s[] = "%s";
-    char firstLine[512];
     // Clean the toolbar
     // Clean the toolbar
-    memset(firstLine, ' ', sizeof(firstLine));
-    firstLine[511] = '\0';
     curses_move(y - 4, 0);
     curses_move(y - 4, 0);
-    printw(fmt_s, firstLine);
-    curses_move(y - 3, 0);
-    printw(fmt_s, firstLine);
-    curses_move(y - 2, 0);
-    printw(fmt_s, firstLine);
-    curses_move(y - 1, 0);
-    printw(fmt_s, firstLine);
-
+    clrtoeol();
     curses_move(y - 3, 0);
     curses_move(y - 3, 0);
     printw(fmt_s, "Editing option, press [enter] to confirm");
     printw(fmt_s, "Editing option, press [enter] to confirm");
+    clrtoeol();
     curses_move(y - 2, 0);
     curses_move(y - 2, 0);
     printw(fmt_s, "                press [esc] to cancel");
     printw(fmt_s, "                press [esc] to cancel");
+    clrtoeol();
+    curses_move(y - 1, 0);
+    clrtoeol();
+
     return true;
     return true;
   }
   }
   return false;
   return false;

+ 1 - 4
Source/CursesDialog/cmCursesStringWidget.h

@@ -23,9 +23,6 @@ class cmCursesStringWidget : public cmCursesWidget
 public:
 public:
   cmCursesStringWidget(int width, int height, int left, int top);
   cmCursesStringWidget(int width, int height, int left, int top);
 
 
-  cmCursesStringWidget(cmCursesStringWidget const&) = delete;
-  cmCursesStringWidget& operator=(cmCursesStringWidget const&) = delete;
-
   /**
   /**
    * Handle user input. Called by the container of this widget
    * Handle user input. Called by the container of this widget
    * when this widget has focus. Returns true if the input was
    * when this widget has focus. Returns true if the input was
@@ -65,7 +62,7 @@ public:
 protected:
 protected:
   // true if the widget is in edit mode
   // true if the widget is in edit mode
   bool InEdit;
   bool InEdit;
-  char* OriginalString;
+  std::string OriginalString;
   bool Done;
   bool Done;
 };
 };