[colobot] 130/377: Split file StringFunctions.cpp into two files StringFunctions.h and StringFunctions.cpp.
Didier Raboud
odyx at moszumanska.debian.org
Wed Mar 30 13:34:07 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 889c0fbe8e96c2a76ab8cae9884b90241e351bd2
Author: Grunaka <dev at romainbreton.fr>
Date: Sun Nov 22 17:25:46 2015 +0100
Split file StringFunctions.cpp into two files StringFunctions.h and StringFunctions.cpp.
---
src/CBot/CBotInstr/CBotExprNum.cpp | 98 --------------------------
src/CBot/CBotProgram.cpp | 4 +-
src/CBot/CBotUtils.cpp | 94 +++++++++++++++++++++++++
src/CBot/CBotUtils.h | 15 ++++
src/CBot/CMakeLists.txt | 1 +
src/CBot/StringFunctions.cpp | 70 +++++++------------
src/CBot/StringFunctions.h | 137 +++++++++++++++++++++++++++++++++++++
7 files changed, 273 insertions(+), 146 deletions(-)
diff --git a/src/CBot/CBotInstr/CBotExprNum.cpp b/src/CBot/CBotInstr/CBotExprNum.cpp
index 65dbd78..acf1e9a 100644
--- a/src/CBot/CBotInstr/CBotExprNum.cpp
+++ b/src/CBot/CBotInstr/CBotExprNum.cpp
@@ -29,104 +29,6 @@
// Global include
-
-////////////////////////////////////////////////////////////////////////////////
-// converts a string into integer
-// may be of the form 0xabc123
-long GetNumInt(const char* p)
-{
- long num = 0;
- while (*p >= '0' && *p <= '9')
- {
- num = num * 10 + *p - '0';
- p++;
- }
- if (*p == 'x' || *p == 'X')
- {
- while (*++p != 0)
- {
- if (*p >= '0' && *p <= '9')
- {
- num = num * 16 + *p - '0';
- continue;
- }
- if (*p >= 'A' && *p <= 'F')
- {
- num = num * 16 + *p - 'A' + 10;
- continue;
- }
- if (*p >= 'a' && *p <= 'f')
- {
- num = num * 16 + *p - 'a' + 10;
- continue;
- }
- break;
- }
- }
- return num;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// converts a string into a float number
-extern float GetNumFloat(const char* p)
-{
- double num = 0;
- double div = 10;
- bool bNeg = false;
-
- if (*p == '-')
- {
- bNeg = true;
- p++;
- }
- while (*p >= '0' && *p <= '9')
- {
- num = num * 10. + (*p - '0');
- p++;
- }
-
- if (*p == '.')
- {
- p++;
- while (*p >= '0' && *p <= '9')
- {
- num = num + (*p - '0') / div;
- div = div * 10;
- p++;
- }
- }
-
- int exp = 0;
- if (*p == 'e' || *p == 'E')
- {
- char neg = 0;
- p++;
- if (*p == '-' || *p == '+') neg = *p++;
-
- while (*p >= '0' && *p <= '9')
- {
- exp = exp * 10 + (*p - '0');
- p++;
- }
- if (neg == '-') exp = -exp;
- }
-
- while (exp > 0)
- {
- num *= 10.0;
- exp--;
- }
-
- while (exp < 0)
- {
- num /= 10.0;
- exp++;
- }
-
- if (bNeg) num = -num;
- return static_cast<float>(num);
-}
-
////////////////////////////////////////////////////////////////////////////////
CBotExprNum::CBotExprNum()
{
diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp
index 4e3f2c4..4ee5bff 100644
--- a/src/CBot/CBotProgram.cpp
+++ b/src/CBot/CBotProgram.cpp
@@ -20,6 +20,8 @@
// Modules inlcude
#include "CBot.h"
+#include "CBotVar/CBotVar.h"
+
#include "CBotCall.h"
#include "CBotStack.h"
#include "CBotCStack.h"
@@ -28,7 +30,7 @@
#include "CBotInstr/CBotFunction.h"
-#include "StringFunctions.cpp"
+#include "StringFunctions.h"
// Local include
diff --git a/src/CBot/CBotUtils.cpp b/src/CBot/CBotUtils.cpp
index c59f874..5e38cb5 100644
--- a/src/CBot/CBotUtils.cpp
+++ b/src/CBot/CBotUtils.cpp
@@ -178,3 +178,97 @@ void DestructElements(CBotString* pOldData, int nCount)
pOldData++;
}
}
+
+////////////////////////////////////////////////////////////////////////////////
+long GetNumInt(const char* p)
+{
+ long num = 0;
+ while (*p >= '0' && *p <= '9')
+ {
+ num = num * 10 + *p - '0';
+ p++;
+ }
+ if (*p == 'x' || *p == 'X')
+ {
+ while (*++p != 0)
+ {
+ if (*p >= '0' && *p <= '9')
+ {
+ num = num * 16 + *p - '0';
+ continue;
+ }
+ if (*p >= 'A' && *p <= 'F')
+ {
+ num = num * 16 + *p - 'A' + 10;
+ continue;
+ }
+ if (*p >= 'a' && *p <= 'f')
+ {
+ num = num * 16 + *p - 'a' + 10;
+ continue;
+ }
+ break;
+ }
+ }
+ return num;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+float GetNumFloat(const char* p)
+{
+ double num = 0;
+ double div = 10;
+ bool bNeg = false;
+
+ if (*p == '-')
+ {
+ bNeg = true;
+ p++;
+ }
+ while (*p >= '0' && *p <= '9')
+ {
+ num = num * 10. + (*p - '0');
+ p++;
+ }
+
+ if (*p == '.')
+ {
+ p++;
+ while (*p >= '0' && *p <= '9')
+ {
+ num = num + (*p - '0') / div;
+ div = div * 10;
+ p++;
+ }
+ }
+
+ int exp = 0;
+ if (*p == 'e' || *p == 'E')
+ {
+ char neg = 0;
+ p++;
+ if (*p == '-' || *p == '+') neg = *p++;
+
+ while (*p >= '0' && *p <= '9')
+ {
+ exp = exp * 10 + (*p - '0');
+ p++;
+ }
+ if (neg == '-') exp = -exp;
+ }
+
+ while (exp > 0)
+ {
+ num *= 10.0;
+ exp--;
+ }
+
+ while (exp < 0)
+ {
+ num /= 10.0;
+ exp++;
+ }
+
+ if (bNeg) num = -num;
+ return static_cast<float>(num);
+}
diff --git a/src/CBot/CBotUtils.h b/src/CBot/CBotUtils.h
index bf958bc..0ce7641 100644
--- a/src/CBot/CBotUtils.h
+++ b/src/CBot/CBotUtils.h
@@ -116,3 +116,18 @@ void ConstructElements(CBotString* pNewData, int nCount);
* \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);
+
+/*!
+ * \brief GetNumFloat Converts a string into a float number.
+ * \param p
+ * \return
+ */
+float GetNumFloat(const char* p);
+
diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt
index 3bb1eb9..a2d530e 100644
--- a/src/CBot/CMakeLists.txt
+++ b/src/CBot/CMakeLists.txt
@@ -13,6 +13,7 @@ set(SOURCES
CBotCallMethode.cpp
CBotStringArray.cpp
CBotTypResult.cpp
+ StringFunctions.cpp
CBotInstr/CBotInstr.cpp
CBotInstr/CBotInstrUtils.cpp
CBotInstr/CBotWhile.cpp
diff --git a/src/CBot/StringFunctions.cpp b/src/CBot/StringFunctions.cpp
index 640efc1..c38af37 100644
--- a/src/CBot/StringFunctions.cpp
+++ b/src/CBot/StringFunctions.cpp
@@ -17,15 +17,20 @@
* along with this program. If not, see http://gnu.org/licenses
*/
-#include "CBotVar/CBotVar.h"
+// Modules inlcude
+#include "StringFunctions.h"
+
+#include "CBotProgram.h"
+#include "CBotEnums.h"
-// definition of string functions
+#include "CBotVar/CBotVar.h"
-// gives the length of a chain
-// execution
+// Local include
+// Global include
+////////////////////////////////////////////////////////////////////////////////
bool rStrLen( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
{
// it takes a parameter
@@ -45,9 +50,7 @@ bool rStrLen( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
return true;
}
-// int xxx ( string )
-// compilation
-
+////////////////////////////////////////////////////////////////////////////////
CBotTypResult cIntStr( CBotVar* &pVar, void* pUser )
{
// it takes a parameter
@@ -64,10 +67,7 @@ CBotTypResult cIntStr( CBotVar* &pVar, void* pUser )
return CBotTypResult( CBotTypInt );
}
-
-// gives the left side of a chain
-// execution
-
+////////////////////////////////////////////////////////////////////////////////
bool rStrLeft( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
{
// it takes a parameter
@@ -100,9 +100,7 @@ bool rStrLeft( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
return true;
}
-// string xxx ( string, int )
-// compilation
-
+////////////////////////////////////////////////////////////////////////////////
CBotTypResult cStrStrInt( CBotVar* &pVar, void* pUser )
{
// it takes a parameter
@@ -127,9 +125,7 @@ CBotTypResult cStrStrInt( CBotVar* &pVar, void* pUser )
return CBotTypResult( CBotTypString );
}
-// gives the right of a string
-// execution
-
+////////////////////////////////////////////////////////////////////////////////
bool rStrRight( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
{
// it takes a parameter
@@ -162,9 +158,7 @@ bool rStrRight( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
return true;
}
-// gives the central part of a chain
-// execution
-
+////////////////////////////////////////////////////////////////////////////////
bool rStrMid( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
{
// it takes a parameter
@@ -214,9 +208,7 @@ bool rStrMid( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
return true;
}
-// gives the central part of a chain
-// compilation
-
+////////////////////////////////////////////////////////////////////////////////
CBotTypResult cStrStrIntInt( CBotVar* &pVar, void* pUser )
{
// it takes a parameter
@@ -251,10 +243,7 @@ CBotTypResult cStrStrIntInt( CBotVar* &pVar, void* pUser )
return CBotTypResult( CBotTypString );
}
-
-// gives the number stored in a string
-// execution
-
+////////////////////////////////////////////////////////////////////////////////
bool rStrVal( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
{
// it takes a parameter
@@ -276,9 +265,7 @@ bool rStrVal( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
return true;
}
-// float xxx ( string )
-// compilation
-
+////////////////////////////////////////////////////////////////////////////////
CBotTypResult cFloatStr( CBotVar* &pVar, void* pUser )
{
// it takes a parameter
@@ -295,10 +282,7 @@ CBotTypResult cFloatStr( CBotVar* &pVar, void* pUser )
return CBotTypResult( CBotTypFloat );
}
-
-// find string in other
-// exécution
-
+////////////////////////////////////////////////////////////////////////////////
bool rStrFind( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
{
// it takes a parameter
@@ -330,9 +314,7 @@ bool rStrFind( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
return true;
}
-// int xxx ( string, string )
-// compilation
-
+////////////////////////////////////////////////////////////////////////////////
CBotTypResult cIntStrStr( CBotVar* &pVar, void* pUser )
{
// it takes a parameter
@@ -357,9 +339,7 @@ CBotTypResult cIntStrStr( CBotVar* &pVar, void* pUser )
return CBotTypResult( CBotTypInt );
}
-// gives a string to uppercase
-// exécution
-
+////////////////////////////////////////////////////////////////////////////////
bool rStrUpper( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
{
// it takes a parameter
@@ -382,9 +362,7 @@ bool rStrUpper( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
return true;
}
-// gives a string to lowercase
-// exécution
-
+////////////////////////////////////////////////////////////////////////////////
bool rStrLower( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
{
// it takes a parameter
@@ -407,9 +385,7 @@ bool rStrLower( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
return true;
}
-// string xxx ( string )
-// compilation
-
+////////////////////////////////////////////////////////////////////////////////
CBotTypResult cStrStr( CBotVar* &pVar, void* pUser )
{
// it takes a parameter
@@ -426,7 +402,7 @@ CBotTypResult cStrStr( CBotVar* &pVar, void* pUser )
return CBotTypResult( CBotTypString );
}
-
+////////////////////////////////////////////////////////////////////////////////
void InitStringFunctions()
{
CBotProgram::AddFunction("strlen", rStrLen, cIntStr );
diff --git a/src/CBot/StringFunctions.h b/src/CBot/StringFunctions.h
new file mode 100644
index 0000000..da534aa
--- /dev/null
+++ b/src/CBot/StringFunctions.h
@@ -0,0 +1,137 @@
+/*
+ * 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 "CBotTypResult.h"
+
+// Local include
+
+// Global include
+
+// Forward declaration
+class CBotVar;
+
+/*!
+ * \brief rStrLen Gives the length of a chain execution
+ * \param pVar
+ * \param pResult
+ * \param ex
+ * \param pUser
+ * \return
+ */
+bool rStrLen( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser );
+
+/*!
+ * \brief cIntStr int xxx ( string ) compilation
+ * \param pVar
+ * \param pUser
+ * \return
+ */
+CBotTypResult cIntStr( CBotVar* &pVar, void* pUser );
+
+/*!
+ * \brief rStrLeft Gives the left side of a chain execution
+ * \param pVar
+ * \param pResult
+ * \param ex
+ * \param pUser
+ * \return
+ */
+bool rStrLeft( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser );
+
+/*!
+ * \brief cStrStrInt string xxx ( string, int ) compilation
+ * \param pVar
+ * \param pUser
+ * \return
+ */
+CBotTypResult cStrStrInt( CBotVar* &pVar, void* pUser );
+
+/*!
+ * \brief rStrRight Gives the right of a string execution
+ * \param pVar
+ * \param pResult
+ * \param ex
+ * \param pUser
+ * \return
+ */
+bool rStrRight( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser );
+
+/*!
+ * \brief rStrMid Gives the central part of a chain execution
+ * \param pVar
+ * \param pResult
+ * \param ex
+ * \param pUser
+ * \return
+ */
+bool rStrMid( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser );
+
+/*!
+ * \brief rStrVal Gives the number stored in a string execution.
+ * \param pVar
+ * \param pResult
+ * \param ex
+ * \param pUser
+ * \return
+ */
+bool rStrVal( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser );
+
+/*!
+ * \brief cIntStrStr int xxx ( string, string ) compilation
+ * \param pVar
+ * \param pUser
+ * \return
+ */
+CBotTypResult cIntStrStr( CBotVar* &pVar, void* pUser );
+
+/*!
+ * \brief rStrUpper Gives a string to uppercase exécution
+ * \param pVar
+ * \param pResult
+ * \param ex
+ * \param pUser
+ * \return
+ */
+bool rStrUpper( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser );
+
+/*!
+ * \brief rStrLower Gives a string to lowercase exécution.
+ * \param pVar
+ * \param pResult
+ * \param ex
+ * \param pUser
+ * \return
+ */
+bool rStrLower( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser );
+
+/*!
+ * \brief cStrStr String xxx ( string ) compilation
+ * \param pVar
+ * \param pUser
+ * \return
+ */
+CBotTypResult cStrStr( CBotVar* &pVar, void* pUser );
+
+/*!
+ * \brief InitStringFunctions
+ */
+void InitStringFunctions();
--
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