From 9aa2dfc9a366df851d1eea05a58d5e171adcb8fd Mon Sep 17 00:00:00 2001 From: Neil Date: Thu, 3 May 2018 07:44:56 +1000 Subject: Simplify PropSetSimple, avoid casts, use nullptr. --- lexlib/PropSetSimple.cxx | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'lexlib/PropSetSimple.cxx') diff --git a/lexlib/PropSetSimple.cxx b/lexlib/PropSetSimple.cxx index cbcbac5bd..ba76019be 100644 --- a/lexlib/PropSetSimple.cxx +++ b/lexlib/PropSetSimple.cxx @@ -17,27 +17,31 @@ using namespace Scintilla; +namespace { + typedef std::map mapss; +mapss *PropsFromPointer(void *impl) { + return static_cast(impl); +} + +} + PropSetSimple::PropSetSimple() { mapss *props = new mapss; impl = static_cast(props); } PropSetSimple::~PropSetSimple() { - mapss *props = static_cast(impl); + mapss *props = PropsFromPointer(impl); delete props; impl = 0; } -void PropSetSimple::Set(const char *key, const char *val, int lenKey, int lenVal) { - mapss *props = static_cast(impl); +void PropSetSimple::Set(const char *key, const char *val, size_t lenKey, size_t lenVal) { + mapss *props = PropsFromPointer(impl); if (!*key) // Empty keys are not supported return; - if (lenKey == -1) - lenKey = static_cast(strlen(key)); - if (lenVal == -1) - lenVal = static_cast(strlen(val)); (*props)[std::string(key, lenKey)] = std::string(val, lenVal); } @@ -53,10 +57,10 @@ void PropSetSimple::Set(const char *keyVal) { endVal++; const char *eqAt = strchr(keyVal, '='); if (eqAt) { - Set(keyVal, eqAt + 1, static_cast(eqAt-keyVal), - static_cast(endVal - eqAt - 1)); + Set(keyVal, eqAt + 1, eqAt-keyVal, + endVal - eqAt - 1); } else if (*keyVal) { // No '=' so assume '=1' - Set(keyVal, "1", static_cast(endVal-keyVal), 1); + Set(keyVal, "1", endVal-keyVal, 1); } } @@ -71,7 +75,7 @@ void PropSetSimple::SetMultiple(const char *s) { } const char *PropSetSimple::Get(const char *key) const { - mapss *props = static_cast(impl); + mapss *props = PropsFromPointer(impl); mapss::const_iterator keyPos = props->find(std::string(key)); if (keyPos != props->end()) { return keyPos->second.c_str(); @@ -86,7 +90,7 @@ const char *PropSetSimple::Get(const char *key) const { // for that, through a recursive function and a simple chain of pointers. struct VarChain { - VarChain(const char *var_=NULL, const VarChain *link_=NULL): var(var_), link(link_) {} + VarChain(const char *var_=nullptr, const VarChain *link_= nullptr): var(var_), link(link_) {} bool contains(const char *testVar) const { return (var && (0 == strcmp(var, testVar))) -- cgit v1.2.3