StringTools.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #pragma once
  5. JPH_NAMESPACE_BEGIN
  6. /// Create a formatted text string for debugging purposes.
  7. /// Note that this function has an internal buffer of 1024 characters, so long strings will be trimmed.
  8. JPH_EXPORT String StringFormat(const char *inFMT, ...);
  9. /// Convert type to string
  10. template<typename T>
  11. String ConvertToString(const T &inValue)
  12. {
  13. using OStringStream = std::basic_ostringstream<char, std::char_traits<char>, STLAllocator<char>>;
  14. OStringStream oss;
  15. oss << inValue;
  16. return oss.str();
  17. }
  18. /// Replace substring with other string
  19. JPH_EXPORT void StringReplace(String &ioString, const string_view &inSearch, const string_view &inReplace);
  20. /// Convert a delimited string to an array of strings
  21. JPH_EXPORT void StringToVector(const string_view &inString, Array<String> &outVector, const string_view &inDelimiter = ",", bool inClearVector = true);
  22. /// Convert an array strings to a delimited string
  23. JPH_EXPORT void VectorToString(const Array<String> &inVector, String &outString, const string_view &inDelimiter = ",");
  24. /// Convert a string to lower case
  25. JPH_EXPORT String ToLower(const string_view &inString);
  26. /// Converts the lower 4 bits of inNibble to a string that represents the number in binary format
  27. JPH_EXPORT const char *NibbleToBinary(uint32 inNibble);
  28. JPH_NAMESPACE_END