diff options
Diffstat (limited to 'src/CBot/CBotString.cpp')
-rw-r--r-- | src/CBot/CBotString.cpp | 51 |
1 files changed, 26 insertions, 25 deletions
diff --git a/src/CBot/CBotString.cpp b/src/CBot/CBotString.cpp index 1b42c23..7223e6f 100644 --- a/src/CBot/CBotString.cpp +++ b/src/CBot/CBotString.cpp @@ -24,7 +24,7 @@ #include <algorithm> //Map is filled with id-string pars that are needed for CBot language parsing -const std::map<EID, char *> CBotString::s_keywordString = +const std::map<EID,const char *> CBotString::s_keywordString = { {ID_IF, "if"}, {ID_ELSE, "else"}, @@ -70,7 +70,7 @@ const std::map<EID, char *> CBotString::s_keywordString = {ID_CLOSEPAR, ")"}, {ID_OPBLK, "{"}, {ID_CLBLK, "}"}, - {ID_SEP, "},"}, + {ID_SEP, ";"}, {ID_COMMA, ","}, {ID_DOTS, ":"}, {ID_DOT, "."}, @@ -138,7 +138,7 @@ CBotString::CBotString(const char* p) m_ptr = NULL; if (m_lg>0) { - m_ptr = (char*)malloc(m_lg+1); + m_ptr = static_cast<char*>(malloc(m_lg+1)); strcpy(m_ptr, p); } } @@ -150,7 +150,7 @@ CBotString::CBotString(const CBotString& srcString) m_ptr = NULL; if (m_lg>0) { - m_ptr = (char*)malloc(m_lg+1); + m_ptr = static_cast<char*>(malloc(m_lg+1)); strcpy(m_ptr, srcString.m_ptr); } } @@ -158,7 +158,7 @@ CBotString::CBotString(const CBotString& srcString) -int CBotString::GivLength() +int CBotString::GetLength() { if (m_ptr == NULL) return 0; return strlen( m_ptr ); @@ -170,7 +170,7 @@ CBotString CBotString::Left(int nCount) const { char chain[2000]; - size_t i; + int i; for (i = 0; i < m_lg && i < nCount && i < 1999; ++i) { chain[i] = m_ptr[i]; @@ -187,8 +187,8 @@ CBotString CBotString::Right(int nCount) const int i = m_lg - nCount; if ( i < 0 ) i = 0; - size_t j; - for (size_t j = 0 ; i < m_lg && i < 1999; ++i) + int j; + for (int j = 0 ; i < m_lg && i < 1999; ++i) { chain[j++] = m_ptr[i]; } @@ -201,7 +201,7 @@ CBotString CBotString::Mid(int nFirst, int nCount) const { char chain[2000]; - size_t i; + int i; for (i = nFirst; i < m_lg && i < 1999 && i <= nFirst + nCount; ++i) { chain[i] = m_ptr[i]; @@ -215,7 +215,7 @@ CBotString CBotString::Mid(int nFirst) const { char chain[2000]; - size_t i; + int i; for (i = nFirst; i < m_lg && i < 1999 ; ++i) { chain[i] = m_ptr[i]; @@ -228,7 +228,7 @@ CBotString CBotString::Mid(int nFirst) const int CBotString::Find(const char c) { - for (size_t i = 0; i < m_lg; ++i) + for (int i = 0; i < m_lg; ++i) { if (m_ptr[i] == c) return i; } @@ -239,9 +239,9 @@ int CBotString::Find(const char * lpsz) { int l = strlen(lpsz); - for (size_t i = 0; i <= m_lg-l; ++i) + for (size_t i = 0; static_cast<int>(i) <= m_lg-l; ++i) { - for (size_t j = 0; j < l; ++j) + for (size_t j = 0; static_cast<int>(j) < l; ++j) { if (m_ptr[i+j] != lpsz[j]) goto bad; } @@ -285,7 +285,7 @@ CBotString CBotString::Mid(int start, int lg) if ( lg < 0 ) lg = m_lg - start; - char* p = (char*)malloc(m_lg+1); + char* p = static_cast<char*>(malloc(m_lg+1)); strcpy(p, m_ptr+start); p[lg] = 0; @@ -296,7 +296,7 @@ CBotString CBotString::Mid(int start, int lg) void CBotString::MakeUpper() { - for (size_t i = 0; i < m_lg && i < 1999 ; ++i) + for (size_t i = 0; static_cast<int>(i) < m_lg && static_cast<int>(i) < 1999 ; ++i) { char c = m_ptr[i]; if ( c >= 'a' && c <= 'z' ) m_ptr[i] = c - 'a' + 'A'; @@ -305,7 +305,7 @@ void CBotString::MakeUpper() void CBotString::MakeLower() { - for (size_t i = 0; i < m_lg && i < 1999 ; ++i) + for (size_t i = 0; static_cast<int>(i) < m_lg && static_cast<int>(i) < 1999 ; ++i) { char c = m_ptr[i]; if ( c >= 'A' && c <= 'Z' ) m_ptr[i] = c - 'A' + 'a'; @@ -315,14 +315,14 @@ void CBotString::MakeLower() bool CBotString::LoadString(unsigned int id) { const char * str = NULL; - str = MapIdToString((EID)id); + str = MapIdToString(static_cast<EID>(id)); if (m_ptr != NULL) free(m_ptr); m_lg = strlen(str); m_ptr = NULL; if (m_lg > 0) { - m_ptr = (char*)malloc(m_lg+1); + m_ptr = static_cast<char*>(malloc(m_lg+1)); strcpy(m_ptr, str); return true; } @@ -339,7 +339,7 @@ const CBotString& CBotString::operator=(const CBotString& stringSrc) if (m_lg > 0) { - m_ptr = (char*)malloc(m_lg+1); + m_ptr = static_cast<char*>(malloc(m_lg+1)); strcpy(m_ptr, stringSrc.m_ptr); } @@ -355,7 +355,7 @@ CBotString operator+(const CBotString& string, const char * lpsz) const CBotString& CBotString::operator+(const CBotString& stringSrc) { - char* p = (char*)malloc(m_lg+stringSrc.m_lg+1); + char* p = static_cast<char*>(malloc(m_lg+stringSrc.m_lg+1)); strcpy(p, m_ptr); char* pp = p + m_lg; @@ -374,7 +374,7 @@ const CBotString& CBotString::operator=(const char ch) m_lg = 1; - m_ptr = (char*)malloc(2); + m_ptr = static_cast<char*>(malloc(2)); m_ptr[0] = ch; m_ptr[1] = 0; @@ -392,7 +392,7 @@ const CBotString& CBotString::operator=(const char* pString) if (m_lg != 0) { - m_ptr = (char*)malloc(m_lg+1); + m_ptr = static_cast<char*>(malloc(m_lg+1)); strcpy(m_ptr, pString); } } @@ -403,7 +403,7 @@ const CBotString& CBotString::operator=(const char* pString) const CBotString& CBotString::operator+=(const char ch) { - char* p = (char*)malloc(m_lg+2); + char* p = static_cast<char*>(malloc(m_lg+2)); if (m_ptr!=NULL) strcpy(p, m_ptr); p[m_lg++] = ch; @@ -418,7 +418,7 @@ const CBotString& CBotString::operator+=(const char ch) const CBotString& CBotString::operator+=(const CBotString& str) { - char* p = (char*)malloc(m_lg+str.m_lg+1); + char* p = static_cast<char*>(malloc(m_lg+str.m_lg+1)); strcpy(p, m_ptr); char* pp = p + m_lg; @@ -549,7 +549,7 @@ CBotStringArray::~CBotStringArray() } -int CBotStringArray::GivSize() +int CBotStringArray::GetSize() { return m_nSize; } @@ -618,6 +618,7 @@ void CBotStringArray::SetSize(int nNewSize) // shrink to nothing DestructElements(m_pData, m_nSize); +// delete[] static_cast<unsigned char *>(m_pData); delete[] (unsigned char *)m_pData; m_pData = NULL; m_nSize = m_nMaxSize = 0; |