summaryrefslogtreecommitdiffstats
path: root/pokemod/String.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'pokemod/String.cpp')
-rw-r--r--pokemod/String.cpp113
1 files changed, 111 insertions, 2 deletions
diff --git a/pokemod/String.cpp b/pokemod/String.cpp
index 0d8b8367..61bc7e37 100644
--- a/pokemod/String.cpp
+++ b/pokemod/String.cpp
@@ -37,7 +37,7 @@ PokeGen::PokeMod::String::String(const char *fmt, ...)
va_end(args);
}
-void PokeGen::PokeMod::String::printf(const char *fmt, ...)
+void PokeGen::PokeMod::String::Printf(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
@@ -45,7 +45,7 @@ void PokeGen::PokeMod::String::printf(const char *fmt, ...)
va_end(args);
}
-void PokeGen::PokeMod::String::printf(const char *fmt, va_list &args)
+void PokeGen::PokeMod::String::Printf(const char *fmt, va_list &args)
{
Format unit;
std::stringstream ss;
@@ -130,7 +130,116 @@ void PokeGen::PokeMod::String::printf(const char *fmt, va_list &args)
append(1, *p);
++p;
}
+}
+
+unsigned PokeGen::PokeMod::String::Count(const char c) const
+{
+ unsigned count = 0;
+ for (unsigned i = 0; i < length(); ++i)
+ count += (*this[i] == c);
+ return count;
+}
+
+unsigned PokeGen::PokeMod::String::Count(const String &s, bool canOverlap) const
+{
+ unsigned count = 0;
+ for (unsigned i = 0; i + s.length() < length(); ++i)
+ {
+ if (this->substr(i, i + s.length() - 1) == s)
+ {
+ ++count;
+ if (!canOverlap)
+ i += s.length() - 1;
+ }
+ }
+ return count;
}
+
+bool PokeGen::PokeMod::String::Convert(bool &val) const
+{
+ if (*this == "true")
+ val = true;
+ else if (*this == "false")
+ val = false;
+ else
+ return false;
+ return true;
+}
+
+bool PokeGen::PokeMod::String::Convert(char &val) const
+{
+ long temp;
+ char *end;
+ temp = std::strtol(c_str(), &end, 10);
+ if ((CHAR_MIN <= temp) && (temp <= CHAR_MAX) && !*end)
+ val = temp;
+ else
+ return false;
+ return true;
+}
+
+bool PokeGen::PokeMod::String::Convert(unsigned char &val) const
+{
+ unsigned long temp;
+ char *end;
+ temp = std::strtoul(c_str(), &end, 10);
+ if ((temp <= UCHAR_MAX) && !*end)
+ val = temp;
+ else
+ return false;
+ return true;
+}
+
+bool PokeGen::PokeMod::String::Convert(int &val) const
+{
+ long temp;
+ char *end;
+ temp = std::strtol(c_str(), &end, 10);
+ if ((INT_MIN <= temp) && (temp <= INT_MAX) && !*end)
+ val = temp;
+ else
+ return false;
+ return true;
+}
+
+bool PokeGen::PokeMod::String::Convert(unsigned &val) const
+{
+ unsigned long temp;
+ char *end;
+ temp = std::strtoul(c_str(), &end, 10);
+ if ((temp <= UINT_MAX) && !*end)
+ val = temp;
+ else
+ return false;
+ return true;
+}
+
+bool PokeGen::PokeMod::String::Convert(long &val) const
+{
+ long temp;
+ char *end;
+ temp = std::strtol(c_str(), &end, 10);
+ if (!*end)
+ val = temp;
+ return !*end;
+}
+
+bool PokeGen::PokeMod::String::Convert(unsigned long &val) const
+{
+ unsigned long temp;
+ char *end;
+ temp = std::strtoul(c_str(), &end, 10);
+ if (!*end)
+ val = temp;
+ return !*end;
+}
+
+bool PokeGen::PokeMod::String::Convert(double &val) const
+{
+ char *end;
+ val = std::strtod(c_str(), &end);
+ return !*end;
+}
PokeGen::PokeMod::String::operator const char *() const
{