diff options
| author | Adam <Adam@anope.org> | 2014-06-23 07:12:41 -0400 |
|---|---|---|
| committer | Adam <Adam@anope.org> | 2014-06-23 07:12:41 -0400 |
| commit | 148b26f687ce85dc01e852a2358b03d493757ada (patch) | |
| tree | f81ea553d0384ec6063eff45cfaff5aa92aaa1c9 | |
| parent | 0dba0692f9f88275b7d89d511bf22124217bc4c6 (diff) | |
Mostly working language string rewrite with new format strings
124 files changed, 3234 insertions, 3616 deletions
diff --git a/include/anope.h b/include/anope.h index 845a2b1fb..839d201cf 100644 --- a/include/anope.h +++ b/include/anope.h @@ -631,7 +631,7 @@ class spacesepstream : public sepstream public: /** Initialize with space seperator */ - spacesepstream(const Anope::string &source) : sepstream(source, ' ') { } + spacesepstream(const Anope::string &source, bool allowempty = false) : sepstream(source, ' ', allowempty) { } }; /** This class can be used on its own to represent an exception, or derived to represent a module-specific exception. @@ -775,3 +775,67 @@ template<typename T, typename O> inline T anope_dynamic_static_cast(O ptr) return static_cast<T>(ptr); } #endif + +struct kwarg +{ + Anope::string name, value; + + template<typename T> + kwarg& operator=(const T& rhs) + { + value = stringify(rhs); + return *this; + } +}; + +inline kwarg operator"" _kw(const char *literal, size_t n) +{ + return kwarg{ literal }; +} + +struct FormatInfo +{ + Anope::string format; + std::vector<kwarg> parameters; + unsigned int pos = 0; + + FormatInfo(const Anope::string &fmt, size_t size) : format(fmt), parameters(size) { } + + template<typename T> + void Add(T& arg) + { + parameters[pos] = kwarg{ stringify(pos).c_str() } = stringify(arg); + ++pos; + } + + template<typename Arg, typename... Args> + void Format(Arg &&arg, Args&&... args) + { + Add(arg); + Format(std::forward<Args>(args)...); + } + + void Format() + { + for (kwarg& arg : parameters) + format = format.replace_all_cs("{" + arg.name + "}", arg.value); + } +}; + +template<> +inline void FormatInfo::Add(kwarg &arg) +{ + parameters[pos++] = arg; +} + +namespace Anope +{ + template<typename... Args> + inline Anope::string Format(const Anope::string &format, Args&&... args) + { + FormatInfo fi(format, sizeof...(Args)); + fi.Format(std::forward<Args>(args)...); + return fi.format; + } +} + diff --git a/include/bots.h b/include/bots.h index 9a2c5d237..ef57d31f3 100644 --- a/include/bots.h +++ b/include/bots.h @@ -124,6 +124,8 @@ class CoreExport BotInfo : public User, public Serializable */ CommandInfo *GetCommand(const Anope::string &cname); + CommandInfo *FindCommand(const Anope::string &service); + /** Find a bot by nick * @param nick The nick * @param nick_only True to only look by nick, and not by UID diff --git a/include/commands.h b/include/commands.h index 359995f8f..6f29aa135 100644 --- a/include/commands.h +++ b/include/commands.h @@ -14,6 +14,7 @@ #include "service.h" #include "anope.h" #include "channels.h" +#include "language.h" struct CommandGroup { @@ -29,6 +30,8 @@ struct CommandInfo /* Service name of the command */ Anope::string name; + /* User visible name */ + Anope::string cname; /* Permission required to execute the command */ Anope::string permission; /* Group this command is in */ @@ -77,7 +80,13 @@ class CoreExport CommandSource ChanServ::AccessGroup AccessFor(ChanServ::Channel *ci); bool IsFounder(ChanServ::Channel *ci); - void Reply(const char *message, ...); + template<typename... Args> + void Reply(const char *message, Args&&... args) + { + const char *translated_message = Language::Translate(this->nc, message); + Reply(Anope::Format(translate |
