TurtleBrains  0.3.5
High quality, portable, C++ framework for rapid 2D game development.
tb_string_utilities.hpp
1 
10 #ifndef TurtleBrains_StringUtilities_hpp
11 #define TurtleBrains_StringUtilities_hpp
12 
13 #include <turtle_brains/core/tb_string.hpp>
14 
15 namespace TurtleBrains::Core::StringUtilities
16 {
17  // 2024-11-21: There is almost a certainty that String is getting renamed String, which is conflicting with
18  // this namespace. This should probably be named StringUtilities to match FileUtilties/SystemUtilities etc...
19  // ikiwixz suggests the String could also move directly into the TurtleBrains namespace. This would suggest
20  // that String type is extremely Core to TurtleBrains, but it would allow Game/Application and other areas to
21  // still use it as String instead of Core::String.
22  //
23  // For years I felt tbCore::String tbMath::Vector3 etc was the better approach since it clearly identified
24  // where the type lived, and I still think there is truth to that, but after testing typedefs in TrophyBrawlers
25  // where the game types are String, Vector3, iceVector3 etc it shortened lines of code considerably without
26  // negative impact.
27  //
28  // 2025-10-07: Consider "String::function" deprecated and start using StringUtilities in any new code.
29 
34  inline bool StringContains(const String& input, const String& contents)
35  {
36  return (String::npos == input.find(contents)) ? false : true;
37  }
38 
43  inline bool StringStartsWith(const String& input, const String& contents)
44  {
45  return (0 == input.find(contents)) ? true : false;
46  }
47 
48  bool IsOnlyWhitespace(const String& input);
49 
55  String ExtendedAsciiToUTF8(const String& input);
56 
59  String TrimWhitespace(String contents);
60 
63  String TrimLeadingWhitespace(String contents);
64 
67  String TrimTrailingWhitespace(String contents);
68 
69  String& TrimWhitespaceInPlace(String& contents);
70  String& TrimLeadingWhitespaceInPlace(String& contents);
71  String& TrimTrailingWhitespaceInPlace(String& contents);
72 
73  String Lowercase(const String& contents);
74  String& LowercaseInPlace(String& contents);
75  String Uppercase(const String& contents);
76  String& UppercaseInPlace(String& contents);
77 
78  String ReplaceFirstInstanceOf(const String& contents, const String& token, const String& replace);
79  String ReplaceAllInstancesOf(const String& contents, const String& token, const String& replace);
80 
81  bool StartsWith(const String& stringToSearch, const String& expectedStart);
82 
83  std::vector<std::string> SeparateString(const std::string& original, const std::string& token = " ");
84  std::vector<std::string> SeparateString(const std::string& original, const std::vector<std::string>& tokens);
85 
86  inline std::vector<std::string> SeparateString(const std::string& original, const std::initializer_list<std::string>& tokens)
87  {
88  return SeparateString(original, std::vector<std::string>(tokens));
89  }
90 
91  String LocalDateTimeToString(void);
92 
93  //235959
94  String LocalTimeToString(void);
95 
96  //20190131
97  String LocalDateToString(void);
98 
99  String TimeToString(const tbCore::uint32& timeInMilliseconds, const bool showMilliseconds = true, const bool forceMinutes = true);
100  String TimeToHourMinuteString(const tbCore::uint32& timeInMilliseconds);
101 
102 }; /* namespace TurtleBrains::Core::StringUtilities */
103 
104 namespace tbCore = TurtleBrains::Core;
105 
106 #endif /* TurtleBrains_StringUtilities_hpp */
Contains core functionality for each component of the API.
Definition: tb_debug_logger.hpp:125
std::string String
Definition: tb_string.hpp:302
std::uint32_t uint32
Unsigned integer with a size of 32 bits. Supports values from 0 to 4294967295, (2^32 - 1).
Definition: tb_types.hpp:27