[colobot] 159/377: Refactored CBotString and const char* to std::string in CBot engine
Didier Raboud
odyx at moszumanska.debian.org
Wed Mar 30 13:34:10 UTC 2016
This is an automated email from the git hooks/post-receive script.
odyx pushed a commit to branch debian/master
in repository colobot.
commit 9ec61d93e5a432e93f86666628cc084361d13089
Author: krzys-h <krzys_h at interia.pl>
Date: Sun Dec 20 16:19:10 2015 +0100
Refactored CBotString and const char* to std::string in CBot engine
A lot of changes, so it needs lots of testing
---
src/CBot/CBot.h | 1 -
src/CBot/CBotCStack.cpp | 6 +-
src/CBot/CBotCStack.h | 1 +
src/CBot/CBotCall.cpp | 22 +-
src/CBot/CBotCall.h | 24 +-
src/CBot/CBotCallMethode.cpp | 14 +-
src/CBot/CBotCallMethode.h | 17 +-
src/CBot/CBotClass.cpp | 48 ++--
src/CBot/CBotClass.h | 43 ++--
src/CBot/CBotDefParam.cpp | 4 +-
src/CBot/CBotDefParam.h | 4 +-
src/CBot/CBotFileUtils.cpp | 7 +-
src/CBot/CBotFileUtils.h | 6 +-
src/CBot/CBotInstr/CBotBreak.cpp | 2 +-
src/CBot/CBotInstr/CBotBreak.h | 2 +-
src/CBot/CBotInstr/CBotClassInst.cpp | 8 +-
src/CBot/CBotInstr/CBotDo.h | 2 +-
src/CBot/CBotInstr/CBotExprAlpha.cpp | 4 +-
src/CBot/CBotInstr/CBotExprNum.cpp | 8 +-
src/CBot/CBotInstr/CBotFor.h | 2 +-
src/CBot/CBotInstr/CBotFunction.cpp | 37 ++--
src/CBot/CBotInstr/CBotFunction.h | 18 +-
src/CBot/CBotInstr/CBotInstr.cpp | 16 +-
src/CBot/CBotInstr/CBotInstr.h | 10 +-
src/CBot/CBotInstr/CBotInstrMethode.h | 4 +-
src/CBot/CBotInstr/CBotReturn.cpp | 2 +-
src/CBot/CBotInstr/CBotWhile.h | 2 +-
src/CBot/CBotKeywordStrings.cpp | 7 +-
src/CBot/CBotKeywordStrings.h | 4 +-
src/CBot/CBotProgram.cpp | 26 +--
src/CBot/CBotProgram.h | 25 +--
src/CBot/CBotStack.cpp | 33 +--
src/CBot/CBotStack.h | 16 +-
src/CBot/CBotString.cpp | 236 --------------------
src/CBot/CBotString.h | 194 -----------------
src/CBot/CBotToken.cpp | 61 +++---
src/CBot/CBotToken.h | 32 ++-
src/CBot/CBotTypResult.cpp | 2 +-
src/CBot/CBotTypResult.h | 3 +-
src/CBot/CBotUtils.cpp | 50 +----
src/CBot/CBotUtils.h | 42 +---
src/CBot/CBotVar/CBotVar.cpp | 25 ++-
src/CBot/CBotVar/CBotVar.h | 26 ++-
src/CBot/CBotVar/CBotVarArray.cpp | 4 +-
src/CBot/CBotVar/CBotVarArray.h | 2 +-
src/CBot/CBotVar/CBotVarBoolean.cpp | 8 +-
src/CBot/CBotVar/CBotVarBoolean.h | 4 +-
src/CBot/CBotVar/CBotVarClass.cpp | 12 +-
src/CBot/CBotVar/CBotVarClass.h | 4 +-
src/CBot/CBotVar/CBotVarFloat.cpp | 6 +-
src/CBot/CBotVar/CBotVarFloat.h | 4 +-
src/CBot/CBotVar/CBotVarInt.cpp | 22 +-
src/CBot/CBotVar/CBotVarInt.h | 6 +-
src/CBot/CBotVar/CBotVarPointer.cpp | 10 +-
src/CBot/CBotVar/CBotVarPointer.h | 4 +-
src/CBot/CBotVar/CBotVarString.cpp | 6 +-
src/CBot/CBotVar/CBotVarString.h | 6 +-
src/CBot/CMakeLists.txt | 4 +-
src/CBot/StringFunctions.cpp | 38 ++--
src/script/script.cpp | 50 ++---
src/script/scriptfunc.cpp | 72 +++---
test/cbot/console/main.cpp | 7 +-
test/unit/CBot/CBotString_test.cpp | 399 ----------------------------------
test/unit/CMakeLists.txt | 1 -
64 files changed, 421 insertions(+), 1344 deletions(-)
diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h
index 7832144..4ba45b0 100644
--- a/src/CBot/CBot.h
+++ b/src/CBot/CBot.h
@@ -25,7 +25,6 @@
// Modules inlcude
#include "CBot/CBotFileUtils.h"
-#include "CBot/CBotString.h"
#include "CBot/CBotClass.h"
#include "CBot/CBotToken.h"
#include "CBot/CBotProgram.h"
diff --git a/src/CBot/CBotCStack.cpp b/src/CBot/CBotCStack.cpp
index ed56e22..df1f563 100644
--- a/src/CBot/CBotCStack.cpp
+++ b/src/CBot/CBotCStack.cpp
@@ -174,7 +174,7 @@ void CBotCStack::SetType(CBotTypResult& type)
CBotVar* CBotCStack::FindVar(CBotToken* &pToken)
{
CBotCStack* p = this;
- CBotString name = pToken->GetString();
+ std::string name = pToken->GetString();
while (p != nullptr)
{
@@ -332,7 +332,7 @@ void CBotCStack::AddVar(CBotVar* pVar)
bool CBotCStack::CheckVarLocal(CBotToken* &pToken)
{
CBotCStack* p = this;
- CBotString name = pToken->GetString();
+ std::string name = pToken->GetString();
while (p != nullptr)
{
@@ -373,7 +373,7 @@ CBotTypResult CBotCStack::CompileCall(CBotToken* &p, CBotVar** ppVars, long& nId
////////////////////////////////////////////////////////////////////////////////
bool CBotCStack::CheckCall(CBotToken* &pToken, CBotDefParam* pParam)
{
- CBotString name = pToken->GetString();
+ std::string name = pToken->GetString();
if ( CBotCall::CheckCall(name) ) return true;
diff --git a/src/CBot/CBotCStack.h b/src/CBot/CBotCStack.h
index e6210f8..1bdfa90 100644
--- a/src/CBot/CBotCStack.h
+++ b/src/CBot/CBotCStack.h
@@ -27,6 +27,7 @@
// Global include
class CBotInstr;
class CBotDefParam;
+class CBotToken;
/*!
* \brief The CBotCStack class Management of the stack of compilation.
diff --git a/src/CBot/CBotCall.cpp b/src/CBot/CBotCall.cpp
index 13f1e85..f391c3d 100644
--- a/src/CBot/CBotCall.cpp
+++ b/src/CBot/CBotCall.cpp
@@ -40,9 +40,9 @@ CBotCall* CBotCall::m_ListCalls = nullptr;
void* CBotCall::m_pUser = nullptr;
////////////////////////////////////////////////////////////////////////////////
-CBotCall::CBotCall(const char* name,
- bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser),
- CBotTypResult rCompile (CBotVar* &pVar, void* pUser))
+CBotCall::CBotCall(const std::string& name,
+ bool rExec(CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser),
+ CBotTypResult rCompile(CBotVar*& pVar, void* pUser))
{
m_name = name;
m_rExec = rExec;
@@ -65,9 +65,9 @@ void CBotCall::Free()
}
////////////////////////////////////////////////////////////////////////////////
-bool CBotCall::AddFunction(const char* name,
- bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser),
- CBotTypResult rCompile (CBotVar* &pVar, void* pUser))
+bool CBotCall::AddFunction(const std::string& name,
+ bool rExec(CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser),
+ CBotTypResult rCompile(CBotVar*& pVar, void* pUser))
{
CBotCall* p = m_ListCalls;
CBotCall* pp = nullptr;
@@ -102,7 +102,7 @@ CBotTypResult CBotCall::CompileCall(CBotToken* &p, CBotVar** ppVar, CBotCStack*
{
nIdent = 0;
CBotCall* pt = m_ListCalls;
- CBotString name = p->GetString();
+ std::string name = p->GetString();
while ( pt != nullptr )
{
@@ -136,7 +136,7 @@ void CBotCall::SetPUser(void* pUser)
}
////////////////////////////////////////////////////////////////////////////////
-bool CBotCall::CheckCall(const char* name)
+bool CBotCall::CheckCall(const std::string& name)
{
CBotCall* p = m_ListCalls;
@@ -149,7 +149,7 @@ bool CBotCall::CheckCall(const char* name)
}
////////////////////////////////////////////////////////////////////////////////
-CBotString CBotCall::GetName()
+std::string CBotCall::GetName()
{
return m_name;
}
@@ -178,7 +178,7 @@ int CBotCall::DoCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBotStack*
if ( token != nullptr )
{
- CBotString name = token->GetString();
+ std::string name = token->GetString();
while ( pt != nullptr )
{
if ( pt->m_name == name )
@@ -260,7 +260,7 @@ bool CBotCall::RestoreCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBot
CBotCall* pt = m_ListCalls;
{
- CBotString name = token->GetString();
+ std::string name = token->GetString();
while ( pt != nullptr )
{
if ( pt->m_name == name )
diff --git a/src/CBot/CBotCall.h b/src/CBot/CBotCall.h
index bb94c23..3dcb3aa 100644
--- a/src/CBot/CBotCall.h
+++ b/src/CBot/CBotCall.h
@@ -20,14 +20,18 @@
#pragma once
// Modules inlcude
-#include "CBot/CBotString.h"
// Local include
// Global include
+#include <string>
// Forward declaration
class CBotStack;
+class CBotCStack;
+class CBotVar;
+class CBotTypResult;
+class CBotToken;
#define STACKRUN 1 //! \def return execution directly on a suspended routine
@@ -44,9 +48,9 @@ public:
* \param rExec
* \param rCompile
*/
- CBotCall(const char* name,
- bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser),
- CBotTypResult rCompile (CBotVar* &pVar, void* pUser));
+ CBotCall(const std::string& name,
+ bool rExec(CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser),
+ CBotTypResult rCompile(CBotVar*& pVar, void* pUser));
/*!
* \brief ~CBotCall
@@ -60,9 +64,9 @@ public:
* \param rCompile
* \return
*/
- static bool AddFunction(const char* name,
- bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser),
- CBotTypResult rCompile (CBotVar* &pVar, void* pUser));
+ static bool AddFunction(const std::string& name,
+ bool rExec(CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser),
+ CBotTypResult rCompile(CBotVar*& pVar, void* pUser));
/*!
* \brief CompileCall Is acceptable by a call procedure name and given
@@ -80,7 +84,7 @@ public:
* \param name
* \return
*/
- static bool CheckCall(const char* name);
+ static bool CheckCall(const std::string& name);
/*!
* \brief DoCall
@@ -117,7 +121,7 @@ public:
* \brief GetName
* \return
*/
- CBotString GetName();
+ std::string GetName();
/*!
* \brief Next
@@ -142,7 +146,7 @@ private:
static void* m_pUser;
long m_nFuncIdent;
- CBotString m_name;
+ std::string m_name;
bool (*m_rExec) (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser);
CBotTypResult (*m_rComp) (CBotVar* &pVar, void* pUser);
CBotCall* m_next;
diff --git a/src/CBot/CBotCallMethode.cpp b/src/CBot/CBotCallMethode.cpp
index d38da85..b3512f6 100644
--- a/src/CBot/CBotCallMethode.cpp
+++ b/src/CBot/CBotCallMethode.cpp
@@ -32,9 +32,9 @@
////////////////////////////////////////////////////////////////////////////////
-CBotCallMethode::CBotCallMethode(const char* name,
- bool rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user),
- CBotTypResult rCompile (CBotVar* pThis, CBotVar* &pVar))
+CBotCallMethode::CBotCallMethode(const std::string& name,
+ bool rExec(CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user),
+ CBotTypResult rCompile(CBotVar* pThis, CBotVar*& pVar))
{
m_name = name;
m_rExec = rExec;
@@ -51,7 +51,7 @@ CBotCallMethode::~CBotCallMethode()
}
////////////////////////////////////////////////////////////////////////////////
-CBotTypResult CBotCallMethode::CompileCall(const char* name,
+CBotTypResult CBotCallMethode::CompileCall(const std::string& name,
CBotVar* pThis,
CBotVar** ppVar,
CBotCStack* pStack,
@@ -82,7 +82,7 @@ CBotTypResult CBotCallMethode::CompileCall(const char* name,
}
////////////////////////////////////////////////////////////////////////////////
-CBotString CBotCallMethode::GetName()
+std::string CBotCallMethode::GetName()
{
return m_name;
}
@@ -104,10 +104,10 @@ void CBotCallMethode::AddNext(CBotCallMethode* pt)
////////////////////////////////////////////////////////////////////////////////
int CBotCallMethode::DoCall(long& nIdent,
- const char* name,
+ const std::string& name,
CBotVar* pThis,
CBotVar** ppVars,
- CBotVar* &pResult,
+ CBotVar*& pResult,
CBotStack* pStack,
CBotToken* pToken)
{
diff --git a/src/CBot/CBotCallMethode.h b/src/CBot/CBotCallMethode.h
index 445e259..bdccbb9 100644
--- a/src/CBot/CBotCallMethode.h
+++ b/src/CBot/CBotCallMethode.h
@@ -21,7 +21,6 @@
// Modules inlcude
#include "CBot/CBotTypResult.h"
-#include "CBot/CBotString.h"
// Local include
@@ -45,9 +44,9 @@ public:
* \param rExec
* \param rCompile
*/
- CBotCallMethode(const char* name,
- bool rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user),
- CBotTypResult rCompile (CBotVar* pThis, CBotVar* &pVar));
+ CBotCallMethode(const std::string& name,
+ bool rExec(CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user),
+ CBotTypResult rCompile(CBotVar* pThis, CBotVar*& pVar));
/*!
* \brief ~CBotCallMethode
@@ -64,7 +63,7 @@ public:
* \param nIdent
* \return
*/
- CBotTypResult CompileCall(const char* name,
+ CBotTypResult CompileCall(const std::string& name,
CBotVar* pThis,
CBotVar** ppVars,
CBotCStack* pStack,
@@ -82,10 +81,10 @@ public:
* \return
*/
int DoCall(long& nIdent,
- const char* name,
+ const std::string& name,
CBotVar* pThis,
CBotVar** ppVars,
- CBotVar* &pResult,
+ CBotVar*& pResult,
CBotStack* pStack,
CBotToken* pFunc);
@@ -93,7 +92,7 @@ public:
* \brief GetName
* \return
*/
- CBotString GetName();
+ std::string GetName();
/*!
* \brief Next
@@ -108,7 +107,7 @@ public:
void AddNext(CBotCallMethode* p);
private:
- CBotString m_name;
+ std::string m_name;
bool (*m_rExec) (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user);
CBotTypResult (*m_rComp) (CBotVar* pThis, CBotVar* &pVar);
CBotCallMethode* m_next;
diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp
index 8e580bb..e7d6719 100644
--- a/src/CBot/CBotClass.cpp
+++ b/src/CBot/CBotClass.cpp
@@ -46,7 +46,7 @@
CBotClass* CBotClass::m_ExClass = nullptr;
////////////////////////////////////////////////////////////////////////////////
-CBotClass::CBotClass(const char* name,
+CBotClass::CBotClass(const std::string& name,
CBotClass* pPapa,
bool bIntrinsic)
{
@@ -96,7 +96,7 @@ CBotClass::~CBotClass()
}
////////////////////////////////////////////////////////////////////////////////
-CBotClass* CBotClass::Create(const char* name,
+CBotClass* CBotClass::Create(const std::string& name,
CBotClass* parent,
bool intrinsic)
{
@@ -209,11 +209,11 @@ void CBotClass::FreeLock(CBotProgram* p)
}
////////////////////////////////////////////////////////////////////////////////
-bool CBotClass::AddItem(CBotString name,
+bool CBotClass::AddItem(std::string name,
CBotTypResult type,
int mPrivate)
{
- CBotToken token(name, CBotString());
+ CBotToken token(name, std::string());
CBotClass* pClass = type.GetClass();
CBotVar* pVar = CBotVar::Create( name, type );
@@ -255,7 +255,7 @@ void CBotClass::AddNext(CBotClass* pClass)
}
////////////////////////////////////////////////////////////////////////////////
-CBotString CBotClass::GetName()
+std::string CBotClass::GetName()
{
return m_name;
}
@@ -286,7 +286,7 @@ CBotVar* CBotClass::GetVar()
}
////////////////////////////////////////////////////////////////////////////////
-CBotVar* CBotClass::GetItem(const char* name)
+CBotVar* CBotClass::GetItem(const std::string& name)
{
CBotVar* p = m_pVar;
@@ -326,7 +326,7 @@ CBotClass* CBotClass::Find(CBotToken* &pToken)
}
////////////////////////////////////////////////////////////////////////////////
-CBotClass* CBotClass::Find(const char* name)
+CBotClass* CBotClass::Find(const std::string& name)
{
CBotClass* p = m_ExClass;
@@ -340,9 +340,9 @@ CBotClass* CBotClass::Find(const char* name)
}
////////////////////////////////////////////////////////////////////////////////
-bool CBotClass::AddFunction(const char* name,
- bool rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user),
- CBotTypResult rCompile (CBotVar* pThis, CBotVar* &pVar))
+bool CBotClass::AddFunction(const std::string& name,
+ bool rExec(CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user),
+ CBotTypResult rCompile(CBotVar* pThis, CBotVar*& pVar))
{
// stores pointers to the two functions
CBotCallMethode* p = m_pCalls;
@@ -377,7 +377,7 @@ bool CBotClass::AddUpdateFunc( void rMaj ( CBotVar* pThis, void* pUser ) )
}
////////////////////////////////////////////////////////////////////////////////
-CBotTypResult CBotClass::CompileMethode(const char* name,
+CBotTypResult CBotClass::CompileMethode(const std::string& name,
CBotVar* pThis,
CBotVar** ppParams,
CBotCStack* pStack,
@@ -400,11 +400,11 @@ CBotTypResult CBotClass::CompileMethode(const char* name,
////////////////////////////////////////////////////////////////////////////////
bool CBotClass::ExecuteMethode(long& nIdent,
- const char* name,
+ const std::string& name,
CBotVar* pThis,
CBotVar** ppParams,
- CBotVar* &pResult,
- CBotStack* &pStack,
+ CBotVar*& pResult,
+ CBotStack*& pStack,
CBotToken* pToken)
{
int ret = m_pCalls->DoCall(nIdent, name, pThis, ppParams, pResult, pStack, pToken);
@@ -424,10 +424,10 @@ bool CBotClass::ExecuteMethode(long& nIdent,
////////////////////////////////////////////////////////////////////////////////
void CBotClass::RestoreMethode(long& nIdent,
- const char* name,
+ const std::string& name,
CBotVar* pThis,
CBotVar** ppParams,
- CBotStack* &pStack)
+ CBotStack*& pStack)
{
m_pMethod->RestoreCall(nIdent, name, pThis, ppParams, pStack, this);
}
@@ -472,7 +472,7 @@ bool CBotClass::SaveStaticState(FILE* pf)
////////////////////////////////////////////////////////////////////////////////
bool CBotClass::RestoreStaticState(FILE* pf)
{
- CBotString ClassName, VarName;
+ std::string ClassName, VarName;
CBotClass* pClass;
unsigned short w;
@@ -511,7 +511,7 @@ bool CBotClass::RestoreStaticState(FILE* pf)
bool CBotClass::CheckCall(CBotToken* &pToken,
CBotDefParam* pParam)
{
- CBotString name = pToken->GetString();
+ std::string name = pToken->GetString();
if ( CBotCall::CheckCall(name) ) return true;
@@ -541,7 +541,7 @@ CBotClass* CBotClass::Compile1(CBotToken* &p, CBotCStack* pStack)
if ( !IsOfType(p, ID_CLASS) ) return nullptr;
- CBotString name = p->GetString();
+ std::string name = p->GetString();
CBotClass* pOld = CBotClass::Find(name);
if ( pOld != nullptr && pOld->m_IsDef )
@@ -556,7 +556,7 @@ CBotClass* CBotClass::Compile1(CBotToken* &p, CBotCStack* pStack)
CBotClass* pPapa = nullptr;
if ( IsOfType( p, ID_EXTENDS ) )
{
- CBotString name = p->GetString();
+ std::string name = p->GetString();
pPapa = CBotClass::Find(name);
if (!IsOfType(p, TokenTypVar) || pPapa == nullptr )
@@ -680,7 +680,7 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond)
CBotCStack* pile = pStack->TokenStack(nullptr, true);
// make "this" known
- CBotToken TokenThis(CBotString("this"), CBotString());
+ CBotToken TokenThis(std::string("this"), std::string());
CBotVar* pThis = CBotVar::Create(&TokenThis, CBotTypResult( CBotTypClass, this ) );
pThis->SetUniqNum(-2);
pile->AddVar(pThis);
@@ -688,7 +688,7 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond)
if ( m_pParent )
{
// makes "super" known
- CBotToken TokenSuper(CBotString("super"), CBotString());
+ CBotToken TokenSuper(std::string("super"), std::string());
CBotVar* pThis = CBotVar::Create(&TokenSuper, CBotTypResult( CBotTypClass, m_pParent ) );
pThis->SetUniqNum(-3);
pile->AddVar(pThis);
@@ -796,7 +796,7 @@ CBotClass* CBotClass::Compile(CBotToken* &p, CBotCStack* pStack)
if ( !IsOfType(p, ID_PUBLIC) ) return nullptr;
if ( !IsOfType(p, ID_CLASS) ) return nullptr;
- CBotString name = p->GetString();
+ std::string name = p->GetString();
// a name for the class is there?
if (IsOfType(p, TokenTypVar))
@@ -807,7 +807,7 @@ CBotClass* CBotClass::Compile(CBotToken* &p, CBotCStack* pStack)
if ( IsOfType( p, ID_EXTENDS ) )
{
// TODO: Not sure how correct is that - I have no idea how the precompilation (Compile1 method) works ~krzys_h
- CBotString name = p->GetString();
+ std::string name = p->GetString();
CBotClass* pPapa = CBotClass::Find(name);
if (!IsOfType(p, TokenTypVar) || pPapa == nullptr)
diff --git a/src/CBot/CBotClass.h b/src/CBot/CBotClass.h
index 69f3605..849a066 100644
--- a/src/CBot/CBotClass.h
+++ b/src/CBot/CBotClass.h
@@ -24,11 +24,10 @@
#include "CBot/CBotTypResult.h"
-#include "CBot/CBotString.h"
-
// Local include
// Global include
+#include <string>
// Forward declaration
class CBotVar;
@@ -38,6 +37,8 @@ class CBotFunction;
class CBotProgram;
class CBotStack;
class CBotDefParam;
+class CBotToken;
+class CBotCStack;
/*!
* \brief The CBotClass class Class to define new classes in the language CBOT
@@ -57,9 +58,9 @@ public:
* \param pParent
* \param bIntrinsic
*/
- CBotClass( const char* name,
- CBotClass* pParent,
- bool bIntrinsic = false );
+ CBotClass(const std::string& name,
+ CBotClass* pParent,
+ bool bIntrinsic = false);
/*!
* \brief CBotClass Destructor.
@@ -73,7 +74,7 @@ public:
* \param intrinsic
* \return
*/
- static CBotClass* Create(const char* name,
+ static CBotClass* Create(const std::string& name,
CBotClass* parent,
bool intrinsic = false);
@@ -86,9 +87,9 @@ public:
* \param rCompile
* \return
*/
- bool AddFunction(const char* name,
- bool rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user),
- CBotTypResult rCompile (CBotVar* pThis, CBotVar* &pVar));
+ bool AddFunction(const std::string& name,
+ bool rExec(CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user),
+ CBotTypResult rCompile(CBotVar* pThis, CBotVar*& pVar));
/*!
* \brief AddUpdateFunc Defines routine to be called to update the elements
@@ -106,7 +107,7 @@ public:
* \param mPrivate
* \return
*/
- bool AddItem(CBotString name, CBotTypResult type, int mPrivate = PR_PUBLIC);
+ bool AddItem(std::string name, CBotTypResult type, int mPrivate = PR_PUBLIC);
/*!
* \brief AddItem Adds an item by passing the pointer to an instance of a
@@ -126,7 +127,7 @@ public:
* \brief GetName Gives the name of the class.
* \return
*/
- CBotString GetName();
+ std::string GetName();
/*!
* \brief GetParent Gives the parent class (or nullptr).
@@ -153,7 +154,7 @@ public:
* \param name
* \return
*/
- static CBotClass* Find(const char* name);
+ static CBotClass* Find(const std::string& name);
/*!
* \brief GetVar Return the list of variables.
@@ -165,7 +166,7 @@ public:
* \param name
* \return
*/
- CBotVar* GetItem(const char* name);
+ CBotVar* GetItem(const std::string& name);
/*!
* \brief GetItemRef
@@ -184,7 +185,7 @@ public:
* \param nIdent
* \return
*/
- CBotTypResult CompileMethode(const char* name,
+ CBotTypResult CompileMethode(const std::string& name,
CBotVar* pThis,
CBotVar** ppParams,
CBotCStack* pStack,
@@ -202,11 +203,11 @@ public:
* \return
*/
bool ExecuteMethode(long& nIdent,
- const char* name,
+ const std::string& name,
CBotVar* pThis,
CBotVar** ppParams,
- CBotVar* &pResult,
- CBotStack* &pStack,
+ CBotVar*& pResult,
+ CBotStack*& pStack,
CBotToken* pToken);
/*!
@@ -218,10 +219,10 @@ public:
* \param pStack
*/
void RestoreMethode(long& nIdent,
- const char* name,
+ const std::string& name,
CBotVar* pThis,
CBotVar** ppParams,
- CBotStack* &pStack);
+ CBotStack*& pStack);
/*!
* \brief Compile Compiles a class declared by the user.
@@ -319,7 +320,7 @@ private:
//! Parent class.
CBotClass* m_pParent;
//! Name of this class.
- CBotString m_name;
+ std::string m_name;
//! Number of variables in the chain.
int m_nbVar;
//! Content of the class.
@@ -357,7 +358,7 @@ private:
For example, a routine which calculates the mean of a parameter list
-int cMean(CBotVar* &pVar, CBotString& ClassName)
+int cMean(CBotVar* &pVar, std::string& ClassName)
{
if ( pVar == nullptr ) return 6001; // there is no parameter!
while ( pVar != nullptr )
diff --git a/src/CBot/CBotDefParam.cpp b/src/CBot/CBotDefParam.cpp
index 7f13f89..2e48c06 100644
--- a/src/CBot/CBotDefParam.cpp
+++ b/src/CBot/CBotDefParam.cpp
@@ -196,9 +196,9 @@ CBotDefParam* CBotDefParam::GetNext()
}
////////////////////////////////////////////////////////////////////////////////
-CBotString CBotDefParam::GetParamString()
+std::string CBotDefParam::GetParamString()
{
- CBotString param;
+ std::string param;
param = m_typename;
param += ' ';
diff --git a/src/CBot/CBotDefParam.h b/src/CBot/CBotDefParam.h
index 433d18f..7006964 100644
--- a/src/CBot/CBotDefParam.h
+++ b/src/CBot/CBotDefParam.h
@@ -99,13 +99,13 @@ public:
* \brief GetParamString
* \return
*/
- CBotString GetParamString();
+ std::string GetParamString();
private:
//! Name of the parameter.
CBotToken m_token;
//! Type name.
- CBotString m_typename;
+ std::string m_typename;
//! Type of paramteter.
CBotTypResult m_type;
//! Next parameter.
diff --git a/src/CBot/CBotFileUtils.cpp b/src/CBot/CBotFileUtils.cpp
index c6e50e1..c3be54a 100644
--- a/src/CBot/CBotFileUtils.cpp
+++ b/src/CBot/CBotFileUtils.cpp
@@ -20,10 +20,9 @@
// Modules inlcude
#include "CBot/CBotFileUtils.h"
-#include "CBot/CBotString.h"
#include "CBot/CBotClass.h"
-
#include "CBot/CBotEnums.h"
+#include "CBot/CBotUtils.h"
// Local include
@@ -108,7 +107,7 @@ bool ReadLong(FILE* pf, long& w)
}
////////////////////////////////////////////////////////////////////////////////
-bool ReadString(FILE* pf, CBotString& s)
+bool ReadString(FILE* pf, std::string& s)
{
unsigned short w;
char buf[1000];
@@ -157,7 +156,7 @@ bool ReadType(FILE* pf, CBotTypResult &type)
if ( type.Eq( CBotTypClass ) )
{
- CBotString s;
+ std::string s;
if ( !ReadString(pf, s) ) return false;
type = CBotTypResult( w, s );
}
diff --git a/src/CBot/CBotFileUtils.h b/src/CBot/CBotFileUtils.h
index 75bfa43..534634a 100644
--- a/src/CBot/CBotFileUtils.h
+++ b/src/CBot/CBotFileUtils.h
@@ -24,11 +24,11 @@
// Local include
// Global include
- #include <cstdio>
+#include <cstdio>
+#include <string>
// Forward declaration
class CBotVar;
-class CBotString;
class CBotTypResult;
///////////////////////////////////////////////////////////////////////////////
@@ -137,7 +137,7 @@ bool ReadFloat(FILE* pf, float& w);
* \param s
* \return
*/
-bool ReadString(FILE* pf, CBotString& s);
+bool ReadString(FILE* pf, std::string& s);
/*!
* \brief WriteType
diff --git a/src/CBot/CBotInstr/CBotBreak.cpp b/src/CBot/CBotInstr/CBotBreak.cpp
index d97d65a..b0a308d 100644
--- a/src/CBot/CBotInstr/CBotBreak.cpp
+++ b/src/CBot/CBotInstr/CBotBreak.cpp
@@ -46,7 +46,7 @@ CBotInstr* CBotBreak::Compile(CBotToken* &p, CBotCStack* pStack)
if (!IsOfType(p, ID_BREAK, ID_CONTINUE)) return nullptr; // should never happen
- if ( !ChkLvl(CBotString(), type ) )
+ if ( !ChkLvl(std::string(), type ) )
{
pStack->SetError(TX_BREAK, pp);
return nullptr; // no object, the error is on the stack
diff --git a/src/CBot/CBotInstr/CBotBreak.h b/src/CBot/CBotInstr/CBotBreak.h
index 7961b0b..ce65b33 100644
--- a/src/CBot/CBotInstr/CBotBreak.h
+++ b/src/CBot/CBotInstr/CBotBreak.h
@@ -70,6 +70,6 @@ public:
private:
//! A label if there is
- CBotString m_label;
+ std::string m_label;
};
diff --git a/src/CBot/CBotInstr/CBotClassInst.cpp b/src/CBot/CBotInstr/CBotClassInst.cpp
index d66ba3e..e03fa3d 100644
--- a/src/CBot/CBotInstr/CBotClassInst.cpp
+++ b/src/CBot/CBotInstr/CBotClassInst.cpp
@@ -82,7 +82,7 @@ CBotInstr* CBotClassInst::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass*
inst = new CBotClassInst();
/// TODO Need to be revised and fixed after adding unit tests
- CBotToken token(pClass->GetName(), CBotString(), p->GetStart(), p->GetEnd());
+ CBotToken token(pClass->GetName(), std::string(), p->GetStart(), p->GetEnd());
inst->SetToken(&token);
CBotToken* vartoken = p;
@@ -137,7 +137,7 @@ CBotInstr* CBotClassInst::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass*
if ( inst->m_hasParams )
{
// the constructor is there?
-// CBotString noname;
+// std::string noname;
CBotTypResult r = pClass->CompileMethode(pClass->GetName(), var, ppVars, pStk, inst->m_nMethodeIdent);
delete pStk->TokenStack(); // releases the supplement stack
int typ = r.GetType();
@@ -242,7 +242,7 @@ bool CBotClassInst::Execute(CBotStack* &pj)
if ( pile->GetState()==0)
{
- CBotString name = m_var->m_token.GetString();
+ std::string name = m_var->m_token.GetString();
if ( bIntrincic )
{
pThis = CBotVar::Create(name, CBotTypResult( CBotTypIntrinsic, pClass ));
@@ -371,7 +371,7 @@ void CBotClassInst::RestoreState(CBotStack* &pj, bool bMain)
// creates the variable of type pointer to the object
{
- CBotString name = m_var->m_token.GetString();
+ std::string name = m_var->m_token.GetString();
pThis = pile->FindVar(name);
pThis->SetUniqNum((static_cast<CBotLeftExprVar*>(m_var))->m_nIdent); // its attribute a unique number
}
diff --git a/src/CBot/CBotInstr/CBotDo.h b/src/CBot/CBotInstr/CBotDo.h
index 8a80040..b2cb646 100644
--- a/src/CBot/CBotInstr/CBotDo.h
+++ b/src/CBot/CBotInstr/CBotDo.h
@@ -69,5 +69,5 @@ private:
//! Conditions
CBotInstr* m_Condition;
//! A label if there is
- CBotString m_label;
+ std::string m_label;
};
diff --git a/src/CBot/CBotInstr/CBotExprAlpha.cpp b/src/CBot/CBotInstr/CBotExprAlpha.cpp
index da68497..a5a415b 100644
--- a/src/CBot/CBotInstr/CBotExprAlpha.cpp
+++ b/src/CBot/CBotInstr/CBotExprAlpha.cpp
@@ -65,8 +65,8 @@ bool CBotExprAlpha::Execute(CBotStack* &pj)
CBotVar* var = CBotVar::Create(static_cast<CBotToken*>(nullptr), CBotTypString);
- CBotString chaine = m_token.GetString();
- chaine = chaine.Mid(1, chaine.GetLength()-2); // removes the quotes
+ std::string chaine = m_token.GetString();
+ chaine = chaine.substr(1, chaine.length()-2); // removes the quotes
var->SetValString(chaine); // value of the number
diff --git a/src/CBot/CBotInstr/CBotExprNum.cpp b/src/CBot/CBotInstr/CBotExprNum.cpp
index e9a72de..a4fcb8d 100644
--- a/src/CBot/CBotInstr/CBotExprNum.cpp
+++ b/src/CBot/CBotInstr/CBotExprNum.cpp
@@ -25,6 +25,8 @@
#include "CBot/CBotVar/CBotVar.h"
+#include "CBot/CBotUtils.h"
+
// Local include
// Global include
@@ -48,7 +50,7 @@ CBotInstr* CBotExprNum::Compile(CBotToken* &p, CBotCStack* pStack)
CBotExprNum* inst = new CBotExprNum();
inst->SetToken(p);
- CBotString s = p->GetString();
+ std::string s = p->GetString();
inst->m_numtype = CBotTypInt;
if (p->GetType() == TokenTypDef)
@@ -57,7 +59,7 @@ CBotInstr* CBotExprNum::Compile(CBotToken* &p, CBotCStack* pStack)
}
else
{
- if (s.Find('.') >= 0 || ( s.Find('x') < 0 && ( s.Find('e') >= 0 || s.Find('E') >= 0 ) ))
+ if (s.find('.') != std::string::npos || ( s.find('x') == std::string::npos && ( s.find_first_of("eE") != std::string::npos ) ))
{
inst->m_numtype = CBotTypFloat;
inst->m_valfloat = GetNumFloat(s);
@@ -88,7 +90,7 @@ bool CBotExprNum::Execute(CBotStack* &pj)
CBotVar* var = CBotVar::Create(static_cast<CBotToken*>(nullptr), m_numtype);
- CBotString nombre ;
+ std::string nombre ;
if (m_token.GetType() == TokenTypDef)
{
nombre = m_token.GetString();
diff --git a/src/CBot/CBotInstr/CBotFor.h b/src/CBot/CBotInstr/CBotFor.h
index 5b9a93e..949b28c 100644
--- a/src/CBot/CBotInstr/CBotFor.h
+++ b/src/CBot/CBotInstr/CBotFor.h
@@ -77,5 +77,5 @@ private:
//! Instructions
CBotInstr* m_Block;
//! A label if there is
- CBotString m_label;
+ std::string m_label;
};
diff --git a/src/CBot/CBotInstr/CBotFunction.cpp b/src/CBot/CBotInstr/CBotFunction.cpp
index f61328b..0744f70 100644
--- a/src/CBot/CBotInstr/CBotFunction.cpp
+++ b/src/CBot/CBotInstr/CBotFunction.cpp
@@ -182,7 +182,7 @@ CBotFunction* CBotFunction::Compile(CBotToken* &p, CBotCStack* pStack, CBotFunct
if ( IsOfType(p, ID_NOT) )
{
- CBotToken d(CBotString("~") + p->GetString());
+ CBotToken d(std::string("~") + p->GetString());
func->m_token = d;
}
@@ -207,7 +207,7 @@ CBotFunction* CBotFunction::Compile(CBotToken* &p, CBotCStack* pStack, CBotFunct
{
pStk->SetRetType(func->m_retTyp); // for knowledge what type returns
- if (!func->m_MasterClass.IsEmpty())
+ if (!func->m_MasterClass.empty())
{
// return "this" known
CBotVar* pThis = CBotVar::Create("this", CBotTypResult( CBotTypClass, func->m_MasterClass ));
@@ -356,7 +356,7 @@ bool CBotFunction::Execute(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInstance)
pile->IncState();
}
- if ( pile->GetState() == 1 && !m_MasterClass.IsEmpty() )
+ if ( pile->GetState() == 1 && !m_MasterClass.empty() )
{
// makes "this" known
CBotVar* pThis = nullptr;
@@ -411,7 +411,7 @@ void CBotFunction::RestoreState(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInst
m_Param->RestoreState(pile2, true); // parameters
- if ( !m_MasterClass.IsEmpty() )
+ if ( !m_MasterClass.empty() )
{
CBotVar* pThis = pile->FindVar("this");
pThis->SetInit(CBotVar::InitType::IS_POINTER);
@@ -431,7 +431,7 @@ void CBotFunction::AddNext(CBotFunction* p)
}
////////////////////////////////////////////////////////////////////////////////
-CBotTypResult CBotFunction::CompileCall(const char* name, CBotVar** ppVars, long& nIdent)
+CBotTypResult CBotFunction::CompileCall(const std::string& name, CBotVar** ppVars, long& nIdent)
{
nIdent = 0;
CBotTypResult type;
@@ -442,7 +442,8 @@ CBotTypResult CBotFunction::CompileCall(const char* name, CBotVar** ppVars, long
}
////////////////////////////////////////////////////////////////////////////////
-CBotFunction* CBotFunction::FindLocalOrPublic(long& nIdent, const char* name, CBotVar** ppVars, CBotTypResult& TypeOrError, bool bPublic)
+CBotFunction* CBotFunction::FindLocalOrPublic(long& nIdent, const std::string& name, CBotVar** ppVars,
+ CBotTypResult& TypeOrError, bool bPublic)
{
TypeOrError.SetType(TX_UNDEFCALL); // no routine of the name
CBotFunction* pt;
@@ -470,7 +471,7 @@ CBotFunction* CBotFunction::FindLocalOrPublic(long& nIdent, const char* name, CB
}
}
- if ( name == nullptr ) return nullptr;
+ if ( name.empty() ) return nullptr;
int delta = 99999; // seeks the lowest signature
CBotFunction* pFunc = nullptr; // the best function found
@@ -595,7 +596,7 @@ CBotFunction* CBotFunction::FindLocalOrPublic(long& nIdent, const char* name, CB
}
////////////////////////////////////////////////////////////////////////////////
-int CBotFunction::DoCall(long& nIdent, const char* name, CBotVar** ppVars, CBotStack* pStack, CBotToken* pToken)
+int CBotFunction::DoCall(long& nIdent, const std::string& name, CBotVar** ppVars, CBotStack* pStack, CBotToken* pToken)
{
CBotTypResult type;
CBotFunction* pt = nullptr;
@@ -617,7 +618,7 @@ int CBotFunction::DoCall(long& nIdent, const char* name, CBotVar** ppVars, CBotS
if ( pStk1->GetState() == 0 )
{
- if ( !pt->m_MasterClass.IsEmpty() )
+ if ( !pt->m_MasterClass.empty() )
{
CBotVar* pInstance = m_pProg->m_pInstance;
// make "this" known
@@ -665,7 +666,7 @@ int CBotFunction::DoCall(long& nIdent, const char* name, CBotVar** ppVars, CBotS
}
////////////////////////////////////////////////////////////////////////////////
-void CBotFunction::RestoreCall(long& nIdent, const char* name, CBotVar** ppVars, CBotStack* pStack)
+void CBotFunction::RestoreCall(long& nIdent, const std::string& name, CBotVar** ppVars, CBotStack* pStack)
{
CBotTypResult type;
CBotFunction* pt = nullptr;
@@ -699,7 +700,7 @@ void CBotFunction::RestoreCall(long& nIdent, const char* name, CBotVar** ppVars,
// preparing parameters on the stack
{
- if ( !pt->m_MasterClass.IsEmpty() )
+ if ( !pt->m_MasterClass.empty() )
{
// CBotVar* pInstance = m_pProg->m_pInstance;
// make "this" known
@@ -722,7 +723,8 @@ void CBotFunction::RestoreCall(long& nIdent, const char* name, CBotVar** ppVars,
}
////////////////////////////////////////////////////////////////////////////////
-int CBotFunction::DoCall(long& nIdent, const char* name, CBotVar* pThis, CBotVar** ppVars, CBotStack* pStack, CBotToken* pToken, CBotClass* pClass)
+int CBotFunction::DoCall(long& nIdent, const std::string& name, CBotVar* pThis, CBotVar** ppVars, CBotStack* pStack,
+ CBotToken* pToken, CBotClass* pClass)
{
CBotTypResult type;
CBotProgram* pProgCurrent = pStack->GetBotCall();
@@ -803,7 +805,8 @@ int CBotFunction::DoCall(long& nIdent, const char* name, CBotVar* pThis, CBotVar
}
////////////////////////////////////////////////////////////////////////////////
-void CBotFunction::RestoreCall(long& nIdent, const char* name, CBotVar* pThis, CBotVar** ppVars, CBotStack* pStack, CBotClass* pClass)
+void CBotFunction::RestoreCall(long& nIdent, const std::string& name, CBotVar* pThis, CBotVar** ppVars,
+ CBotStack* pStack, CBotClass* pClass)
{
CBotTypResult type;
CBotFunction* pt = FindLocalOrPublic(nIdent, name, ppVars, type);
@@ -851,17 +854,17 @@ bool CBotFunction::CheckParam(CBotDefParam* pParam)
}
////////////////////////////////////////////////////////////////////////////////
-CBotString CBotFunction::GetName()
+std::string CBotFunction::GetName()
{
return m_token.GetString();
}
////////////////////////////////////////////////////////////////////////////////
-CBotString CBotFunction::GetParams()
+std::string CBotFunction::GetParams()
{
- if ( m_Param == nullptr ) return CBotString("()");
+ if ( m_Param == nullptr ) return std::string("()");
- CBotString params = "( ";
+ std::string params = "( ";
CBotDefParam* p = m_Param; // list of parameters
while (p != nullptr)
diff --git a/src/CBot/CBotInstr/CBotFunction.h b/src/CBot/CBotInstr/CBotFunction.h
index f11015f..dbf9676 100644
--- a/src/CBot/CBotInstr/CBotFunction.h
+++ b/src/CBot/CBotInstr/CBotFunction.h
@@ -104,7 +104,7 @@ public:
* \param nIdent
* \return
*/
- CBotTypResult CompileCall(const char* name,
+ CBotTypResult CompileCall(const std::string& name,
CBotVar** ppVars,
long& nIdent);
@@ -118,7 +118,7 @@ public:
* \param bPublic
* \return
*/
- CBotFunction* FindLocalOrPublic(long& nIdent, const char* name,
+ CBotFunction* FindLocalOrPublic(long& nIdent, const std::string& name,
CBotVar** ppVars,
CBotTypResult& TypeOrError,
bool bPublic = true);
@@ -134,7 +134,7 @@ public:
*/
int DoCall(long& nIdent,
- const char* name,
+ const std::string& name,
CBotVar** ppVars,
CBotStack* pStack,
CBotToken* pToken);
@@ -147,7 +147,7 @@ public:
* \param pStack
*/
void RestoreCall(long& nIdent,
- const char* name,
+ const std::string& name,
CBotVar** ppVars,
CBotStack* pStack);
@@ -164,7 +164,7 @@ public:
* \return
*/
int DoCall(long& nIdent,
- const char* name,
+ const std::string& name,
CBotVar* pThis,
CBotVar** ppVars,
CBotStack* pStack,
@@ -181,7 +181,7 @@ public:
* \param pClass
*/
void RestoreCall(long& nIdent,
- const char* name,
+ const std::string& name,
CBotVar* pThis,
CBotVar** ppVars,
CBotStack* pStack,
@@ -204,13 +204,13 @@ public:
* \brief GetName
* \return
*/
- CBotString GetName();
+ std::string GetName();
/*!
* \brief GetParams
* \return
*/
- CBotString GetParams();
+ std::string GetParams();
/*!
* \brief IsPublic
@@ -263,7 +263,7 @@ private:
//! Extern function.
bool m_bExtern;
//! Name of the class we derive.
- CBotString m_MasterClass;
+ std::string m_MasterClass;
CBotProgram* m_pProg;
//! For the position of the word "extern".
CBotToken m_extern;
diff --git a/src/CBot/CBotInstr/CBotInstr.cpp b/src/CBot/CBotInstr/CBotInstr.cpp
index 66aff75..c08723e 100644
--- a/src/CBot/CBotInstr/CBotInstr.cpp
+++ b/src/CBot/CBotInstr/CBotInstr.cpp
@@ -50,7 +50,7 @@
////////////////////////////////////////////////////////////////////////////////
int CBotInstr::m_LoopLvl = 0;
-std::vector<CBotString> CBotInstr::m_labelLvl = std::vector<CBotString>();
+std::vector<std::string> CBotInstr::m_labelLvl = std::vector<std::string>();
////////////////////////////////////////////////////////////////////////////////
CBotInstr::CBotInstr()
@@ -72,7 +72,7 @@ CBotInstr::~CBotInstr()
}
////////////////////////////////////////////////////////////////////////////////
-void CBotInstr::IncLvl(CBotString& label)
+void CBotInstr::IncLvl(std::string& label)
{
m_labelLvl.resize(m_LoopLvl+1);
m_labelLvl[m_LoopLvl] = label;
@@ -91,24 +91,24 @@ void CBotInstr::IncLvl()
void CBotInstr::DecLvl()
{
m_LoopLvl--;
- m_labelLvl[m_LoopLvl].Empty();
+ m_labelLvl[m_LoopLvl].clear();
}
////////////////////////////////////////////////////////////////////////////////
-bool CBotInstr::ChkLvl(const CBotString& label, int type)
+bool CBotInstr::ChkLvl(const std::string& label, int type)
{
int i = m_LoopLvl;
while (--i>=0)
{
if ( type == ID_CONTINUE && m_labelLvl[i] == "#SWITCH") continue;
- if (label.IsEmpty()) return true;
+ if (label.empty()) return true;
if (m_labelLvl[i] == label) return true;
}
return false;
}
////////////////////////////////////////////////////////////////////////////////
-bool CBotInstr::IsOfClass(CBotString n)
+bool CBotInstr::IsOfClass(const std::string& n)
{
return name == n;
}
@@ -284,7 +284,7 @@ CBotInstr* CBotInstr::Compile(CBotToken* &p, CBotCStack* pStack)
////////////////////////////////////////////////////////////////////////////////
bool CBotInstr::Execute(CBotStack* &pj)
{
- CBotString ClassManquante = name;
+ std::string ClassManquante = name;
assert(0); // should never go through this routine
// but use the routines of the subclasses
return false;
@@ -301,7 +301,7 @@ bool CBotInstr::Execute(CBotStack* &pj, CBotVar* pVar)
////////////////////////////////////////////////////////////////////////////////
void CBotInstr::RestoreState(CBotStack* &pj, bool bMain)
{
- CBotString ClassManquante = name;
+ std::string ClassManquante = name;
assert(0); // should never go through this routine
// but use the routines of the subclasses
}
diff --git a/src/CBot/CBotInstr/CBotInstr.h b/src/CBot/CBotInstr/CBotInstr.h
index 9ed637c..e8221a2 100644
--- a/src/CBot/CBotInstr/CBotInstr.h
+++ b/src/CBot/CBotInstr/CBotInstr.h
@@ -208,7 +208,7 @@ public:
* \brief IncLvl Adds a level with a label.
* \param label
*/
- static void IncLvl(CBotString& label);
+ static void IncLvl(std::string& label);
/*!
* \brief IncLvl Adds a level (switch statement).
@@ -226,21 +226,21 @@ public:
* \param type
* \return
*/
- static bool ChkLvl(const CBotString& label, int type);
+ static bool ChkLvl(const std::string& label, int type);
/*!
* \brief IsOfClass
* \param name
* \return
*/
- bool IsOfClass(CBotString name);
+ bool IsOfClass(const std::string& name);
protected:
//! Keeps the token.
CBotToken m_token;
//! Debug.
- CBotString name;
+ std::string name;
//! Linked command.
CBotInstr* m_next;
//! Second list definition chain.
@@ -258,5 +258,5 @@ protected:
private:
//! List of labels used.
- static std::vector<CBotString> m_labelLvl;
+ static std::vector<std::string> m_labelLvl;
};
diff --git a/src/CBot/CBotInstr/CBotInstrMethode.h b/src/CBot/CBotInstr/CBotInstrMethode.h
index 1c8512d..f6bb1ab 100644
--- a/src/CBot/CBotInstr/CBotInstrMethode.h
+++ b/src/CBot/CBotInstr/CBotInstrMethode.h
@@ -84,9 +84,9 @@ private:
//! Complete type of the result.
CBotTypResult m_typRes;
//! Name of the method.
- CBotString m_NomMethod;
+ std::string m_NomMethod;
//! Identifier of the method.
long m_MethodeIdent;
//! Name of the class.
- CBotString m_ClassName;
+ std::string m_ClassName;
};
diff --git a/src/CBot/CBotInstr/CBotReturn.cpp b/src/CBot/CBotInstr/CBotReturn.cpp
index c89e959..aeb6d52 100644
--- a/src/CBot/CBotInstr/CBotReturn.cpp
+++ b/src/CBot/CBotInstr/CBotReturn.cpp
@@ -97,7 +97,7 @@ bool CBotReturn::Execute(CBotStack* &pj)
if ( pile->IfStep() ) return false;
- pile->SetBreak(3, CBotString());
+ pile->SetBreak(3, std::string());
return pj->Return(pile);
}
diff --git a/src/CBot/CBotInstr/CBotWhile.h b/src/CBot/CBotInstr/CBotWhile.h
index 6b91c74..8898413 100644
--- a/src/CBot/CBotInstr/CBotWhile.h
+++ b/src/CBot/CBotInstr/CBotWhile.h
@@ -74,6 +74,6 @@ private:
//! Instructions
CBotInstr* m_Block;
//! A label if there is
- CBotString m_label;
+ std::string m_label;
};
diff --git a/src/CBot/CBotKeywordStrings.cpp b/src/CBot/CBotKeywordStrings.cpp
index e1a45fa..2af5eb0 100644
--- a/src/CBot/CBotKeywordStrings.cpp
+++ b/src/CBot/CBotKeywordStrings.cpp
@@ -4,7 +4,7 @@
//! \brief Keeps the string corresponding to keyword ID
// Map is filled with id-string pars that are needed for CBot language parsing
-static const std::map<EID, const char*> s_keywordString = {
+static const std::map<EID, const std::string> s_keywordString = {
{ID_IF, "if"},
{ID_ELSE, "else"},
{ID_WHILE, "while"},
@@ -94,9 +94,8 @@ static const std::map<EID, const char*> s_keywordString = {
{TX_NAN, "not a number"}
};
-static const char emptyString[] = "";
-
-const char* LoadString(EID id)
+static const std::string emptyString = "";
+const std::string& LoadString(EID id)
{
if (s_keywordString.find(id) != s_keywordString.end())
{
diff --git a/src/CBot/CBotKeywordStrings.h b/src/CBot/CBotKeywordStrings.h
index b328b78..e652a20 100644
--- a/src/CBot/CBotKeywordStrings.h
+++ b/src/CBot/CBotKeywordStrings.h
@@ -2,9 +2,11 @@
#include "CBotEnums.h"
+#include <string>
+
/**
* \brief LoadString Maps given ID to its string equivalent.
* \param id Provided identifier.
* \return String if found, else NullString.
*/
-const char* LoadString(EID id);
+const std::string& LoadString(EID id);
diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp
index 80c9327..0dd62f1 100644
--- a/src/CBot/CBotProgram.cpp
+++ b/src/CBot/CBotProgram.cpp
@@ -81,7 +81,7 @@ CBotProgram::~CBotProgram()
}
////////////////////////////////////////////////////////////////////////////////
-bool CBotProgram::Compile( const char* program, std::vector<CBotString>& ListFonctions, void* pUser )
+bool CBotProgram::Compile(const std::string& program, std::vector<std::string>& ListFonctions, void* pUser)
{
int error = 0;
Stop();
@@ -176,7 +176,7 @@ bool CBotProgram::Compile( const char* program, std::vector<CBotString>& ListFon
}
////////////////////////////////////////////////////////////////////////////////
-bool CBotProgram::Start(const char* name)
+bool CBotProgram::Start(const std::string& name)
{
#if STACKMEM
m_pStack->Delete();
@@ -210,7 +210,7 @@ bool CBotProgram::Start(const char* name)
}
////////////////////////////////////////////////////////////////////////////////
-bool CBotProgram::GetPosition(const char* name, int& start, int& stop, CBotGet modestart, CBotGet modestop)
+bool CBotProgram::GetPosition(const std::string& name, int& start, int& stop, CBotGet modestart, CBotGet modestop)
{
CBotFunction* p = m_Prog;
while (p != nullptr)
@@ -293,7 +293,7 @@ void CBotProgram::Stop()
}
////////////////////////////////////////////////////////////////////////////////
-bool CBotProgram::GetRunPos(const char* &FunctionName, int &start, int &end)
+bool CBotProgram::GetRunPos(std::string& FunctionName, int& start, int& end)
{
FunctionName = nullptr;
start = end = 0;
@@ -304,7 +304,7 @@ bool CBotProgram::GetRunPos(const char* &FunctionName, int &start, int &end)
}
////////////////////////////////////////////////////////////////////////////////
-CBotVar* CBotProgram::GetStackVars(const char* &FunctionName, int level)
+CBotVar* CBotProgram::GetStackVars(std::string& FunctionName, int level)
{
FunctionName = nullptr;
if (m_pStack == nullptr) return nullptr;
@@ -356,11 +356,11 @@ bool CBotProgram::GetError(int& code, int& start, int& end, CBotProgram* &pProg)
}
////////////////////////////////////////////////////////////////////////////////
-CBotString CBotProgram::GetErrorText(int code)
+std::string CBotProgram::GetErrorText(int code)
{
- CBotString TextError = LoadString(static_cast<EID>(code));
+ std::string TextError = LoadString(static_cast<EID>(code));
- if (TextError.IsEmpty())
+ if (TextError.empty())
{
char buf[100];
sprintf(buf, "Exception numéro %d.", code);
@@ -376,9 +376,9 @@ CBotFunction* CBotProgram::GetFunctions()
}
////////////////////////////////////////////////////////////////////////////////
-bool CBotProgram::AddFunction(const char* name,
- bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser),
- CBotTypResult rCompile (CBotVar* &pVar, void* pUser))
+bool CBotProgram::AddFunction(const std::string& name,
+ bool rExec(CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser),
+ CBotTypResult rCompile(CBotVar*& pVar, void* pUser))
{
// stores pointers to the two functions
return CBotCall::AddFunction(name, rExec, rCompile);
@@ -412,7 +412,7 @@ CBotTypResult cSizeOf( CBotVar* &pVar, void* pUser )
}
////////////////////////////////////////////////////////////////////////////////
-bool CBotProgram::DefineNum(const char* name, long val)
+bool CBotProgram::DefineNum(const std::string& name, long val)
{
return CBotToken::DefineNum(name, val);
}
@@ -440,7 +440,7 @@ bool CBotProgram::SaveState(FILE* pf)
bool CBotProgram::RestoreState(FILE* pf)
{
unsigned short w;
- CBotString s;
+ std::string s;
Stop();
diff --git a/src/CBot/CBotProgram.h b/src/CBot/CBotProgram.h
index 26aeb68..50c62f6 100644
--- a/src/CBot/CBotProgram.h
+++ b/src/CBot/CBotProgram.h
@@ -21,7 +21,6 @@
// Modules inlcude
#include "CBot/CBotTypResult.h"
-#include "CBot/CBotString.h"
#include "CBot/CBotEnums.h"
@@ -84,7 +83,7 @@ public:
* \return false if an error at compile.
* \see GetCompileError() to retrieve the error.
*/
- bool Compile( const char* program, std::vector<CBotString>& ListFonctions, void* pUser = nullptr);
+ bool Compile(const std::string& program, std::vector<std::string>& ListFonctions, void* pUser = nullptr);
/*!
* \brief SetIdent Associates an identifier with the instance CBotProgram.
@@ -128,7 +127,7 @@ public:
* \param code
* \return
*/
- static CBotString GetErrorText(int code);
+ static std::string GetErrorText(int code);
/*!
* \brief Start Defines what function should be executed. The program does
@@ -136,7 +135,7 @@ public:
* \param name
* \return false if the funtion name is not found
*/
- bool Start(const char* name);
+ bool Start(const std::string& name);
/*!
* \brief Run Executes the program.
@@ -154,7 +153,7 @@ public:
* \param end
* \return false if it is not running (program completion)
*/
- bool GetRunPos(const char* &FunctionName, int &start, int &end);
+ bool GetRunPos(std::string& FunctionName, int& start, int& end);
/*!
* \brief GetStackVars provides the pointer to the variables on the
@@ -168,7 +167,7 @@ public:
* \param level
* \return
*/
- CBotVar* GetStackVars(const char* &FunctionName, int level);
+ CBotVar* GetStackVars(std::string& FunctionName, int level);
/*!
* \brief Stop stops execution of the program therefore quits "suspend" mode
@@ -193,9 +192,9 @@ public:
* \param rCompile
* \return
*/
- static bool AddFunction(const char* name,
- bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser),
- CBotTypResult rCompile (CBotVar* &pVar, void* pUser));
+ static bool AddFunction(const std::string& name,
+ bool rExec(CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser),
+ CBotTypResult rCompile(CBotVar*& pVar, void* pUser));
/*!
* \brief DefineNum
@@ -203,7 +202,7 @@ public:
* \param val
* \return
*/
- static bool DefineNum(const char* name, long val);
+ static bool DefineNum(const std::string& name, long val);
/*!
* \brief SaveState Backup the execution status in the file the file must
@@ -233,11 +232,11 @@ public:
* \param modestop
* \return
*/
- bool GetPosition(const char* name,
+ bool GetPosition(const std::string& name,
int& start,
int& stop,
CBotGet modestart = GetPosExtern,
- CBotGet modestop = GetPosBloc);
+ CBotGet modestop = GetPosBloc);
/*!
* \brief GetFunctions
@@ -286,7 +285,7 @@ private:
For example, a routine which calculates the mean of a parameter list
-int cMean(CBotVar* &pVar, CBotString& ClassName)
+int cMean(CBotVar* &pVar, std::string& ClassName)
{
if ( pVar == nullptr ) return 6001; // there is no parameter!
while ( pVar != nullptr )
diff --git a/src/CBot/CBotStack.cpp b/src/CBot/CBotStack.cpp
index c2c04d2..f77b9f7 100644
--- a/src/CBot/CBotStack.cpp
+++ b/src/CBot/CBotStack.cpp
@@ -27,6 +27,7 @@
#include "CBot/CBotVar/CBotVarClass.h"
#include "CBot/CBotFileUtils.h"
+#include "CBot/CBotUtils.h"
// Local include
@@ -44,7 +45,7 @@ CBotVar* CBotStack::m_retvar = nullptr;
int CBotStack::m_error = 0;
int CBotStack::m_start = 0;
int CBotStack::m_end = 0;
-CBotString CBotStack::m_labelBreak="";
+std::string CBotStack::m_labelBreak="";
void* CBotStack::m_pUser = nullptr;
#if STACKMEM
@@ -381,7 +382,7 @@ void CBotStack::Reset(void* pUser)
m_error = 0;
// m_start = 0;
// m_end = 0;
- m_labelBreak.Empty();
+ m_labelBreak.clear();
m_pUser = pUser;
}
@@ -414,36 +415,36 @@ bool CBotStack::IfStep()
}
////////////////////////////////////////////////////////////////////////////////
-bool CBotStack::BreakReturn(CBotStack* pfils, const char* name)
+bool CBotStack::BreakReturn(CBotStack* pfils, const std::string& name)
{
if ( m_error>=0 ) return false; // normal output
if ( m_error==-3 ) return false; // normal output (return current)
- if (!m_labelBreak.IsEmpty() && (name[0] == 0 || m_labelBreak != name))
+ if (!m_labelBreak.empty() && (name.empty() || m_labelBreak != name))
return false; // it's not for me
m_error = 0;
- m_labelBreak.Empty();
+ m_labelBreak.clear();
return Return(pfils);
}
////////////////////////////////////////////////////////////////////////////////
-bool CBotStack::IfContinue(int state, const char* name)
+bool CBotStack::IfContinue(int state, const std::string& name)
{
if ( m_error != -2 ) return false;
- if (!m_labelBreak.IsEmpty() && (name == nullptr || m_labelBreak != name))
+ if (!m_labelBreak.empty() && (name.empty() || m_labelBreak != name))
return false; // it's not for me
m_state = state; // where again?
m_error = 0;
- m_labelBreak.Empty();
+ m_labelBreak.clear();
if ( m_next != EOX ) m_next->Delete(); // purge above stack
return true;
}
////////////////////////////////////////////////////////////////////////////////
-void CBotStack::SetBreak(int val, const char* name)
+void CBotStack::SetBreak(int val, const std::string& name)
{
m_error = -val; // reacts as an Exception
m_labelBreak = name;
@@ -502,7 +503,7 @@ void CBotStack::SetType(CBotTypResult& type)
CBotVar* CBotStack::FindVar(CBotToken* &pToken, bool bUpdate, bool bModif)
{
CBotStack* p = this;
- CBotString name = pToken->GetString();
+ std::string name = pToken->GetString();
while (p != nullptr)
{
@@ -524,7 +525,7 @@ CBotVar* CBotStack::FindVar(CBotToken* &pToken, bool bUpdate, bool bModif)
}
////////////////////////////////////////////////////////////////////////////////
-CBotVar* CBotStack::FindVar(const char* name)
+CBotVar* CBotStack::FindVar(const std::string& name)
{
CBotStack* p = this;
while (p != nullptr)
@@ -814,7 +815,7 @@ bool SaveVar(FILE* pf, CBotVar* pVar)
}
////////////////////////////////////////////////////////////////////////////////
-void CBotStack::GetRunPos(const char* &FunctionName, int &start, int &end)
+void CBotStack::GetRunPos(std::string& FunctionName, int& start, int& end)
{
CBotProgram* prog = m_prog; // Current program
@@ -849,7 +850,7 @@ void CBotStack::GetRunPos(const char* &FunctionName, int &start, int &end)
}
////////////////////////////////////////////////////////////////////////////////
-CBotVar* CBotStack::GetStackVars(const char* &FunctionName, int level)
+CBotVar* CBotStack::GetStackVars(std::string& FunctionName, int level)
{
CBotProgram* prog = m_prog; // current program
FunctionName = nullptr;
@@ -1005,7 +1006,7 @@ bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar)
{
unsigned short w, wi, prv, st;
float ww;
- CBotString name, s;
+ std::string name, s;
delete pVar;
@@ -1018,7 +1019,7 @@ bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar)
if (!ReadWord(pf, w)) return false; // private or type?
if ( w == 0 ) return true;
- CBotString defnum;
+ std::string defnum;
if ( w == 200 )
{
if (!ReadString(pf, defnum)) return false; // number with identifier
@@ -1039,7 +1040,7 @@ bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar)
if (!ReadWord(pf, wi) || !ParseInitType(wi, &initType)) return false; // init ?
if (!ReadString(pf, name)) return false; // variable name
- CBotToken token(name, CBotString());
+ CBotToken token(name, std::string());
switch (w)
{
diff --git a/src/CBot/CBotStack.h b/src/CBot/CBotStack.h
index 738cfd6..b5afe4d 100644
--- a/src/CBot/CBotStack.h
+++ b/src/CBot/CBotStack.h
@@ -22,12 +22,12 @@
// Modules inlcude
#include "CBot/CBotDefines.h"
#include "CBot/CBotTypResult.h"
-#include "CBot/CBotString.h"
// Local include
// Global include
#include <cstdio>
+#include <string>
// Forward declaration
class CBotInstr;
@@ -150,7 +150,7 @@ public:
* \param [in] name Name of variable to find
* \return Found variable
*/
- CBotVar* FindVar(const char* name);
+ CBotVar* FindVar(const std::string& name);
/**
* \brief Fetch a variable on the stack according to its identification number
@@ -180,9 +180,9 @@ public:
CBotStack* AddStack2(UnknownEnumBlock bBlock = UnknownEnumBlock::UNKNOWN_FALSE); // extends the stack
bool Return(CBotStack* pFils); // transmits the result over
bool ReturnKeep(CBotStack* pFils); // transmits the result without reducing the stack
- bool BreakReturn(CBotStack* pfils, const char* name = nullptr);
+ bool BreakReturn(CBotStack* pfils, const std::string& name = nullptr);
// in case of eventual break
- bool IfContinue(int state, const char* name);
+ bool IfContinue(int state, const std::string& name);
// or "continue"
bool IsOk();
@@ -204,7 +204,7 @@ public:
void SetError(int n, CBotToken* token = nullptr);
void SetPosError(CBotToken* token);
void ResetError(int n, int start, int end);
- void SetBreak(int val, const char* name);
+ void SetBreak(int val, const std::string& name);
void SetBotCall(CBotProgram* p);
CBotProgram* GetBotCall(bool bFirst = false);
@@ -221,8 +221,8 @@ public:
static
void SetTimer(int n);
- void GetRunPos(const char* &FunctionName, int &start, int &end);
- CBotVar* GetStackVars(const char* &FunctionName, int level);
+ void GetRunPos(std::string& FunctionName, int& start, int& end);
+ CBotVar* GetStackVars(std::string& FunctionName, int level);
private:
CBotStack* m_next;
@@ -254,7 +254,7 @@ private:
static
int m_timer;
static
- CBotString m_labelBreak;
+ std::string m_labelBreak;
static
void* m_pUser;
diff --git a/src/CBot/CBotString.cpp b/src/CBot/CBotString.cpp
deleted file mode 100644
index 2459f39..0000000
--- a/src/CBot/CBotString.cpp
+++ /dev/null
@@ -1,236 +0,0 @@
-/*
- * This file is part of the Colobot: Gold Edition source code
- * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
- * http://epsitec.ch; http://colobot.info; http://github.com/colobot
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see http://gnu.org/licenses
- */
-
-/////////////////////////////////////////////////////
-
-#include "CBot/CBotString.h"
-
-#include <cstdlib>
-#include <cstring>
-#include <algorithm>
-#include <boost/algorithm/string.hpp>
-
-CBotString::CBotString()
-{
- m_str = "";
-}
-
-CBotString::~CBotString()
-{
-}
-
-
-CBotString::CBotString(const char* p)
-{
- m_str = p;
-}
-
-CBotString::CBotString(const std::string &p)
-{
- m_str = p;
-}
-
-CBotString::CBotString(const CBotString& srcString)
-{
- m_str = srcString.m_str;
-}
-
-
-
-int CBotString::GetLength()
-{
- return m_str.length();
-}
-
-
-
-CBotString CBotString::Left(int nCount) const
-{
- return CBotString(m_str.substr(0, nCount));
-}
-
-CBotString CBotString::Right(int nCount) const
-{
- return CBotString(m_str.substr(m_str.length()-nCount, std::string::npos));
-}
-
-CBotString CBotString::Mid(int start, int lg)
-{
- return CBotString(m_str.substr(start, lg));
-}
-
-int CBotString::Find(const char c)
-{
- std::size_t pos = m_str.find(c);
- return pos != std::string::npos ? pos : -1;
-}
-
-int CBotString::Find(const char * lpsz)
-{
- std::size_t pos = m_str.find(lpsz);
- return pos != std::string::npos ? pos : -1;
-}
-
-int CBotString::ReverseFind(const char c)
-{
- std::size_t pos = m_str.rfind(c);
- return pos != std::string::npos ? pos : -1;
-}
-
-int CBotString::ReverseFind(const char * lpsz)
-{
- std::size_t pos = m_str.rfind(lpsz);
- return pos != std::string::npos ? pos : -1;
-}
-
-void CBotString::MakeUpper()
-{
- boost::to_upper(m_str);
-}
-
-void CBotString::MakeLower()
-{
- boost::to_lower(m_str);
-}
-
-
-const CBotString& CBotString::operator=(const CBotString& stringSrc)
-{
- m_str = stringSrc.m_str;
- return *this;
-}
-
-CBotString CBotString::operator+(const CBotString& stringSrc)
-{
- CBotString s(*this);
- s += stringSrc;
- return s;
-}
-
-const CBotString& CBotString::operator=(const char ch)
-{
- m_str = ch;
- return *this;
-}
-
-const CBotString& CBotString::operator=(const char* pString)
-{
- if (pString != nullptr)
- m_str = pString;
- else
- m_str.clear();
- return *this;
-}
-
-
-const CBotString& CBotString::operator+=(const char ch)
-{
- m_str += ch;
- return *this;
-}
-
-const CBotString& CBotString::operator+=(const CBotString& str)
-{
- m_str += str.m_str;
- return *this;
-}
-
-bool CBotString::operator==(const CBotString& str)
-{
- return m_str == str.m_str;
-}
-
-bool CBotString::operator==(const char* p)
-{
- return m_str == p;
-}
-
-bool CBotString::operator!=(const CBotString& str)
-{
- return m_str != str.m_str;
-}
-
-bool CBotString::operator!=(const char* p)
-{
- return m_str != p;
-}
-
-bool CBotString::operator>(const CBotString& str)
-{
- return m_str > str.m_str;
-}
-
-bool CBotString::operator>(const char* p)
-{
- return m_str > p;
-}
-
-bool CBotString::operator>=(const CBotString& str)
-{
- return m_str >= str.m_str;
-}
-
-bool CBotString::operator>=(const char* p)
-{
- return m_str >= p;
-}
-
-bool CBotString::operator<(const CBotString& str)
-{
- return m_str < str.m_str;
-}
-
-bool CBotString::operator<(const char* p)
-{
- return m_str < p;
-}
-
-bool CBotString::operator<=(const CBotString& str)
-{
- return m_str <= str.m_str;
-}
-
-bool CBotString::operator<=(const char* p)
-{
- return m_str <= p;
-}
-
-bool CBotString::IsEmpty() const
-{
- return m_str.empty();
-}
-
-void CBotString::Empty()
-{
- m_str.clear();
-}
-
-static char emptyString[] = "";
-
-CBotString::operator const char * () const
-{
- if (this == nullptr) return emptyString; // TODO: can this be removed?
- return m_str.c_str();
-}
-
-const char* CBotString::CStr() const
-{
- if (this == nullptr) return emptyString; // TODO: can this be removed?
- return m_str.c_str();
-}
diff --git a/src/CBot/CBotString.h b/src/CBot/CBotString.h
deleted file mode 100644
index efe2d9d..0000000
--- a/src/CBot/CBotString.h
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- * This file is part of the Colobot: Gold Edition source code
- * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
- * http://epsitec.ch; http://colobot.info; http://github.com/colobot
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see http://gnu.org/licenses
- */
-
-#pragma once
-
-// Modules inlcude
-#include "CBot/CBotUtils.h"
-
-#include "CBot/CBotEnums.h"
-
-// Local include
-
-// Global include
-#include <map>
-
-/**
- * \brief CBotString Class used to work on strings
- * TODO: do not use this class, code should be refactored to use std::string instead
- */
-class CBotString
-{
-public:
-
- /**
- * \brief CBotString Creates an empty string
- */
- CBotString();
-
- /**
- * \brief CBotString
- * \param p
- */
- CBotString(const char* p);
-
- /**
- * \brief CBotString
- * \param p
- */
- CBotString(const std::string& p);
-
- /**
- * \brief CBotString
- * \param p
- */
- CBotString(const CBotString& p);
-
- /**
- * \brief CBotString Destructor.
- */
- ~CBotString();
-
- /**
- * \brief Empty Clear the internal string.
- */
- void Empty();
-
- /**
- * \brief IsEmpty Check if the string is empty.
- * \return True if the sting is empty false otherwise.
- */
- bool IsEmpty() const;
-
- /**
- * \brief GetLength Get the string length.
- * \return The size of the string.
- */
- int GetLength();
-
- /**
- * \brief Find Find the position of a character in a string starting from
- * the beginning of the string.
- * \param c The character to find.
- * \return The position of the character or -1 if the character was not
- * found.
- * \see ReverseFind(const char c)
- */
- int Find(const char c);
-
- /**
- * \brief Find Find the position of a string in a string starting from the
- * beginning of the string.
- * \param lpsz The string to find.
- * \return The position of the string or -1 if the string was not
- * found.
- * \see ReverseFind(const char* lpsz)
- */
- int Find(const char* lpsz);
-
- /**
- * \brief Find Find the position of a character in a string starting from
- * the end of the string.
- * \param c The character to find.
- * \return The position of the character or -1 if the character was not
- * found.
- * \see Find(const char c)
- */
- int ReverseFind(const char c);
-
- /**
- * \brief Find Find the position of a string in a string starting from the
- * end of the string.
- * \param lpsz The string to find.
- * \return The string of the character or -1 if the string was not
- * found.
- * \see Find(const char* lpsz)
- */
- int ReverseFind(const char* lpsz);
-
- /**
- * \brief Mid Return a part of a string from a starting index and until
- * the end of the string with a limited size.
- * \param nFirst The start index of the character in the string.
- * \param lg The size limit. Default value is 2000.
- * \return The exctracted string.
- */
- CBotString Mid(int start, int lg=-1);
-
- /**
- * \brief Left Return a part of a string starting from the left.
- * \param nCount The number of character to retreive.
- * \return The exctracted string.
- */
- CBotString Left(int nCount) const;
-
- /**
- * \brief Right Return a part of a string starting from the right.
- * \param nCount The number of character to retreive.
- * \return The exctracted string.
- */
- CBotString Right(int nCount) const;
-
- /**
- * \brief MakeUpper Uppercase the string.
- */
- void MakeUpper();
-
- /**
- * \brief MakeLower Lowercase the string.
- */
- void MakeLower();
-
- /**
- * @brief CStr Convert the CBotString to a C string.
- * @return A C string string.
- */
- const char* CStr() const;
-
- /**
- * \brief Overloaded oprators to work on CBotString classes
- */
- const CBotString& operator=(const CBotString& stringSrc);
- const CBotString& operator=(const char ch);
- const CBotString& operator=(const char* pString);
- CBotString operator+(const CBotString& str);
-
- const CBotString& operator+=(const char ch);
- const CBotString& operator+=(const CBotString& str);
- bool operator==(const CBotString& str);
- bool operator==(const char* p);
- bool operator!=(const CBotString& str);
- bool operator!=(const char* p);
- bool operator>(const CBotString& str);
- bool operator>(const char* p);
- bool operator>=(const CBotString& str);
- bool operator>=(const char* p);
- bool operator<(const CBotString& str);
- bool operator<(const char* p);
- bool operator<=(const CBotString& str);
- bool operator<=(const char* p);
-
- operator const char*() const; // as a C string
-
-
-private:
-
- //! \brief String
- std::string m_str;
-};
diff --git a/src/CBot/CBotToken.cpp b/src/CBot/CBotToken.cpp
index baef697..9951c18 100644
--- a/src/CBot/CBotToken.cpp
+++ b/src/CBot/CBotToken.cpp
@@ -27,9 +27,9 @@
#include <cstdarg>
////////////////////////////////////////////////////////////////////////////////
-std::vector<CBotString> CBotToken::m_ListKeyWords;
+std::vector<std::string> CBotToken::m_ListKeyWords;
int CBotToken::m_ListIdKeyWords[200];
-std::vector<CBotString> CBotToken::m_ListKeyDefine;
+std::vector<std::string> CBotToken::m_ListKeyDefine;
long CBotToken::m_ListKeyNums[MAXDEFNUM];
////////////////////////////////////////////////////////////////////////////////
@@ -47,8 +47,8 @@ CBotToken::CBotToken(const CBotToken* pSrc)
m_next = nullptr;
m_prev = nullptr;
- m_Text.Empty();
- m_Sep.Empty();
+ m_Text.clear();
+ m_Sep.clear();
m_type = 0;
m_IdKeyWord = 0;
@@ -71,7 +71,7 @@ CBotToken::CBotToken(const CBotToken* pSrc)
}
////////////////////////////////////////////////////////////////////////////////
-CBotToken::CBotToken(const CBotString& mot, const CBotString& sep, int start, int end)
+CBotToken::CBotToken(const std::string& mot, const std::string& sep, int start, int end)
{
m_Text = mot; // word (mot) found as token
m_Sep = sep; // separator
@@ -84,17 +84,6 @@ CBotToken::CBotToken(const CBotString& mot, const CBotString& sep, int start, in
m_IdKeyWord = -1;
}
-CBotToken::CBotToken(const char* mot, const char* sep)
-{
- m_Text = mot;
- if ( sep != nullptr ) m_Sep = sep;
- m_next = nullptr;
- m_prev = nullptr;
-
- m_type = TokenTypVar; // at the beginning a default variable type
- m_IdKeyWord = -1;
-}
-
////////////////////////////////////////////////////////////////////////////////
CBotToken::~CBotToken()
{
@@ -155,19 +144,19 @@ CBotToken* CBotToken::GetPrev()
}
////////////////////////////////////////////////////////////////////////////////
-CBotString CBotToken::GetString()
+std::string CBotToken::GetString()
{
return m_Text;
}
////////////////////////////////////////////////////////////////////////////////
-CBotString CBotToken::GetSep()
+std::string CBotToken::GetSep()
{
return m_Sep;
}
////////////////////////////////////////////////////////////////////////////////
-void CBotToken::SetString(const char* name)
+void CBotToken::SetString(const std::string& name)
{
m_Text = name;
}
@@ -229,8 +218,8 @@ static char nch[] = "\"\r\n\t"; // forbidden in cha
////////////////////////////////////////////////////////////////////////////////
CBotToken* CBotToken::NextToken(char* &program, int& error, bool first)
{
- CBotString mot; // the word which is found
- CBotString sep; // separators that are after
+ std::string mot; // the word which is found
+ std::string sep; // separators that are after
char c;
bool stop = first;
@@ -315,7 +304,7 @@ cc: mot += c;
if (CharInList(mot[0], sep3)) // an operational separator?
{
- CBotString motc = mot;
+ std::string motc = mot;
while (motc += c, c != 0 && GetKeyWords(motc)>0) // operand seeks the longest possible
{
mot += c; // build the word
@@ -332,7 +321,7 @@ cc: mot += c;
{
if (stop || c == 0 || CharInList(c, sep1))
{
- if (!first && mot.IsEmpty()) return nullptr; // end of the analysis
+ if (!first && mot.empty()) return nullptr; // end of the analysis
bis:
while (CharInList(c, sep2))
{
@@ -387,10 +376,10 @@ bis:
}
////////////////////////////////////////////////////////////////////////////////
-CBotToken* CBotToken::CompileTokens(const char* program, int& error)
+CBotToken* CBotToken::CompileTokens(const std::string& program, int& error)
{
CBotToken *nxt, *prv, *tokenbase;
- char* p = const_cast<char*> ( program);
+ char* p = const_cast<char*> (program.c_str());
int pos = 0;
error = 0;
@@ -399,9 +388,9 @@ CBotToken* CBotToken::CompileTokens(const char* program, int& error)
if (tokenbase == nullptr) return nullptr;
tokenbase->m_start = pos;
- pos += tokenbase->m_Text.GetLength();
+ pos += tokenbase->m_Text.length();
tokenbase->m_end = pos;
- pos += tokenbase->m_Sep.GetLength();
+ pos += tokenbase->m_Sep.length();
char* pp = p;
while (nullptr != (nxt = NextToken(p, error)))
@@ -415,7 +404,7 @@ CBotToken* CBotToken::CompileTokens(const char* program, int& error)
nxt->m_end = pos;
pos += nxt->m_Sep.GetLength();*/
pos += (p - pp); // total size
- nxt->m_end = pos - nxt->m_Sep.GetLength();
+ nxt->m_end = pos - nxt->m_Sep.length();
pp = p;
}
@@ -436,7 +425,7 @@ void CBotToken::Delete(CBotToken* pToken)
}
////////////////////////////////////////////////////////////////////////////////
-int CBotToken::GetKeyWords(const char* w)
+int CBotToken::GetKeyWords(const std::string& w)
{
int i;
int l = m_ListKeyWords.size();
@@ -456,7 +445,7 @@ int CBotToken::GetKeyWords(const char* w)
}
////////////////////////////////////////////////////////////////////////////////
-bool CBotToken::GetKeyDefNum(const char* w, CBotToken* &token)
+bool CBotToken::GetKeyDefNum(const std::string& w, CBotToken*& token)
{
int i;
int l = m_ListKeyDefine.size();
@@ -477,18 +466,18 @@ bool CBotToken::GetKeyDefNum(const char* w, CBotToken* &token)
////////////////////////////////////////////////////////////////////////////////
void CBotToken::LoadKeyWords()
{
- CBotString s;
+ std::string s;
int i, n = 0;
i = TokenKeyWord; //start with keywords of the language
- while (!(s = LoadString(static_cast<EID>(i))).IsEmpty())
+ while (!(s = LoadString(static_cast<EID>(i))).empty())
{
m_ListKeyWords.push_back(s);
m_ListIdKeyWords[n++] = i++;
}
i = TokenKeyDeclare; //keywords of declarations
- while (!(s = LoadString(static_cast<EID>(i))).IsEmpty())
+ while (!(s = LoadString(static_cast<EID>(i))).empty())
{
m_ListKeyWords.push_back(s);
m_ListIdKeyWords[n++] = i++;
@@ -496,14 +485,14 @@ void CBotToken::LoadKeyWords()
i = TokenKeyVal; //keywords of values
- while (!(s = LoadString(static_cast<EID>(i))).IsEmpty())
+ while (!(s = LoadString(static_cast<EID>(i))).empty())
{
m_ListKeyWords.push_back(s);
m_ListIdKeyWords[n++] = i++;
}
i = TokenKeyOp; //operators
- while (!(s = LoadString(static_cast<EID>(i))).IsEmpty())
+ while (!(s = LoadString(static_cast<EID>(i))).empty())
{
m_ListKeyWords.push_back(s);
m_ListIdKeyWords[n++] = i++;
@@ -511,7 +500,7 @@ void CBotToken::LoadKeyWords()
}
////////////////////////////////////////////////////////////////////////////////
-bool CBotToken::DefineNum(const char* name, long val)
+bool CBotToken::DefineNum(const std::string& name, long val)
{
int i;
int l = m_ListKeyDefine.size();
diff --git a/src/CBot/CBotToken.h b/src/CBot/CBotToken.h
index 1dbe39b..4a0e2d6 100644
--- a/src/CBot/CBotToken.h
+++ b/src/CBot/CBotToken.h
@@ -19,9 +19,8 @@
#pragma once
-#include "CBot/CBotString.h"
-
#include <vector>
+#include <string>
/////////////////////////////////////////////////////////////////////////////////////
// Token management (tokens)
@@ -69,11 +68,10 @@ public:
*/
CBotToken();
CBotToken(const CBotToken* pSrc);
- CBotToken(const CBotString& mot,
- const CBotString& sep,
+ CBotToken(const std::string& mot,
+ const std::string& sep = "",
int start=0,
int end=0);
- CBotToken(const char* mot, const char* sep = nullptr);
/*!
* \brief ~CBotToken Destructor. Be careful when you delete a CBotToken that
@@ -92,20 +90,20 @@ public:
* \return The token string if a string has been set. An empty string
* otherwise.
*/
- CBotString GetString();
+ std::string GetString();
/*!
* \brief SetString Set the token string.
* \param [in] name The new string to set.
*/
- void SetString(const char* name);
+ void SetString(const std::string& name);
/*!
* \brief GetSep Return the token separator.
* \return The token separator a separator has been set. An empty separator
* otherwise.
*/
- CBotString GetSep();
+ std::string GetSep();
/*!
* \brief GetStart Return the start position of the string token in the
@@ -165,7 +163,7 @@ public:
* \return The first token of the linked liste.
* \todo Replace the error code by an enum.
*/
- static CBotToken* CompileTokens(const char* p, int& error);
+ static CBotToken* CompileTokens(const std::string& p, int& error);
/*!
* \brief NextToken Looking for the next token in the string. The string must
@@ -191,7 +189,7 @@ public:
* \param [in] val The number associated with the keyword.
* \return Ture if the number is available false oterhwise.
*/
- static bool DefineNum(const char* name, long val);
+ static bool DefineNum(const std::string& name, long val);
/*!
* \brief Free Free the array created with DefineNum.
@@ -211,9 +209,9 @@ private:
long m_IdKeyWord;
//! The token string
- CBotString m_Text;
+ std::string m_Text;
//! The token separator
- CBotString m_Sep;
+ std::string m_Sep;
//! The strat position of the token in the CBotProgram
int m_start;
@@ -225,7 +223,7 @@ private:
* \param w The word to compare.
* \return -1 if this is not a keyword the keyword number otherwise.
*/
- static int GetKeyWords(const char* w); // is it a keyword?
+ static int GetKeyWords(const std::string& w); // is it a keyword?
/*!
* \brief GetKeyDefNum Check if this is a defined word and set the defined
@@ -234,18 +232,18 @@ private:
* \param [out] token The token in which the type will be set.
* \return True if the defined word is found false otherwise.
*/
- static bool GetKeyDefNum(const char* w, CBotToken* &token);
+ static bool GetKeyDefNum(const std::string& w, CBotToken*& token);
/*!
* \brief LoadKeyWords Loads the list of keywords. The list of keyword is
- * CBotString::s_keywordString. This keywords are keywords languages (if, +,
+ * std::string::s_keywordString. This keywords are keywords languages (if, +,
* for, while, case, extern ...)
* \todo Fixme Figure out how this should work.
*/
static void LoadKeyWords();
//! List of keywords of the CBot language (if, +, for, while, case, extern ...)
- static std::vector<CBotString> m_ListKeyWords;
+ static std::vector<std::string> m_ListKeyWords;
//! List of id correponding to the keywords of the CBot language
static int m_ListIdKeyWords[200];
@@ -253,7 +251,7 @@ private:
//! This keywords are defined in :
//! - void CScriptFunctions::Init()
//! - void CBotProgram::Init()
- static std::vector<CBotString> m_ListKeyDefine;
+ static std::vector<std::string> m_ListKeyDefine;
//! List of id correponding to the defined words
static long m_ListKeyNums[MAXDEFNUM];
diff --git a/src/CBot/CBotTypResult.cpp b/src/CBot/CBotTypResult.cpp
index bde4f74..c4f9ee2 100644
--- a/src/CBot/CBotTypResult.cpp
+++ b/src/CBot/CBotTypResult.cpp
@@ -43,7 +43,7 @@ CBotTypResult::CBotTypResult(int type)
}
////////////////////////////////////////////////////////////////////////////////
-CBotTypResult::CBotTypResult(int type, const char* name)
+CBotTypResult::CBotTypResult(int type, const std::string& name)
{
m_type = type;
m_pNext = nullptr;
diff --git a/src/CBot/CBotTypResult.h b/src/CBot/CBotTypResult.h
index 97ac52a..f992f01 100644
--- a/src/CBot/CBotTypResult.h
+++ b/src/CBot/CBotTypResult.h
@@ -24,6 +24,7 @@
// Local include
// Global include
+#include <string>
class CBotClass;
@@ -55,7 +56,7 @@ public:
// for simple types (CBotTypInt à CBotTypString)
- CBotTypResult(int type, const char* name);
+ CBotTypResult(int type, const std::string& name);
// for pointer types and intrinsic classes
CBotTypResult(int type, CBotClass* pClass);
diff --git a/src/CBot/CBotUtils.cpp b/src/CBot/CBotUtils.cpp
index 715a84c..c098e46 100644
--- a/src/CBot/CBotUtils.cpp
+++ b/src/CBot/CBotUtils.cpp
@@ -120,14 +120,14 @@ bool WriteWord(FILE* pf, unsigned short w)
}
////////////////////////////////////////////////////////////////////////////////
-bool WriteString(FILE* pf, CBotString s)
+bool WriteString(FILE* pf, std::string s)
{
size_t lg1, lg2;
- lg1 = s.GetLength();
+ lg1 = s.size();
if (!WriteWord(pf, lg1)) return false;
- lg2 = fwrite(s, 1, lg1, pf );
+ lg2 = fwrite(s.c_str(), 1, lg1, pf );
return (lg1 == lg2);
}
@@ -142,46 +142,9 @@ bool WriteFloat(FILE* pf, float w)
}
////////////////////////////////////////////////////////////////////////////////
-void ConstructElement(CBotString* pNewData)
-{
- memset(pNewData, 0, sizeof(CBotString));
-}
-
-////////////////////////////////////////////////////////////////////////////////
-void DestructElement(CBotString* pOldData)
-{
- pOldData->~CBotString();
-}
-
-////////////////////////////////////////////////////////////////////////////////
-void CopyElement(CBotString* pSrc, CBotString* pDest)
-{
- *pSrc = *pDest;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-void ConstructElements(CBotString* pNewData, int nCount)
-{
- while (nCount--)
- {
- ConstructElement(pNewData);
- pNewData++;
- }
-}
-
-////////////////////////////////////////////////////////////////////////////////
-void DestructElements(CBotString* pOldData, int nCount)
-{
- while (nCount--)
- {
- DestructElement(pOldData);
- pOldData++;
- }
-}
-
-////////////////////////////////////////////////////////////////////////////////
-long GetNumInt(const char* p)
+long GetNumInt(const std::string& str)
{
+ const char* p = str.c_str();
long num = 0;
while (*p >= '0' && *p <= '9')
{
@@ -214,8 +177,9 @@ long GetNumInt(const char* p)
}
////////////////////////////////////////////////////////////////////////////////
-float GetNumFloat(const char* p)
+float GetNumFloat(const std::string& str)
{
+ const char* p = str.c_str();
double num = 0;
double div = 10;
bool bNeg = false;
diff --git a/src/CBot/CBotUtils.h b/src/CBot/CBotUtils.h
index 819331c..74914ca 100644
--- a/src/CBot/CBotUtils.h
+++ b/src/CBot/CBotUtils.h
@@ -20,16 +20,15 @@
#pragma once
// Modules inlcude
-#include "CBot/CBotString.h"
#include "CBot/CBotTypResult.h"
// Local include
// Global include
#include <cstdio>
+#include <string>
// Forward declaration
-class CBotString;
class CBotVar;
class CBotToken;
class CBotCStack;
@@ -74,7 +73,7 @@ bool WriteWord(FILE* pf, unsigned short w);
* \param s
* \return
*/
-bool WriteString(FILE* pf, CBotString s);
+bool WriteString(FILE* pf, std::string s);
/*!
* \brief WriteFloat
@@ -85,49 +84,16 @@ bool WriteString(FILE* pf, CBotString s);
bool WriteFloat(FILE* pf, float w);
/*!
- * \brief ConstructElement
- * \param pNewData
- */
-void ConstructElement(CBotString* pNewData);
-
-/*!
- * \brief DestructElement
- * \param pOldData
- */
-void DestructElement(CBotString* pOldData);
-
-/*!
- * \brief CopyElement
- * \param pSrc
- * \param pDest
- */
-void CopyElement(CBotString* pSrc, CBotString* pDest);
-
-/*!
- * \brief ConstructElements
- * \param pNewData
- * \param nCount
- */
-void ConstructElements(CBotString* pNewData, int nCount);
-
-/*!
- * \brief DestructElements
- * \param pOldData
- * \param nCount
- */
-void DestructElements(CBotString* pOldData, int nCount);
-
-/*!
* \brief GetNumInt Converts a string into integer may be of the form 0xabc123.
* \param p
* \return
*/
-long GetNumInt(const char* p);
+long GetNumInt(const std::string& p);
/*!
* \brief GetNumFloat Converts a string into a float number.
* \param p
* \return
*/
-float GetNumFloat(const char* p);
+float GetNumFloat(const std::string& str);
diff --git a/src/CBot/CBotVar/CBotVar.cpp b/src/CBot/CBotVar/CBotVar.cpp
index 43a6a34..fc41945 100644
--- a/src/CBot/CBotVar/CBotVar.cpp
+++ b/src/CBot/CBotVar/CBotVar.cpp
@@ -41,6 +41,7 @@
#include <cassert>
#include <cmath>
#include <cstdio>
+#include <string>
////////////////////////////////////////////////////////////////////////////////
long CBotVar::m_identcpt = 0;
@@ -71,7 +72,7 @@ CBotVar::~CBotVar( )
void CBotVar::debug()
{
// const char* p = static_cast<const char*>( m_token->GetString());
- CBotString s = static_cast<const char*>( GetValString());
+ std::string s = GetValString();
// const char* v = static_cast<const char*> (s);
if ( m_type.Eq(CBotTypClass) )
@@ -221,7 +222,7 @@ CBotVar* CBotVar::Create( CBotVar* pVar )
}
////////////////////////////////////////////////////////////////////////////////
-CBotVar* CBotVar::Create( const char* n, CBotTypResult type)
+CBotVar* CBotVar::Create(const std::string& n, CBotTypResult type)
{
CBotToken name(n);
@@ -286,7 +287,7 @@ CBotVar* CBotVar::Create( const char* n, CBotTypResult type)
}
////////////////////////////////////////////////////////////////////////////////
-CBotVar* CBotVar::Create( const char* name, int type, CBotClass* pClass)
+CBotVar* CBotVar::Create(const std::string& name, int type, CBotClass* pClass)
{
CBotToken token( name, "" );
CBotVar* pVar = Create( &token, type );
@@ -308,7 +309,7 @@ CBotVar* CBotVar::Create( const char* name, int type, CBotClass* pClass)
}
////////////////////////////////////////////////////////////////////////////////
-CBotVar* CBotVar::Create( const char* name, CBotClass* pClass)
+CBotVar* CBotVar::Create(const std::string& name, CBotClass* pClass)
{
CBotToken token( name, "" );
CBotVar* pVar = Create( &token, CBotTypResult( CBotTypClass, pClass ) );
@@ -390,13 +391,13 @@ void CBotVar::SetInit(CBotVar::InitType bInit)
}
////////////////////////////////////////////////////////////////////////////////
-CBotString CBotVar::GetName()
+std::string CBotVar::GetName()
{
return m_token->GetString();
}
////////////////////////////////////////////////////////////////////////////////
-void CBotVar::SetName(const char* name)
+void CBotVar::SetName(const std::string& name)
{
m_token->SetString(name);
}
@@ -408,7 +409,7 @@ CBotToken* CBotVar::GetToken()
}
////////////////////////////////////////////////////////////////////////////////
-CBotVar* CBotVar::GetItem(const char* name)
+CBotVar* CBotVar::GetItem(const std::string& name)
{
assert(0);
return nullptr;
@@ -436,7 +437,7 @@ CBotVar* CBotVar::GetItem(int row, bool bGrow)
}
////////////////////////////////////////////////////////////////////////////////
-bool CBotVar::IsElemOfClass(const char* name)
+bool CBotVar::IsElemOfClass(const std::string& name)
{
CBotClass* pc = nullptr;
@@ -579,7 +580,7 @@ float CBotVar::GetValFloat()
}
////////////////////////////////////////////////////////////////////////////////
-void CBotVar::SetValInt(int c, const char* s)
+void CBotVar::SetValInt(int c, const std::string& s)
{
assert(0);
}
@@ -737,16 +738,16 @@ void CBotVar::Copy(CBotVar* pSrc, bool bName)
}
////////////////////////////////////////////////////////////////////////////////
-void CBotVar::SetValString(const char* p)
+void CBotVar::SetValString(const std::string& p)
{
assert(0);
}
////////////////////////////////////////////////////////////////////////////////
-CBotString CBotVar::GetValString()
+std::string CBotVar::GetValString()
{
assert(0);
- return CBotString();
+ return std::string();
}
////////////////////////////////////////////////////////////////////////////////
diff --git a/src/CBot/CBotVar/CBotVar.h b/src/CBot/CBotVar/CBotVar.h
index 56a5d5d..6f95db4 100644
--- a/src/CBot/CBotVar/CBotVar.h
+++ b/src/CBot/CBotVar/CBotVar.h
@@ -21,16 +21,18 @@
// Modules inlcude
#include "CBot/CBotDefines.h"
-
-#include "CBot/CBotString.h"
+#include "CBot/CBotTypResult.h"
// Local include
// Global include
+#include <string>
// Forward declaration
class CBotVarClass;
class CBotInstr;
+class CBotClass;
+class CBotToken;
/*!
* \brief The CBotVar class Class for managing variables. May be useful to the
@@ -68,7 +70,7 @@ public:
* \param type
* \return
*/
- static CBotVar* Create( const char* name, CBotTypResult type);
+ static CBotVar* Create(const std::string& name, CBotTypResult type);
/*!
* \brief Create Creates from one instance of a known class.
@@ -76,7 +78,7 @@ public:
* \param pClass
* \return
*/
- static CBotVar* Create( const char* name, CBotClass* pClass);
+ static CBotVar* Create(const std::string& name, CBotClass* pClass);
/*!
* \brief Create Creates a variable depending on its type.
@@ -101,7 +103,7 @@ public:
* \param pClass
* \return
*/
- static CBotVar* Create( const char* name, int type, CBotClass* pClass);
+ static CBotVar* Create(const std::string& name, int type, CBotClass* pClass);
/*!
* \brief Create
@@ -139,13 +141,13 @@ public:
* \brief GetName The name of the variable, if known.
* \return
*/
- CBotString GetName();
+ std::string GetName();
/*!
* \brief SetName Changes the name of the variable
* \param name
*/
- void SetName(const char* name);
+ void SetName(const std::string& name);
/*!
* \brief GetType Returns the base type (int) of the variable
@@ -251,7 +253,7 @@ public:
* \param name
* \return
*/
- virtual CBotVar* GetItem(const char* name);
+ virtual CBotVar* GetItem(const std::string& name);
/*!
* \brief GetItemRef
@@ -287,7 +289,7 @@ public:
* \param name
* \return
*/
- bool IsElemOfClass(const char* name);
+ bool IsElemOfClass(const std::string& name);
/*!
* \brief GetNext Next variable in the list (parameters).
@@ -313,7 +315,7 @@ public:
* \param val
* \param name
*/
- virtual void SetValInt(int val, const char* name = nullptr);
+ virtual void SetValInt(int val, const std::string& name = "");
/*!
* \brief SetValFloat Initialized with a real value (#).
@@ -325,7 +327,7 @@ public:
* \brief SetValString Initialized with a string value (#).
* \param p
*/
- virtual void SetValString(const char* p);
+ virtual void SetValString(const std::string& p);
/*!
* \brief GetValInt Request the full value (#).
@@ -343,7 +345,7 @@ public:
* \brief GetValString Request the string value (#).
* \return
*/
- virtual CBotString GetValString();
+ virtual std::string GetValString();
/*!
* \brief SetClass
diff --git a/src/CBot/CBotVar/CBotVarArray.cpp b/src/CBot/CBotVar/CBotVarArray.cpp
index f24dd20..aa01b66 100644
--- a/src/CBot/CBotVar/CBotVarArray.cpp
+++ b/src/CBot/CBotVar/CBotVarArray.cpp
@@ -131,9 +131,9 @@ CBotVar* CBotVarArray::GetItemList()
}
////////////////////////////////////////////////////////////////////////////////
-CBotString CBotVarArray::GetValString()
+std::string CBotVarArray::GetValString()
{
- if ( m_pInstance == nullptr ) return ( CBotString( "Null pointer" ) ) ;
+ if ( m_pInstance == nullptr ) return ( std::string( "Null pointer" ) ) ;
return m_pInstance->GetValString();
}
diff --git a/src/CBot/CBotVar/CBotVarArray.h b/src/CBot/CBotVar/CBotVarArray.h
index 542984d..5ce4b5b 100644
--- a/src/CBot/CBotVar/CBotVarArray.h
+++ b/src/CBot/CBotVar/CBotVarArray.h
@@ -86,7 +86,7 @@ public:
* \brief GetValString Gets the contents of the array into a string.
* \return
*/
- CBotString GetValString() override;
+ std::string GetValString() override;
/*!
* \brief Save1State
diff --git a/src/CBot/CBotVar/CBotVarBoolean.cpp b/src/CBot/CBotVar/CBotVarBoolean.cpp
index 7a177e0..10d33bd 100644
--- a/src/CBot/CBotVar/CBotVarBoolean.cpp
+++ b/src/CBot/CBotVar/CBotVarBoolean.cpp
@@ -64,7 +64,7 @@ void CBotVarBoolean::Copy(CBotVar* pSrc, bool bName)
}
////////////////////////////////////////////////////////////////////////////////
-void CBotVarBoolean::SetValInt(int val, const char* s)
+void CBotVarBoolean::SetValInt(int val, const std::string& s)
{
m_val = static_cast<bool>(val);
m_binit = CBotVar::InitType::DEF;
@@ -90,11 +90,11 @@ float CBotVarBoolean::GetValFloat()
}
////////////////////////////////////////////////////////////////////////////////
-CBotString CBotVarBoolean::GetValString()
+std::string CBotVarBoolean::GetValString()
{
- CBotString ret;
+ std::string ret;
- CBotString res;
+ std::string res;
if ( m_binit == CBotVar::InitType::UNDEF )
{
diff --git a/src/CBot/CBotVar/CBotVarBoolean.h b/src/CBot/CBotVar/CBotVarBoolean.h
index 0451f6d..9ac52fe 100644
--- a/src/CBot/CBotVar/CBotVarBoolean.h
+++ b/src/CBot/CBotVar/CBotVarBoolean.h
@@ -47,7 +47,7 @@ public:
* \param val
* \param s
*/
- void SetValInt(int val, const char* s = nullptr) override;
+ void SetValInt(int val, const std::string& s = nullptr) override;
/*!
* \brief SetValFloat
@@ -71,7 +71,7 @@ public:
* \brief GetValString
* \return
*/
- CBotString GetValString() override;
+ std::string GetValString() override;
/*!
* \brief Copy Copy a variable into another.
diff --git a/src/CBot/CBotVar/CBotVarClass.cpp b/src/CBot/CBotVar/CBotVarClass.cpp
index 894ff03..484cbb2 100644
--- a/src/CBot/CBotVar/CBotVarClass.cpp
+++ b/src/CBot/CBotVar/CBotVarClass.cpp
@@ -268,7 +268,7 @@ void CBotVarClass::Maj(void* pUser, bool bContinu)
}
////////////////////////////////////////////////////////////////////////////////
-CBotVar* CBotVarClass::GetItem(const char* name)
+CBotVar* CBotVarClass::GetItem(const std::string& name)
{
CBotVar* p = m_pVar;
@@ -335,15 +335,15 @@ CBotVar* CBotVarClass::GetItemList()
}
////////////////////////////////////////////////////////////////////////////////
-CBotString CBotVarClass::GetValString()
+std::string CBotVarClass::GetValString()
{
// if ( m_Indirect != nullptr) return m_Indirect->GetValString();
- CBotString res;
+ std::string res;
if ( m_pClass != nullptr ) // not used for an array
{
- res = m_pClass->GetName() + CBotString("( ");
+ res = m_pClass->GetName() + std::string("( ");
CBotVarClass* my = this;
while ( my != nullptr )
@@ -351,7 +351,7 @@ CBotString CBotVarClass::GetValString()
CBotVar* pv = my->m_pVar;
while ( pv != nullptr )
{
- res += pv->GetName() + CBotString("=");
+ res += pv->GetName() + std::string("=");
if ( pv->IsStatic() )
{
@@ -423,7 +423,7 @@ void CBotVarClass::DecrementUse()
pThis->SetPointer(this);
CBotVar* pResult = nullptr;
- CBotString nom = CBotString("~") + m_pClass->GetName();
+ std::string nom = std::string("~") + m_pClass->GetName();
long ident = 0;
while ( pile->IsOk() && !m_pClass->ExecuteMethode(ident, nom, pThis, ppVars, pResult, pile, nullptr)) ; // waits for the end
diff --git a/src/CBot/CBotVar/CBotVarClass.h b/src/CBot/CBotVar/CBotVarClass.h
index a04fccc..7d564d9 100644
--- a/src/CBot/CBotVar/CBotVarClass.h
+++ b/src/CBot/CBotVar/CBotVarClass.h
@@ -70,7 +70,7 @@ public:
* \param name
* \return
*/
- CBotVar* GetItem(const char* name) override;
+ CBotVar* GetItem(const std::string& name) override;
/*!
* \brief GetItemRef
@@ -98,7 +98,7 @@ public:
* \brief GetValString
* \return
*/
- CBotString GetValString() override;
+ std::string GetValString() override;
/*!
* \brief Save1State
diff --git a/src/CBot/CBotVar/CBotVarFloat.cpp b/src/CBot/CBotVar/CBotVarFloat.cpp
index 29dbdae..e5b4132 100644
--- a/src/CBot/CBotVar/CBotVarFloat.cpp
+++ b/src/CBot/CBotVar/CBotVarFloat.cpp
@@ -67,7 +67,7 @@ void CBotVarFloat::Copy(CBotVar* pSrc, bool bName)
}
////////////////////////////////////////////////////////////////////////////////
-void CBotVarFloat::SetValInt(int val, const char* s)
+void CBotVarFloat::SetValInt(int val, const std::string& s)
{
m_val = static_cast<float>(val);
m_binit = CBotVar::InitType::DEF;
@@ -93,9 +93,9 @@ float CBotVarFloat::GetValFloat()
}
////////////////////////////////////////////////////////////////////////////////
-CBotString CBotVarFloat::GetValString()
+std::string CBotVarFloat::GetValString()
{
- CBotString res;
+ std::string res;
if ( m_binit == CBotVar::InitType::UNDEF )
{
diff --git a/src/CBot/CBotVar/CBotVarFloat.h b/src/CBot/CBotVar/CBotVarFloat.h
index 37a121b..c8821a5 100644
--- a/src/CBot/CBotVar/CBotVarFloat.h
+++ b/src/CBot/CBotVar/CBotVarFloat.h
@@ -45,7 +45,7 @@ public:
* \param val
* \param s
*/
- void SetValInt(int val, const char* s = nullptr) override;
+ void SetValInt(int val, const std::string& s = nullptr) override;
/*!
* \brief SetValFloat
@@ -69,7 +69,7 @@ public:
* \brief GetValString
* \return
*/
- CBotString GetValString() override;
+ std::string GetValString() override;
/*!
* \brief Copy Copy a variable into another.
diff --git a/src/CBot/CBotVar/CBotVarInt.cpp b/src/CBot/CBotVar/CBotVarInt.cpp
index 52b9e5c..3e3a182 100644
--- a/src/CBot/CBotVar/CBotVarInt.cpp
+++ b/src/CBot/CBotVar/CBotVarInt.cpp
@@ -66,7 +66,7 @@ void CBotVarInt::Copy(CBotVar* pSrc, bool bName)
}
////////////////////////////////////////////////////////////////////////////////
-void CBotVarInt::SetValInt(int val, const char* defnum)
+void CBotVarInt::SetValInt(int val, const std::string& defnum)
{
m_val = val;
m_binit = CBotVar::InitType::DEF;
@@ -93,11 +93,11 @@ float CBotVarInt::GetValFloat()
}
////////////////////////////////////////////////////////////////////////////////
-CBotString CBotVarInt::GetValString()
+std::string CBotVarInt::GetValString()
{
- if ( !m_defnum.IsEmpty() ) return m_defnum;
+ if ( !m_defnum.empty() ) return m_defnum;
- CBotString res;
+ std::string res;
if ( m_binit == CBotVar::InitType::UNDEF )
{
@@ -216,27 +216,27 @@ void CBotVarInt::SR(CBotVar* left, CBotVar* right)
////////////////////////////////////////////////////////////////////////////////
void CBotVarInt::Neg()
{
- m_val = -m_val;
+ m_val = -m_val;
}
////////////////////////////////////////////////////////////////////////////////
void CBotVarInt::Not()
{
- m_val = ~m_val;
+ m_val = ~m_val;
}
////////////////////////////////////////////////////////////////////////////////
void CBotVarInt::Inc()
{
- m_val++;
- m_defnum.Empty();
+ m_val++;
+ m_defnum.empty();
}
////////////////////////////////////////////////////////////////////////////////
void CBotVarInt::Dec()
{
- m_val--;
- m_defnum.Empty();
+ m_val--;
+ m_defnum.empty();
}
////////////////////////////////////////////////////////////////////////////////
@@ -278,7 +278,7 @@ bool CBotVarInt::Ne(CBotVar* left, CBotVar* right)
////////////////////////////////////////////////////////////////////////////////
bool CBotVarInt::Save0State(FILE* pf)
{
- if ( !m_defnum.IsEmpty() )
+ if ( !m_defnum.empty() )
{
if(!WriteWord(pf, 200 )) return false; // special marker
if(!WriteString(pf, m_defnum)) return false; // name of the value
diff --git a/src/CBot/CBotVar/CBotVarInt.h b/src/CBot/CBotVar/CBotVarInt.h
index 0d8372e..16da788 100644
--- a/src/CBot/CBotVar/CBotVarInt.h
+++ b/src/CBot/CBotVar/CBotVarInt.h
@@ -45,7 +45,7 @@ public:
* \param val
* \param s
*/
- void SetValInt(int val, const char* s = nullptr) override;
+ void SetValInt(int val, const std::string& s = nullptr) override;
/*!
* \brief SetValFloat
@@ -69,7 +69,7 @@ public:
* \brief GetValString
* \return
*/
- CBotString GetValString() override;
+ std::string GetValString() override;
/*!
* \brief Copy Copy a variable in to another.
@@ -250,6 +250,6 @@ private:
//! The value.
int m_val;
//! The name if given by DefineNum.
- CBotString m_defnum;
+ std::string m_defnum;
friend class CBotVar;
};
diff --git a/src/CBot/CBotVar/CBotVarPointer.cpp b/src/CBot/CBotVar/CBotVarPointer.cpp
index de0f166..18b4d59 100644
--- a/src/CBot/CBotVar/CBotVarPointer.cpp
+++ b/src/CBot/CBotVar/CBotVarPointer.cpp
@@ -23,9 +23,9 @@
#include "CBot/CBotClass.h"
#include "CBot/CBotVar/CBotVarClass.h"
-#include "CBot/CBotFileUtils.h"
-
#include "CBot/CBotEnums.h"
+#include "CBot/CBotUtils.h"
+#include "CBot/CBotFileUtils.h"
// Local include
@@ -71,7 +71,7 @@ void CBotVarPointer::Maj(void* pUser, bool bContinu)
}
////////////////////////////////////////////////////////////////////////////////
-CBotVar* CBotVarPointer::GetItem(const char* name)
+CBotVar* CBotVarPointer::GetItem(const std::string& name)
{
if ( m_pVarClass == nullptr) // no existing instance?
return m_pClass->GetItem(name); // makes the pointer in the class itself
@@ -96,9 +96,9 @@ CBotVar* CBotVarPointer::GetItemList()
}
////////////////////////////////////////////////////////////////////////////////
-CBotString CBotVarPointer::GetValString()
+std::string CBotVarPointer::GetValString()
{
- CBotString s = "Pointer to ";
+ std::string s = "Pointer to ";
if ( m_pVarClass == nullptr ) s = "Null pointer" ;
else s += m_pVarClass->GetValString();
return s;
diff --git a/src/CBot/CBotVar/CBotVarPointer.h b/src/CBot/CBotVar/CBotVarPointer.h
index 8f54f58..c7800bc 100644
--- a/src/CBot/CBotVar/CBotVarPointer.h
+++ b/src/CBot/CBotVar/CBotVarPointer.h
@@ -71,7 +71,7 @@ public:
* \param name
* \return
*/
- CBotVar* GetItem(const char* name) override;
+ CBotVar* GetItem(const std::string& name) override;
/*!
* \brief GetItemRef
@@ -90,7 +90,7 @@ public:
* \brief GetValString
* \return
*/
- CBotString GetValString() override;
+ std::string GetValString() override;
/*!
* \brief SetPointer Initializes the pointer to the instance of a class.
diff --git a/src/CBot/CBotVar/CBotVarString.cpp b/src/CBot/CBotVar/CBotVarString.cpp
index 425733f..5cf3d47 100644
--- a/src/CBot/CBotVar/CBotVarString.cpp
+++ b/src/CBot/CBotVar/CBotVarString.cpp
@@ -43,7 +43,7 @@ CBotVarString::CBotVarString( const CBotToken* name )
m_bStatic = false;
m_mPrivate = 0;
- m_val.Empty();
+ m_val.clear();
}
////////////////////////////////////////////////////////////////////////////////
@@ -65,14 +65,14 @@ void CBotVarString::Copy(CBotVar* pSrc, bool bName)
}
////////////////////////////////////////////////////////////////////////////////
-void CBotVarString::SetValString(const char* p)
+void CBotVarString::SetValString(const std::string& p)
{
m_val = p;
m_binit = CBotVar::InitType::DEF;
}
////////////////////////////////////////////////////////////////////////////////
-CBotString CBotVarString::GetValString()
+std::string CBotVarString::GetValString()
{
if ( m_binit == CBotVar::InitType::UNDEF )
{
diff --git a/src/CBot/CBotVar/CBotVarString.h b/src/CBot/CBotVar/CBotVarString.h
index 662e1d9..b291c5e 100644
--- a/src/CBot/CBotVar/CBotVarString.h
+++ b/src/CBot/CBotVar/CBotVarString.h
@@ -44,13 +44,13 @@ public:
* \brief SetValString
* \param p
*/
- void SetValString(const char* p) override;
+ void SetValString(const std::string& p) override;
/*!
* \brief GetValString
* \return
*/
- CBotString GetValString() override;
+ std::string GetValString() override;
/*!
* \brief Copy Copy a variable into another.
@@ -123,5 +123,5 @@ public:
private:
//! The value.
- CBotString m_val;
+ std::string m_val;
};
diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt
index 3f07eb5..08f8356 100644
--- a/src/CBot/CMakeLists.txt
+++ b/src/CBot/CMakeLists.txt
@@ -5,12 +5,12 @@ set(SOURCES
CBotProgram.cpp
CBotStack.cpp
CBotCStack.cpp
- CBotString.cpp
CBotToken.cpp
CBotCall.cpp
CBotDefParam.cpp
CBotCallMethode.cpp
CBotTypResult.cpp
+ CBotKeywordStrings.cpp
StringFunctions.cpp
CBotInstr/CBotInstr.cpp
CBotInstr/CBotInstrUtils.cpp
@@ -67,7 +67,7 @@ set(SOURCES
CBotVar/CBotVarFloat.cpp
CBotVar/CBotVarInt.cpp
CBotVar/CBotVar.cpp
- CBotKeywordStrings.cpp CBotKeywordStrings.h)
+)
# Includes
set(LOCAL_INCLUDES
diff --git a/src/CBot/StringFunctions.cpp b/src/CBot/StringFunctions.cpp
index e323fe3..7ffe425 100644
--- a/src/CBot/StringFunctions.cpp
+++ b/src/CBot/StringFunctions.cpp
@@ -24,11 +24,13 @@
#include "CBot/CBotEnums.h"
#include "CBot/CBotVar/CBotVar.h"
+#include "CBot/CBotUtils.h"
// Local include
// Global include
+#include <boost/algorithm/string.hpp>
////////////////////////////////////////////////////////////////////////////////
bool rStrLen( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
@@ -43,10 +45,10 @@ bool rStrLen( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
if ( pVar->GetNext() != nullptr ) { ex = TX_OVERPARAM ; return true; }
// get the contents of the string
- CBotString s = pVar->GetValString();
+ std::string s = pVar->GetValString();
// puts the length of the stack
- pResult->SetValInt( s.GetLength() );
+ pResult->SetValInt( s.length() );
return true;
}
@@ -77,7 +79,7 @@ bool rStrLeft( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
if ( pVar->GetType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// get the contents of the string
- CBotString s = pVar->GetValString();
+ std::string s = pVar->GetValString();
// it takes a second parameter
pVar = pVar->GetNext();
@@ -93,7 +95,7 @@ bool rStrLeft( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
if ( pVar->GetNext() != nullptr ) { ex = TX_OVERPARAM ; return true; }
// takes the interesting part
- s = s.Left( n );
+ s = s.substr(0, n);
// puts on the stack
pResult->SetValString( s );
@@ -135,7 +137,7 @@ bool rStrRight( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
if ( pVar->GetType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// get the contents of the string
- CBotString s = pVar->GetValString();
+ std::string s = pVar->GetValString();
// it takes a second parameter
pVar = pVar->GetNext();
@@ -151,7 +153,7 @@ bool rStrRight( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
if ( pVar->GetNext() != nullptr ) { ex = TX_OVERPARAM ; return true; }
// takes the interesting part
- s = s.Right( n );
+ s = s.substr(s.length()-n, std::string::npos);
// puts on the stack
pResult->SetValString( s );
@@ -168,7 +170,7 @@ bool rStrMid( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
if ( pVar->GetType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// get the contents of the string
- CBotString s = pVar->GetValString();
+ std::string s = pVar->GetValString();
// it takes a second parameter
pVar = pVar->GetNext();
@@ -195,12 +197,12 @@ bool rStrMid( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
if ( pVar->GetNext() != nullptr ){ ex = TX_OVERPARAM ; return true; }
// takes the interesting part
- s = s.Mid( n, l );
+ s = s.substr(n, l);
}
else
{
// takes the interesting part
- s = s.Mid( n );
+ s = s.substr(n);
}
// puts on the stack
@@ -253,7 +255,7 @@ bool rStrVal( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
if ( pVar->GetType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// get the contents of the string
- CBotString s = pVar->GetValString();
+ std::string s = pVar->GetValString();
// but no second parameter
if ( pVar->GetNext() != nullptr ){ ex = TX_OVERPARAM ; return true; }
@@ -292,7 +294,7 @@ bool rStrFind( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
if ( pVar->GetType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// get the contents of the string
- CBotString s = pVar->GetValString();
+ std::string s = pVar->GetValString();
// it takes a second parameter
pVar = pVar->GetNext();
@@ -302,14 +304,14 @@ bool rStrFind( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
if ( pVar->GetType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// retrieves this number
- CBotString s2 = pVar->GetValString();
+ std::string s2 = pVar->GetValString();
// no third parameter
if ( pVar->GetNext() != nullptr ) { ex = TX_OVERPARAM ; return true; }
// puts the result on the stack
- int res = s.Find(s2);
- pResult->SetValInt( res );
+ std::size_t res = s.find(s2);
+ pResult->SetValInt( res != std::string::npos ? res : -1 );
if ( res < 0 ) pResult->SetInit( CBotVar::InitType::IS_NAN );
return true;
}
@@ -349,13 +351,13 @@ bool rStrUpper( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
if ( pVar->GetType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// get the contents of the string
- CBotString s = pVar->GetValString();
+ std::string s = pVar->GetValString();
// but no second parameter
if ( pVar->GetNext() != nullptr ){ ex = TX_OVERPARAM ; return true; }
- s.MakeUpper();
+ boost::to_upper(s);
// puts the value on the stack
pResult->SetValString( s );
@@ -372,13 +374,13 @@ bool rStrLower( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
if ( pVar->GetType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// get the contents of the string
- CBotString s = pVar->GetValString();
+ std::string s = pVar->GetValString();
// but no second parameter
if ( pVar->GetNext() != nullptr ){ ex = TX_OVERPARAM ; return true; }
- s.MakeLower();
+ boost::to_lower(s);
// puts the value on the stack
pResult->SetValString( s );
diff --git a/src/script/script.cpp b/src/script/script.cpp
index 42d2fd6..4e70817 100644
--- a/src/script/script.cpp
+++ b/src/script/script.cpp
@@ -158,8 +158,8 @@ bool CScript::CheckToken()
{
CBotToken* bt;
CBotToken* allBt;
- CBotString bs;
- const char* token;
+ std::string bs;
+ std::string token;
int error, cursor1, cursor2, i;
char used[100];
@@ -186,13 +186,13 @@ bool CScript::CheckToken()
cursor1 = bt->GetStart();
cursor2 = bt->GetEnd();
- i = m_main->IsObligatoryToken(token);
+ i = m_main->IsObligatoryToken(token.c_str());
if ( i != -1 )
{
used[i] = 1; // token used
}
- if ( !m_main->IsProhibitedToken(token) )
+ if ( !m_main->IsProhibitedToken(token.c_str()) )
{
m_error = ERR_PROHIBITEDTOKEN;
m_cursor1 = cursor1;
@@ -228,9 +228,9 @@ bool CScript::CheckToken()
bool CScript::Compile()
{
- std::vector<CBotString> functionList;
+ std::vector<std::string> functionList;
int i;
- const char* p;
+ std::string p;
m_error = 0;
m_cursor1 = 0;
@@ -486,8 +486,7 @@ bool CScript::IsContinue()
bool CScript::GetCursor(int &cursor1, int &cursor2)
{
- const char* funcName;
-
+ std::string funcName;
cursor1 = cursor2 = 0;
if (m_botProg == nullptr) return false;
@@ -508,11 +507,10 @@ bool CScript::GetCursor(int &cursor1, int &cursor2)
void PutList(const char *baseName, bool bArray, CBotVar *var, Ui::CList *list, int &rankList)
{
- CBotString bs;
CBotVar *svar, *pStatic;
char varName[100];
char buffer[100];
- const char *p;
+ std::string p;
int index, type;
if ( var == nullptr && baseName[0] != 0 )
@@ -528,8 +526,7 @@ void PutList(const char *baseName, bool bArray, CBotVar *var, Ui::CList *list, i
var->Maj(nullptr, false);
pStatic = var->GetStaticVar(); // finds the static element
- bs = pStatic->GetName(); // variable name
- p = bs;
+ p = pStatic->GetName(); // variable name
//? if ( strcmp(p, "this") == 0 )
//? {
//? var = var->GetNext();
@@ -538,7 +535,7 @@ void PutList(const char *baseName, bool bArray, CBotVar *var, Ui::CList *list, i
if ( baseName[0] == 0 )
{
- sprintf(varName, "%s", p);
+ sprintf(varName, "%s", p.c_str());
}
else
{
@@ -548,7 +545,7 @@ void PutList(const char *baseName, bool bArray, CBotVar *var, Ui::CList *list, i
}
else
{
- sprintf(varName, "%s.%s", baseName, p);
+ sprintf(varName, "%s.%s", baseName, p.c_str());
}
}
@@ -556,18 +553,14 @@ void PutList(const char *baseName, bool bArray, CBotVar *var, Ui::CList *list, i
if ( type < CBotTypBoolean )
{
- CBotString value;
- value = pStatic->GetValString();
- p = value;
- sprintf(buffer, "%s = %s;", varName, p);
+ p = pStatic->GetValString();
+ sprintf(buffer, "%s = %s;", varName, p.c_str());
list->SetItemName(rankList++, buffer);
}
else if ( type == CBotTypString )
{
- CBotString value;
- value = pStatic->GetValString();
- p = value;
- sprintf(buffer, "%s = \"%s\";", varName, p);
+ p = pStatic->GetValString();
+ sprintf(buffer, "%s = \"%s\";", varName, p.c_str());
list->SetItemName(rankList++, buffer);
}
else if ( type == CBotTypArrayPointer )
@@ -597,7 +590,7 @@ void PutList(const char *baseName, bool bArray, CBotVar *var, Ui::CList *list, i
void CScript::UpdateList(Ui::CList* list)
{
CBotVar *var;
- const char *progName, *funcName;
+ std::string progName, funcName;
int total, select, level, cursor1, cursor2, rank;
if (m_botProg == nullptr) return;
@@ -607,7 +600,7 @@ void CScript::UpdateList(Ui::CList* list)
list->Flush(); // empty list
m_botProg->GetRunPos(progName, cursor1, cursor2);
- if ( progName == nullptr ) return;
+ if ( progName.empty() ) return;
level = 0;
rank = 0;
@@ -646,8 +639,7 @@ void CScript::ColorizeScript(Ui::CEdit* edit, int rangeStart, int rangeEnd)
CBotToken* bt = CBotToken::CompileTokens(text.c_str(), error);
while ( bt != nullptr )
{
- CBotString bs = bt->GetString();
- const char* token = bs;
+ std::string token = bt->GetString();
int type = bt->GetType();
int cursor1 = bt->GetStart();
@@ -659,15 +651,15 @@ void CScript::ColorizeScript(Ui::CEdit* edit, int rangeStart, int rangeEnd)
cursor2 += rangeStart;
Gfx::FontHighlight color = Gfx::FONT_HIGHLIGHT_NONE;
- if ((type == TokenTypVar || (type >= TokenKeyWord && type < TokenKeyWord+100)) && IsType(token)) // types (basic types are TokenKeyWord, classes are TokenTypVar)
+ if ((type == TokenTypVar || (type >= TokenKeyWord && type < TokenKeyWord+100)) && IsType(token.c_str())) // types (basic types are TokenKeyWord, classes are TokenTypVar)
{
color = Gfx::FONT_HIGHLIGHT_TYPE;
}
- else if (type == TokenTypVar && IsFunction(token)) // functions
+ else if (type == TokenTypVar && IsFunction(token.c_str())) // functions
{
color = Gfx::FONT_HIGHLIGHT_TOKEN;
}
- else if (type == TokenTypVar && (strcmp(token, "this") == 0 || strcmp(token, "super") == 0)) // this, super
+ else if (type == TokenTypVar && (token == "this" || token == "super")) // this, super
{
color = Gfx::FONT_HIGHLIGHT_THIS;
}
diff --git a/src/script/scriptfunc.cpp b/src/script/scriptfunc.cpp
index b2fce1c..060dddc 100644
--- a/src/script/scriptfunc.cpp
+++ b/src/script/scriptfunc.cpp
@@ -473,7 +473,7 @@ CBotTypResult CScriptFunctions::cPlayMusic(CBotVar* &var, void* user)
bool CScriptFunctions::rPlayMusic(CBotVar* var, CBotVar* result, int& exception, void* user)
{
std::string filename;
- CBotString cbs;
+ std::string cbs;
bool repeat;
cbs = var->GetValString();
@@ -703,13 +703,9 @@ bool CScriptFunctions::rFactory(CBotVar* thisclass, CBotVar* var, CBotVar* resul
ObjectType type = static_cast<ObjectType>(var->GetValInt());
var = var->GetNext();
- CBotString cbs;
- const char* program;
+ std::string program;
if ( var != nullptr )
- {
- cbs = var->GetValString();
- program = cbs;
- }
+ program = var->GetValString();
else
program = "";
@@ -1584,8 +1580,7 @@ bool CScriptFunctions::rProduce(CBotVar* var, CBotVar* result, int& exception, v
if ( var != nullptr )
{
- CBotString cbs = var->GetValString();
- name = static_cast<const char*>(cbs);
+ name = var->GetValString();
var = var->GetNext();
if ( var != nullptr )
{
@@ -2225,17 +2220,15 @@ CBotTypResult CScriptFunctions::cReceive(CBotVar* &var, void* user)
bool CScriptFunctions::rReceive(CBotVar* var, CBotVar* result, int& exception, void* user)
{
CScript* script = static_cast<CScript*>(user);
- CBotString cbs;
Error err;
- const char* p;
+ std::string p;
float power;
exception = 0;
if ( !script->m_taskExecutor->IsForegroundTask() ) // no task in progress?
{
- cbs = var->GetValString();
- p = cbs;
+ p = var->GetValString();
var = var->GetNext();
power = 10.0f*g_unit;
@@ -2245,7 +2238,7 @@ bool CScriptFunctions::rReceive(CBotVar* var, CBotVar* result, int& exception, v
var = var->GetNext();
}
- err = script->m_taskExecutor->StartTaskInfo(p, 0.0f, power, false);
+ err = script->m_taskExecutor->StartTaskInfo(p.c_str(), 0.0f, power, false);
if ( err != ERR_OK )
{
script->m_taskExecutor->StopForegroundTask();
@@ -2294,17 +2287,15 @@ CBotTypResult CScriptFunctions::cSend(CBotVar* &var, void* user)
bool CScriptFunctions::rSend(CBotVar* var, CBotVar* result, int& exception, void* user)
{
CScript* script = static_cast<CScript*>(user);
- CBotString cbs;
Error err;
- const char* p;
+ std::string p;
float value, power;
exception = 0;
if ( !script->m_taskExecutor->IsForegroundTask() ) // no task in progress?
{
- cbs = var->GetValString();
- p = cbs;
+ p = var->GetValString();
var = var->GetNext();
value = var->GetValFloat();
@@ -2317,7 +2308,7 @@ bool CScriptFunctions::rSend(CBotVar* var, CBotVar* result, int& exception, void
var = var->GetNext();
}
- err = script->m_taskExecutor->StartTaskInfo(static_cast<const char*>(p), value, power, true);
+ err = script->m_taskExecutor->StartTaskInfo(p.c_str(), value, power, true);
if ( err != ERR_OK )
{
script->m_taskExecutor->StopForegroundTask();
@@ -2365,15 +2356,13 @@ bool CScriptFunctions::rDeleteInfo(CBotVar* var, CBotVar* result, int& exception
exception = 0;
- CBotString infoNameCbs = var->GetValString();
- std::string infoName = std::string(static_cast<const char*>(infoNameCbs));
+ std::string infoName = var->GetValString();
var = var->GetNext();
float power = 10.0f*g_unit;
if (var != nullptr)
{
power = var->GetValFloat()*g_unit;
- var = var->GetNext();
}
CExchangePost* exchangePost = FindExchangePost(pThis, power);
@@ -2413,15 +2402,13 @@ bool CScriptFunctions::rTestInfo(CBotVar* var, CBotVar* result, int& exception,
exception = 0;
- CBotString infoNameCbs = var->GetValString();
- std::string infoName = std::string(static_cast<const char*>(infoNameCbs));
+ std::string infoName = var->GetValString();
var = var->GetNext();
float power = 10.0f*g_unit;
if (var != nullptr)
{
power = var->GetValFloat()*g_unit;
- var = var->GetNext();
}
CExchangePost* exchangePost = FindExchangePost(pThis, power);
@@ -2813,12 +2800,10 @@ CBotTypResult CScriptFunctions::cMessage(CBotVar* &var, void* user)
bool CScriptFunctions::rMessage(CBotVar* var, CBotVar* result, int& exception, void* user)
{
CScript* script = static_cast<CScript*>(user);
- CBotString cbs;
- const char* p;
+ std::string p;
Ui::TextType type;
- cbs = var->GetValString();
- p = cbs;
+ p = var->GetValString();
type = Ui::TT_MESSAGE;
var = var->GetNext();
@@ -2827,7 +2812,7 @@ bool CScriptFunctions::rMessage(CBotVar* var, CBotVar* result, int& exception, v
type = static_cast<Ui::TextType>(var->GetValInt());
}
- script->m_main->GetDisplayText()->DisplayText(p, script->m_object, 10.0f, type);
+ script->m_main->GetDisplayText()->DisplayText(p.c_str(), script->m_object, 10.0f, type);
return true;
}
@@ -3157,22 +3142,22 @@ int CScriptFunctions::m_nextFile = 1;
// Prepares a file name.
-void PrepareFilename(CBotString &filename)
+void PrepareFilename(std::string &filename)
{
CResourceManager::CreateDirectory("files");
- filename = CBotString("files/") + filename;
- GetLogger()->Debug("CBot accessing file '%s'\n", static_cast<const char*>(filename));
+ filename = "files/" + filename;
+ GetLogger()->Debug("CBot accessing file '%s'\n", filename.c_str());
}
bool CScriptFunctions::FileClassOpenFile(CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
{
- CBotString mode;
+ std::string mode;
// must be a character string
if ( pVar->GetType() != CBotTypString ) { Exception = CBotErrBadString; return false; }
- CBotString filename = pVar->GetValString();
+ std::string filename = pVar->GetValString();
PrepareFilename(filename);
// there may be a second parameter
@@ -3196,20 +3181,20 @@ bool CScriptFunctions::FileClassOpenFile(CBotVar* pThis, CBotVar* pVar, CBotVar*
// which must not be initialized
if ( pVar->IsDefined()) { Exception = CBotErrFileOpen; return false; }
- if ( ! mode.IsEmpty() )
+ if ( !mode.empty() )
{
// opens the requested file
bool ok = false;
std::unique_ptr<std::ios> file;
if (mode == "r")
{
- auto is = MakeUnique<CInputStream>(static_cast<const char*>(filename));
+ auto is = MakeUnique<CInputStream>(filename);
ok = is->is_open();
file = std::move(is);
}
else if (mode == "w")
{
- auto os = MakeUnique<COutputStream>(static_cast<const char*>(filename));
+ auto os = MakeUnique<COutputStream>(filename);
ok = os->is_open();
file = std::move(os);
}
@@ -3396,7 +3381,7 @@ bool CScriptFunctions::rfwrite (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult,
// which must be a character string
if ( pVar->GetType() != CBotTypString ) { Exception = CBotErrBadString; return false; }
- CBotString param = pVar->GetValString();
+ std::string param = pVar->GetValString();
// retrieve the item "handle"
pVar = pThis->GetItem("handle");
@@ -3526,11 +3511,10 @@ CBotTypResult CScriptFunctions::cfeof (CBotVar* pThis, CBotVar* &pVar)
bool CScriptFunctions::rDeleteFile(CBotVar* var, CBotVar* result, int& exception, void* user)
{
- CBotString cbs;
+ std::string filename;
- cbs = var->GetValString();
- PrepareFilename(cbs);
- std::string filename = static_cast<const char*>(cbs);
+ filename = var->GetValString();
+ PrepareFilename(filename);
return CResourceManager::Remove(filename);
}
@@ -3773,7 +3757,7 @@ void CScriptFunctions::Init()
bc->AddFunction("eof", CScriptFunctions::rfeof, CScriptFunctions::cfeof );
//m_pFuncFile = new CBotProgram( );
- //CBotStringArray ListFonctions;
+ //std::stringArray ListFonctions;
//m_pFuncFile->Compile( "public file openfile(string name, string mode) {return new file(name, mode);}", ListFonctions);
//m_pFuncFile->SetIdent(-2); // restoreState in special identifier for this function
diff --git a/test/cbot/console/main.cpp b/test/cbot/console/main.cpp
index 721105a..fc0e5cc 100644
--- a/test/cbot/console/main.cpp
+++ b/test/cbot/console/main.cpp
@@ -18,8 +18,7 @@ CBotTypResult cMessage(CBotVar* &var, void* user)
bool rMessage(CBotVar* var, CBotVar* result, int& exception, void* user)
{
- CBotString cbs = var->GetValString();
- const char* message = cbs; // Don't ask me why, but it doesn't work if you write it on a single line
+ std::string message = var->GetValString();
std::cout << message << std::endl;
@@ -44,7 +43,7 @@ int main(int argc, char* argv[])
CBotProgram::AddFunction("message", rMessage, cMessage);
// Compile the program
- std::vector<CBotString> externFunctions;
+ std::vector<std::string> externFunctions;
std::unique_ptr<CBotProgram> program{new CBotProgram(nullptr)};
if (!program->Compile(code.c_str(), externFunctions, nullptr))
{
@@ -63,7 +62,7 @@ int main(int argc, char* argv[])
return 2;
}
bool runErrors = false;
- for (const char* func : externFunctions)
+ for (const std::string& func : externFunctions)
{
if (!program->Start(func))
{
diff --git a/test/unit/CBot/CBotString_test.cpp b/test/unit/CBot/CBotString_test.cpp
deleted file mode 100644
index c058cfd..0000000
--- a/test/unit/CBot/CBotString_test.cpp
+++ /dev/null
@@ -1,399 +0,0 @@
-/*
- * This file is part of the Colobot: Gold Edition source code
- * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
- * http://epsitec.ch; http://colobot.info; http://github.com/colobot
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see http://gnu.org/licenses
- */
-
-// Modules inlcude
-#include "CBot/CBotString.h"
-
-// Local include
-
-// Global include
-#include <gtest/gtest.h>
-
-/**
- * @brief CBotString_Test.Empty Check Empty and IsEmpty functions of class
- * CBotString_Test.
- */
-TEST(CBotString_Test, Empty)
-{
- CBotString str1;
- EXPECT_EQ(true, str1.IsEmpty());
-
- CBotString str2("qsexrdctfvygbuh");
- EXPECT_EQ(false, str2.IsEmpty());
- str2.Empty();
- EXPECT_EQ(true, str2.IsEmpty());
-}
-
-/**
- * @brief CBotString_Test.Length Check GetLength function of class
- * CBotString_Test.
- */
-TEST(CBotString_Test, Length)
-{
- CBotString str1;
- EXPECT_EQ(0, str1.GetLength());
-
- CBotString str2("a");
- EXPECT_EQ(1, str2.GetLength());
-
- CBotString str3("aaaaa");
- EXPECT_EQ(5, str3.GetLength());
-}
-
-/**
- * @brief CBotString_Test.Find Check find functions of class CBotString_Test
- */
-TEST(CBotString_Test, Find)
-{
- CBotString str1("a");
- EXPECT_EQ(0, str1.Find('a'));
-
- CBotString str2("b");
- EXPECT_EQ(-1, str2.Find('a'));
-
- CBotString str3("bbabb");
- EXPECT_EQ(2, str3.Find('a'));
-
- CBotString str4("bbAbb");
- EXPECT_EQ(-1, str4.Find('a'));
-
- CBotString str5("bbAbb");
- EXPECT_EQ(2, str5.Find('A'));
-
- CBotString str6("test");
- EXPECT_EQ(0, str6.Find("test"));
-
- CBotString str7("azazdazd");
- EXPECT_EQ(-1, str7.Find("test"));
-
- CBotString str8("bbtestbb");
- EXPECT_EQ(2, str8.Find("test"));
-
- CBotString str9("bbTestbb");
- EXPECT_EQ(-1, str9.Find("test"));
-
- CBotString str10("bbTestbb");
- EXPECT_EQ(2, str10.Find("Test"));
-}
-
-/**
- * @brief CBotString_Test.ReverseFind Check find functions of class
- * CBotString_Test
- */
-TEST(CBotString_Test, ReverseFind)
-{
- CBotString str1("a");
- EXPECT_EQ(0, str1.ReverseFind('a'));
-
- CBotString str2("b");
- EXPECT_EQ(-1, str2.ReverseFind('a'));
-
- CBotString str3("bbabb");
- EXPECT_EQ(2, str3.ReverseFind('a'));
-
- CBotString str4("bbAbb");
- EXPECT_EQ(-1, str4.ReverseFind('a'));
-
- CBotString str5("bbAbb");
- EXPECT_EQ(2, str5.ReverseFind('A'));
-
- CBotString str6("test");
- EXPECT_EQ(0, str6.ReverseFind("test"));
-
- CBotString str7("azazdazd");
- EXPECT_EQ(-1, str7.ReverseFind("test"));
-
- CBotString str8("bbtestbb");
- EXPECT_EQ(2, str8.ReverseFind("test"));
-
- CBotString str9("bbTestbb");
- EXPECT_EQ(-1, str9.ReverseFind("test"));
-
- CBotString str10("bbTestbb");
- EXPECT_EQ(2, str10.ReverseFind("Test"));
-}
-
-/**
- * @brief CBotString_Test.Mid Check Mid functions of class CBotString_Test
- */
-TEST(CBotString_Test, Mid)
-{
- CBotString str1("aaaColobot");
- EXPECT_STREQ(str1.Mid(3).CStr(), "Colobot");
-
- CBotString str2("aaaColobotaa");
- EXPECT_STREQ(str2.Mid(3,7).CStr(), "Colobot");
-}
-
-/**
- * @brief CBotString_Test.Left Check Left function of class CBotString_Test
- */
-TEST(CBotString_Test, Left)
-{
- CBotString str1("Colobotaaa");
- EXPECT_STREQ(str1.Left(7).CStr(), "Colobot");
-}
-
-/**
- * @brief CBotString_Test.Right Check Right function of class CBotString_Test
- */
-TEST(CBotString_Test, Right)
-{
- CBotString str1("aaaColobot");
- EXPECT_STREQ(str1.Right(7).CStr(), "Colobot");
-}
-
-/**
- * @brief CBotString_Test.MakeUpper Check MakeUpper function of class
- * CBotString_Test
- */
-TEST(CBotString_Test, MakeUpper)
-{
- CBotString str1("colobot");
- str1.MakeUpper();
- EXPECT_STREQ(str1.CStr(), "COLOBOT");
-
- CBotString str2("Colobot");
- str2.MakeUpper();
- EXPECT_STREQ(str2.CStr(), "COLOBOT");
-}
-
-/**
- * @brief CBotString_Test.MakeLower Check MakeLower function of class
- * CBotString_Test
- */
-TEST(CBotString_Test, MakeLower)
-{
- CBotString str1("COLOBOT");
- str1.MakeLower();
- EXPECT_STREQ(str1.CStr(), "colobot");
-
- CBotString str2("Colobot");
- str2.MakeLower();
- EXPECT_STREQ(str2.CStr(), "colobot");
-}
-
-/**
- * @brief CBotString_Test.operatorEqual Check operator equal of class
- * CBotString_Test
- */
-TEST(CBotString_Test, operatorEqual)
-{
- //-- CBotString
- CBotString botStr1;
- CBotString botStr2("Colobot");
-
- //-- C Character
- const char cStr1[2] = "C";
-
- //-- C string
- const char cStr2[8] = "Colobot";
-
- //-- Compare with CBotString
- botStr1 = botStr2;
- EXPECT_STREQ(botStr1.CStr(), botStr2.CStr());
-
- //-- Compare with C character
- botStr1 = cStr1[0];
- EXPECT_STREQ(botStr1.CStr(), cStr1);
-
- //-- Compare with C string
- botStr1 = cStr2;
- EXPECT_STREQ(botStr1.CStr(), cStr2);
-
-}
-
-/**
- * @brief CBotString_Test.operatorIsEqual Check operator is equal of class
- * CBotString_Test
- */
-TEST(CBotString_Test, operatorIsEqual)
-{
- //-- CBotString
- CBotString botStr1("C");
- CBotString botStr2("C");
- CBotString botStr3("Colobot");
-
- //-- C string
- const char cStr1[8] = "Colobot";
- const char cStr2[8] = "colobot";
-
- EXPECT_EQ(true, (botStr1 == botStr2));
- EXPECT_EQ(false, (botStr1 == botStr3));
-
- //-- Compare with C string
- EXPECT_EQ(true, (botStr3 == cStr1));
- EXPECT_EQ(false, (botStr3 == cStr2));
-}
-
-/**
- * @brief CBotString_Test.operatorAdd Check operator add of class
- * CBotString_Test.
- */
-TEST(CBotString_Test, operatorAdd)
-{
- //-- CBotString
- CBotString botStr1;
- CBotString botStr2("C");
- CBotString botStr3("olobot");
- CBotString botStr4("Colobot");
-
- //-- C string
- const char* cStr1 = "olobot";
-
- botStr1 = botStr1 + botStr2;
- botStr1 = botStr1 + botStr3;
- EXPECT_STREQ(botStr1.CStr(), botStr4.CStr());
-
- botStr1.Empty();
- botStr1 = botStr2 + cStr1;
- EXPECT_STREQ(botStr1.CStr(), botStr4.CStr());
-
- botStr1.Empty();
- botStr1 += botStr2;
- botStr1 += botStr3;
- EXPECT_STREQ(botStr1.CStr(), botStr4.CStr());
-
-
- botStr1.Empty();
- botStr1 += botStr2;
- botStr1 += cStr1;
- EXPECT_STREQ(botStr1.CStr(), botStr4.CStr());
-}
-
-/**
- * @brief CBotString_Test.operatorDiff Check operator diff of class
- * CBotString_Test.
- */
-TEST(CBotString_Test, operatorDiff)
-{
- //-- CBotString
- CBotString botStr1("C");
- CBotString botStr2("C");
- CBotString botStr3("Colobot");
-
- //-- C string
- const char cStr1[8] = "Colobot";
- const char cStr2[8] = "colobot";
-
- EXPECT_EQ(false, (botStr1 != botStr2));
- EXPECT_EQ(true, (botStr1 != botStr3));
-
- //-- Compare with C string
- EXPECT_EQ(false, (botStr3 != cStr1));
- EXPECT_EQ(true, (botStr3 != cStr2));
-}
-
-/**
- * @brief CBotString_Test.operatorSuperior Check operator superior of class
- * CBotString_Test.
- */
-TEST(CBotString_Test, operatorSuperior)
-{
- //-- CBotString
- CBotString botStr1("a");
- CBotString botStr2("z");
- CBotString botStr3("colobot");
-
- //-- C string
- const char cStr1[2] = "a";
- const char cStr2[2] = "z";
-
- EXPECT_EQ(true, (botStr3 > botStr1));
- EXPECT_EQ(false, (botStr3 > botStr2));
-
- //-- Compare with C string
- EXPECT_EQ(true, (botStr3 > cStr1));
- EXPECT_EQ(false, (botStr3 > cStr2));
-}
-
-/**
- * @brief CBotString_Test.operatorSuperiorOrEqual Check operator superior or
- * equa of class CBotString_Test.
- */
-TEST(CBotString_Test, operatorSuperiorOrEqual)
-{
- //-- CBotString
- CBotString botStr1("a");
- CBotString botStr2("z");
- CBotString botStr3("colobot");
-
- //-- C string
- const char cStr1[2] = "a";
- const char cStr2[2] = "z";
- const char cStr3[8] = "colobot";
-
- EXPECT_EQ(true, (botStr3 >= botStr1));
- EXPECT_EQ(false, (botStr3 >= botStr2));
- EXPECT_EQ(true, (botStr3 >= botStr3));
-
- //-- Compare with C string
- EXPECT_EQ(true, (botStr3 >= cStr1));
- EXPECT_EQ(false, (botStr3 >= cStr2));
- EXPECT_EQ(true, (botStr3 >= cStr3));
-}
-
-/**
- * @brief CBotString_Test.operatorInferior Check operator Inferior of class
- * CBotString_Test.
- */
-TEST(CBotString_Test, operatorInferior)
-{
- //-- CBotString
- CBotString botStr1("a");
- CBotString botStr2("z");
- CBotString botStr3("colobot");
-
- //-- C string
- const char cStr1[2] = "a";
- const char cStr2[2] = "z";
-
- EXPECT_EQ(false, (botStr3 < botStr1));
- EXPECT_EQ(true, (botStr3 < botStr2));
-
- //-- Compare with C string
- EXPECT_EQ(false, (botStr3 < cStr1));
- EXPECT_EQ(true, (botStr3 < cStr2));
-}
-
-/**
- * @brief CBotString_Test.operatorInferiorOrEqual Check operator Inferior or
- * equa of class CBotString_Test.
- */
-TEST(CBotString_Test, operatorInferiorOrEqual)
-{
- //-- CBotString
- CBotString botStr1("a");
- CBotString botStr2("z");
- CBotString botStr3("colobot");
-
- //-- C string
- const char cStr1[2] = "a";
- const char cStr2[2] = "z";
- const char cStr3[8] = "colobot";
-
- EXPECT_EQ(false, (botStr3 <= botStr1));
- EXPECT_EQ(true, (botStr3 <= botStr2));
- EXPECT_EQ(true, (botStr3 <= botStr3));
-
- //-- Compare with C string
- EXPECT_EQ(false, (botStr3 <= cStr1));
- EXPECT_EQ(true, (botStr3 <= cStr2));
- EXPECT_EQ(true, (botStr3 <= cStr3));
-}
diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt
index 5bdc38a..f12c3a2 100644
--- a/test/unit/CMakeLists.txt
+++ b/test/unit/CMakeLists.txt
@@ -15,7 +15,6 @@ set(UT_SOURCES
math/geometry_test.cpp
math/matrix_test.cpp
math/vector_test.cpp
- CBot/CBotString_test.cpp
${PLATFORM_TESTS}
)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/colobot.git
More information about the Pkg-games-commits
mailing list