diff options
author | nyamatongwe <unknown> | 2013-05-02 13:16:36 +1000 |
---|---|---|
committer | nyamatongwe <unknown> | 2013-05-02 13:16:36 +1000 |
commit | 1f8862974636d649b93b514fc0ff8e5526e304b7 (patch) | |
tree | 6007647c7c8aaaa8741617159b8e86647dfcc4c7 | |
parent | 341ce982991fd356c631c1e706ec3e88d6844c33 (diff) | |
download | scintilla-mirror-1f8862974636d649b93b514fc0ff8e5526e304b7.tar.gz |
Replacing raw pointer and allocation with std::string.
-rw-r--r-- | src/CallTip.cxx | 22 | ||||
-rw-r--r-- | src/CallTip.h | 2 |
2 files changed, 10 insertions, 14 deletions
diff --git a/src/CallTip.cxx b/src/CallTip.cxx index d5ba3bd09..8931f413d 100644 --- a/src/CallTip.cxx +++ b/src/CallTip.cxx @@ -7,12 +7,14 @@ #include <stdlib.h> #include <string.h> +#include <stdio.h> + +#include <string> #include "Platform.h" #include "Scintilla.h" #include "CallTip.h" -#include <stdio.h> #ifdef SCI_NAMESPACE using namespace Scintilla; @@ -22,7 +24,6 @@ CallTip::CallTip() { wCallTip = 0; inCallTipMode = false; posStartCallTip = 0; - val = 0; rectUp = PRectangle(0,0,0,0); rectDown = PRectangle(0,0,0,0); lineHeight = 1; @@ -56,8 +57,6 @@ CallTip::CallTip() { CallTip::~CallTip() { font.Release(); wCallTip.Destroy(); - delete []val; - val = 0; } // Although this test includes 0, we should never see a \0 character. @@ -176,17 +175,17 @@ int CallTip::PaintContents(Surface *surfaceWindow, bool draw) { // Draw the definition in three parts: before highlight, highlighted, after highlight int ytext = rcClient.top + ascent + 1; rcClient.bottom = ytext + surfaceWindow->Descent(font) + 1; - char *chunkVal = val; + const char *chunkVal = val.c_str(); bool moreChunks = true; int maxWidth = 0; while (moreChunks) { - char *chunkEnd = strchr(chunkVal, '\n'); + const char *chunkEnd = strchr(chunkVal, '\n'); if (chunkEnd == NULL) { chunkEnd = chunkVal + strlen(chunkVal); moreChunks = false; } - int chunkOffset = chunkVal - val; + int chunkOffset = chunkVal - val.c_str(); int chunkLength = chunkEnd - chunkVal; int chunkEndOffset = chunkOffset + chunkLength; int thisStartHighlight = Platform::Maximum(startHighlight, chunkOffset); @@ -215,7 +214,7 @@ int CallTip::PaintContents(Surface *surfaceWindow, bool draw) { } void CallTip::PaintCT(Surface *surfaceWindow) { - if (!val) + if (val.empty()) return; PRectangle rcClientPos = wCallTip.GetClientPosition(); PRectangle rcClientSize(0, 0, rcClientPos.right - rcClientPos.left, @@ -253,10 +252,7 @@ PRectangle CallTip::CallTipStart(int pos, Point pt, int textHeight, const char * int codePage_, int characterSet, int technology, Window &wParent) { clickPlace = 0; - delete []val; - val = 0; - val = new char[strlen(defn) + 1]; - strcpy(val, defn); + val = defn; codePage = codePage_; Surface *surfaceMeasure = Surface::Allocate(technology); if (!surfaceMeasure) @@ -275,7 +271,7 @@ PRectangle CallTip::CallTipStart(int pos, Point pt, int textHeight, const char * // Only support \n here - simply means container must avoid \r! int numLines = 1; const char *newline; - const char *look = val; + const char *look = val.c_str(); rectUp = PRectangle(0,0,0,0); rectDown = PRectangle(0,0,0,0); offsetMain = insetX; // changed to right edge of any arrows diff --git a/src/CallTip.h b/src/CallTip.h index fdc4db86f..eafaa2f2e 100644 --- a/src/CallTip.h +++ b/src/CallTip.h @@ -17,7 +17,7 @@ namespace Scintilla { class CallTip { int startHighlight; // character offset to start and... int endHighlight; // ...end of highlighted text - char *val; + std::string val; Font font; PRectangle rectUp; // rectangle of last up angle in the tip PRectangle rectDown; // rectangle of last down arrow in the tip |