2012-06-14 06:06:06 -07:00
|
|
|
|
|
|
|
// 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, ...);
|
|
|
|
|
2012-11-15 02:58:46 -08:00
|
|
|
/// Output the formatted text into string, return string by value
|
|
|
|
extern AString Printf(const char * format, ...);
|
|
|
|
|
2012-06-14 06:06:06 -07:00
|
|
|
/// Add the formatted string to the existing data in the string
|
|
|
|
extern AString & AppendPrintf (AString & str, const char * format, ...);
|
|
|
|
|
2013-05-01 10:02:09 -07:00
|
|
|
/// Split the string at any of the listed delimiters, return as a stringvector
|
2012-06-14 06:06:06 -07:00
|
|
|
extern AStringVector StringSplit(const AString & str, const AString & delim);
|
|
|
|
|
2013-05-01 10:02:09 -07:00
|
|
|
/// Split the string at any of the listed delimiters and trim each value, return as a stringvector
|
2013-03-14 02:52:57 -07:00
|
|
|
extern AStringVector StringSplitAndTrim(const AString & str, const AString & delim);
|
|
|
|
|
2012-06-14 06:06:06 -07:00
|
|
|
/// Trime whitespace at both ends of the string
|
2013-07-07 07:42:07 -07:00
|
|
|
extern AString TrimString(const AString & str); // tolua_export
|
2012-06-14 06:06:06 -07:00
|
|
|
|
|
|
|
/// In-place string conversion to uppercase; returns the same string
|
|
|
|
extern AString & StrToUpper(AString & s);
|
|
|
|
|
|
|
|
/// Case-insensitive string comparison; returns 0 if the strings are the same
|
2013-07-07 07:42:07 -07:00
|
|
|
extern int NoCaseCompare(const AString & s1, const AString & s2); // tolua_export
|
2012-06-14 06:06:06 -07:00
|
|
|
|
2012-08-22 16:05:12 -07:00
|
|
|
/// 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 );
|
|
|
|
|
2012-06-14 06:06:06 -07:00
|
|
|
/// Replaces *each* occurence of iNeedle in iHayStack with iReplaceWith
|
2013-07-07 07:42:07 -07:00
|
|
|
extern void ReplaceString(AString & iHayStack, const AString & iNeedle, const AString & iReplaceWith); // tolua_export
|
2012-06-14 06:06:06 -07:00
|
|
|
|
|
|
|
/// Returns the list of all items in the specified directory (files, folders, nix pipes, whatever's there)
|
|
|
|
extern AStringList GetDirectoryContents(const char * a_Directory);
|
|
|
|
|
2012-08-17 03:18:07 -07:00
|
|
|
/// 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);
|
|
|
|
|
2012-08-28 14:59:49 -07:00
|
|
|
/// 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);
|
|
|
|
|
2012-09-02 02:04:11 -07:00
|
|
|
/// 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);
|
2012-06-14 06:06:06 -07:00
|
|
|
|
2013-07-07 07:13:43 -07:00
|
|
|
/// Returns a copy of a_Message with all quotes and backslashes escaped by a backslash
|
2013-07-07 07:42:07 -07:00
|
|
|
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
|
2013-07-07 07:13:43 -07:00
|
|
|
|
2012-06-14 06:06:06 -07:00
|
|
|
// If you have any other string helper functions, declare them here
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif // STRINGUTILS_H_INCLUDED
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|