summaryrefslogtreecommitdiffstats
path: root/src/StringUtils.h
diff options
context:
space:
mode:
authorworktycho <work.tycho@gmail.com>2013-12-09 18:51:12 +0100
committerworktycho <work.tycho@gmail.com>2013-12-09 18:51:12 +0100
commit843605d59ebc128be0a578dc6f45ef8c05da6e79 (patch)
tree3ffebc6ba27baf7a9e1d4bc51501ffeea9b14226 /src/StringUtils.h
parentmerged makefile changes (diff)
parentFix Undefined behavior at Bindings/LuaWindow line 32 (diff)
downloadcuberite-843605d59ebc128be0a578dc6f45ef8c05da6e79.tar
cuberite-843605d59ebc128be0a578dc6f45ef8c05da6e79.tar.gz
cuberite-843605d59ebc128be0a578dc6f45ef8c05da6e79.tar.bz2
cuberite-843605d59ebc128be0a578dc6f45ef8c05da6e79.tar.lz
cuberite-843605d59ebc128be0a578dc6f45ef8c05da6e79.tar.xz
cuberite-843605d59ebc128be0a578dc6f45ef8c05da6e79.tar.zst
cuberite-843605d59ebc128be0a578dc6f45ef8c05da6e79.zip
Diffstat (limited to 'src/StringUtils.h')
-rw-r--r--src/StringUtils.h93
1 files changed, 93 insertions, 0 deletions
diff --git a/src/StringUtils.h b/src/StringUtils.h
new file mode 100644
index 000000000..3917cc4ec
--- /dev/null
+++ b/src/StringUtils.h
@@ -0,0 +1,93 @@
+
+// StringUtils.h
+
+// Interfaces to various string helper functions
+
+
+
+
+#ifndef STRINGUTILS_H_INCLUDED
+#define STRINGUTILS_H_INCLUDED
+
+
+
+
+
+typedef std::string AString;
+typedef std::vector<AString> AStringVector;
+typedef std::list<AString> AStringList;
+
+
+
+
+
+/// Add the formated string to the existing data in the string
+extern AString & AppendVPrintf(AString & str, const char * format, va_list args);
+
+/// Output the formatted text into the string
+extern AString & Printf (AString & str, const char * format, ...);
+
+/// Output the formatted text into string, return string by value
+extern AString Printf(const char * format, ...);
+
+/// Add the formatted string to the existing data in the string
+extern AString & AppendPrintf (AString & str, const char * format, ...);
+
+/// Split the string at any of the listed delimiters, return as a stringvector
+extern AStringVector StringSplit(const AString & str, const AString & delim);
+
+/// Split the string at any of the listed delimiters and trim each value, return as a stringvector
+extern AStringVector StringSplitAndTrim(const AString & str, const AString & delim);
+
+/// Trime whitespace at both ends of the string
+extern AString TrimString(const AString & str); // tolua_export
+
+/// In-place string conversion to uppercase; returns the same string
+extern AString & StrToUpper(AString & s);
+
+/// In-place string conversion to lowercase; returns the same string
+extern AString & StrToLower(AString & s);
+
+/// Case-insensitive string comparison; returns 0 if the strings are the same
+extern int NoCaseCompare(const AString & s1, const AString & s2); // tolua_export
+
+/// Case-insensitive string comparison that returns a rating of equal-ness between [0 - s1.length()]
+extern unsigned int RateCompareString(const AString & s1, const AString & s2 );
+
+/// Replaces *each* occurence of iNeedle in iHayStack with iReplaceWith
+extern void ReplaceString(AString & iHayStack, const AString & iNeedle, const AString & iReplaceWith); // tolua_export
+
+/// Converts a stream of BE shorts into UTF-8 string; returns a ref to a_UTF8
+extern AString & RawBEToUTF8(short * a_RawData, int a_NumShorts, AString & a_UTF8);
+
+/// Converts a UTF-8 string into a UTF-16 BE string, packing that back into AString; return a ref to a_UTF16
+extern AString & UTF8ToRawBEUTF16(const char * a_UTF8, size_t a_UTF8Length, AString & a_UTF16);
+
+/// Creates a nicely formatted HEX dump of the given memory block. Max a_BytesPerLine is 120
+extern AString & CreateHexDump(AString & a_Out, const void * a_Data, int a_Size, int a_BytesPerLine);
+
+/// Returns a copy of a_Message with all quotes and backslashes escaped by a backslash
+extern AString EscapeString(const AString & a_Message); // tolua_export
+
+/// Removes all control codes used by MC for colors and styles
+extern AString StripColorCodes(const AString & a_Message); // tolua_export
+
+/// URL-Decodes the given string, replacing all "%HH" into the correct characters. Invalid % sequences are left intact
+extern AString URLDecode(const AString & a_String); // Cannot export to Lua automatically - would generated an extra return value
+
+/// Replaces all occurrences of char a_From inside a_String with char a_To.
+extern AString ReplaceAllCharOccurrences(const AString & a_String, char a_From, char a_To); // Needn't export to Lua, since Lua doesn't have chars anyway
+
+/// Decodes a Base64-encoded string into the raw data
+extern AString Base64Decode(const AString & a_Base64String);
+
+// If you have any other string helper functions, declare them here
+
+
+
+
+#endif // STRINGUTILS_H_INCLUDED
+
+
+
+