|
@@ -31,7 +31,6 @@
|
|
|
|
|
|
|
|
#include "Header.h"
|
|
#include "Header.h"
|
|
|
#include "Types.h"
|
|
#include "Types.h"
|
|
|
-#include "String.h"
|
|
|
|
|
|
|
|
|
|
namespace Rml {
|
|
namespace Rml {
|
|
|
namespace Core {
|
|
namespace Core {
|
|
@@ -41,47 +40,64 @@ namespace Core {
|
|
|
@author Lloyd Weehuizen
|
|
@author Lloyd Weehuizen
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
-class RMLUICORE_API StringUtilities
|
|
|
|
|
|
|
+// Redefine Windows APIs as their STDC counterparts.
|
|
|
|
|
+#ifdef RMLUI_PLATFORM_WIN32
|
|
|
|
|
+ #define strcasecmp stricmp
|
|
|
|
|
+ #define strncasecmp strnicmp
|
|
|
|
|
+#endif
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+/// Construct a string using sprintf-style syntax.
|
|
|
|
|
+RMLUICORE_API String CreateString(size_t max_size, const char* format, ...);
|
|
|
|
|
+
|
|
|
|
|
+/// Format to a string using sprintf-style syntax.
|
|
|
|
|
+RMLUICORE_API int FormatString(String& string, size_t max_size, const char* format, ...);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+namespace StringUtilities
|
|
|
{
|
|
{
|
|
|
-public:
|
|
|
|
|
/// Expands character-delimited list of values in a single string to a whitespace-trimmed list
|
|
/// Expands character-delimited list of values in a single string to a whitespace-trimmed list
|
|
|
/// of values.
|
|
/// of values.
|
|
|
/// @param[out] string_list Resulting list of values.
|
|
/// @param[out] string_list Resulting list of values.
|
|
|
/// @param[in] string String to expand.
|
|
/// @param[in] string String to expand.
|
|
|
/// @param[in] delimiter Delimiter found between entries in the string list.
|
|
/// @param[in] delimiter Delimiter found between entries in the string list.
|
|
|
- static void ExpandString(StringList& string_list, const String& string, const char delimiter = ',');
|
|
|
|
|
|
|
+ RMLUICORE_API void ExpandString(StringList& string_list, const String& string, const char delimiter = ',');
|
|
|
/// Expands character-delimited list of values with custom quote characters.
|
|
/// Expands character-delimited list of values with custom quote characters.
|
|
|
/// @param[out] string_list Resulting list of values.
|
|
/// @param[out] string_list Resulting list of values.
|
|
|
/// @param[in] string String to expand.
|
|
/// @param[in] string String to expand.
|
|
|
/// @param[in] delimiter Delimiter found between entries in the string list.
|
|
/// @param[in] delimiter Delimiter found between entries in the string list.
|
|
|
/// @param[in] quote_character Begin quote
|
|
/// @param[in] quote_character Begin quote
|
|
|
/// @param[in] unquote_character End quote
|
|
/// @param[in] unquote_character End quote
|
|
|
- static void ExpandString(StringList& string_list, const String& string, const char delimiter, char quote_character, char unquote_character);
|
|
|
|
|
|
|
+ RMLUICORE_API void ExpandString(StringList& string_list, const String& string, const char delimiter, char quote_character, char unquote_character);
|
|
|
/// Joins a list of string values into a single string separated by a character delimiter.
|
|
/// Joins a list of string values into a single string separated by a character delimiter.
|
|
|
/// @param[out] string Resulting concatenated string.
|
|
/// @param[out] string Resulting concatenated string.
|
|
|
/// @param[in] string_list Input list of string values.
|
|
/// @param[in] string_list Input list of string values.
|
|
|
/// @param[in] delimiter Delimiter to insert between the individual values.
|
|
/// @param[in] delimiter Delimiter to insert between the individual values.
|
|
|
- static void JoinString(String& string, const StringList& string_list, const char delimiter = ',');
|
|
|
|
|
|
|
+ RMLUICORE_API void JoinString(String& string, const StringList& string_list, const char delimiter = ',');
|
|
|
|
|
|
|
|
- /// Converts a character array in UTF-8 encoding to a vector of words. The UCS-2 words will be encoded as
|
|
|
|
|
- /// either big- or little-endian, depending on the host processor.
|
|
|
|
|
- /// @param[in] input Input string in UTF-8 encoding.
|
|
|
|
|
- /// @param[out] output Output string of UCS-2 characters.
|
|
|
|
|
- /// @return True if the conversion went successfully, false if any characters had to be skipped (this will occur if they can't fit into UCS-2).
|
|
|
|
|
- static bool UTF8toUCS2(const String& input, WString& output);
|
|
|
|
|
|
|
+ /// Converts a string in UTF-8 encoding to a wide string in UCS-2 encoding. The UCS-2 words will
|
|
|
|
|
+ /// be encoded as either big- or little-endian, depending on the host processor.
|
|
|
|
|
+ /// Reports a warning if the conversion fails.
|
|
|
|
|
+ RMLUICORE_API WString ToUCS2(const String& str);
|
|
|
|
|
|
|
|
- /// Converts an array of words in UCS-2 encoding into a character array in UTF-8 encoding. This
|
|
|
|
|
|
|
+ /// Converts a wide string in UCS-2 encoding into a string in UTF-8 encoding. This
|
|
|
/// function assumes the endianness of the input words to be the same as the host processor.
|
|
/// function assumes the endianness of the input words to be the same as the host processor.
|
|
|
- /// @param[in] input Input string of words in UCS-2 encoding.
|
|
|
|
|
- /// @param[out] output Output string in UTF-8 encoding.
|
|
|
|
|
- /// @return True if the conversion went successfully, false if not.
|
|
|
|
|
- static bool UCS2toUTF8(const WString& input, String& output);
|
|
|
|
|
|
|
+ /// Reports a warning if the conversion fails.
|
|
|
|
|
+ RMLUICORE_API String ToUTF8(const WString& wstr);
|
|
|
|
|
+
|
|
|
|
|
+ /// Converts upper-case characters in string to lower-case.
|
|
|
|
|
+ RMLUICORE_API String ToLower(const String& string);
|
|
|
|
|
+
|
|
|
|
|
+ // Replaces all occurences of 'search' in 'subject' with 'replace'.
|
|
|
|
|
+ RMLUICORE_API String Replace(String subject, const String& search, const String& replace);
|
|
|
|
|
+ // Replaces all occurences of 'search' in 'subject' with 'replace'.
|
|
|
|
|
+ RMLUICORE_API String Replace(String subject, char search, char replace);
|
|
|
|
|
|
|
|
/// Checks if a given value is a whitespace character.
|
|
/// Checks if a given value is a whitespace character.
|
|
|
/// @param[in] x The character to evaluate.
|
|
/// @param[in] x The character to evaluate.
|
|
|
/// @return True if the character is whitespace, false otherwise.
|
|
/// @return True if the character is whitespace, false otherwise.
|
|
|
template < typename CharacterType >
|
|
template < typename CharacterType >
|
|
|
- static bool IsWhitespace(CharacterType x)
|
|
|
|
|
|
|
+ inline bool IsWhitespace(CharacterType x)
|
|
|
{
|
|
{
|
|
|
return (x == '\r' || x == '\n' || x == ' ' || x == '\t');
|
|
return (x == '\r' || x == '\n' || x == ' ' || x == '\t');
|
|
|
}
|
|
}
|
|
@@ -89,14 +105,14 @@ public:
|
|
|
/// Strip whitespace characters from the beginning and end of a string.
|
|
/// Strip whitespace characters from the beginning and end of a string.
|
|
|
/// @param[in] string The string to trim.
|
|
/// @param[in] string The string to trim.
|
|
|
/// @return The stripped string.
|
|
/// @return The stripped string.
|
|
|
- static String StripWhitespace(const String& string);
|
|
|
|
|
|
|
+ RMLUICORE_API String StripWhitespace(const String& string);
|
|
|
|
|
|
|
|
/// Operator for STL containers using strings.
|
|
/// Operator for STL containers using strings.
|
|
|
struct RMLUICORE_API StringComparei
|
|
struct RMLUICORE_API StringComparei
|
|
|
{
|
|
{
|
|
|
bool operator()(const String& lhs, const String& rhs) const;
|
|
bool operator()(const String& lhs, const String& rhs) const;
|
|
|
};
|
|
};
|
|
|
-};
|
|
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|