diff --git a/Source/Engine/Core/Types/StringView.cpp b/Source/Engine/Core/Types/StringView.cpp
index d6cbb3a6a..e29afe4e8 100644
--- a/Source/Engine/Core/Types/StringView.cpp
+++ b/Source/Engine/Core/Types/StringView.cpp
@@ -27,6 +27,18 @@ bool StringView::operator!=(const String& other) const
return StringUtils::Compare(this->GetText(), *other) != 0;
}
+String StringView::Left(int32 count) const
+{
+ const int32 countClamped = count < 0 ? 0 : count < Length() ? count : Length();
+ return String(**this, countClamped);
+}
+
+String StringView::Right(int32 count) const
+{
+ const int32 countClamped = count < 0 ? 0 : count < Length() ? count : Length();
+ return String(**this + Length() - countClamped);
+}
+
String StringView::Substring(int32 startIndex) const
{
ASSERT(startIndex >= 0 && startIndex < Length());
diff --git a/Source/Engine/Core/Types/StringView.h b/Source/Engine/Core/Types/StringView.h
index 5d5ad2799..b413ff552 100644
--- a/Source/Engine/Core/Types/StringView.h
+++ b/Source/Engine/Core/Types/StringView.h
@@ -321,6 +321,20 @@ public:
public:
+ ///
+ /// Gets the left most given number of characters.
+ ///
+ /// The characters count.
+ /// The substring.
+ String Left(int32 count) const;
+
+ ///
+ /// Gets the string of characters from the right (end of the string).
+ ///
+ /// The characters count.
+ /// The substring.
+ String Right(int32 count) const;
+
///
/// Retrieves substring created from characters starting from startIndex to the String end.
///
diff --git a/Source/Engine/Platform/Base/StringUtilsBase.cpp b/Source/Engine/Platform/Base/StringUtilsBase.cpp
index b492abc9b..e8fe3ebc3 100644
--- a/Source/Engine/Platform/Base/StringUtilsBase.cpp
+++ b/Source/Engine/Platform/Base/StringUtilsBase.cpp
@@ -289,7 +289,7 @@ void RemoveLongPathPrefix(const String& path, String& result)
result.Remove(2, 6);
}
-String StringUtils::GetDirectoryName(const String& path)
+String StringUtils::GetDirectoryName(const StringView& path)
{
const int32 lastFrontSlash = path.FindLast('\\');
const int32 lastBackSlash = path.FindLast('/');
@@ -297,24 +297,22 @@ String StringUtils::GetDirectoryName(const String& path)
return splitIndex != INVALID_INDEX ? path.Left(splitIndex) : String::Empty;
}
-String StringUtils::GetFileName(const String& path)
+String StringUtils::GetFileName(const StringView& path)
{
Char chr;
const int32 length = path.Length();
int32 num = length;
-
do
{
num--;
if (num < 0)
- return path;
+ return String(path);
chr = path[num];
} while (chr != DirectorySeparatorChar && chr != AltDirectorySeparatorChar && chr != VolumeSeparatorChar);
-
return path.Substring(num + 1, length - num - 1);
}
-String StringUtils::GetFileNameWithoutExtension(const String& path)
+String StringUtils::GetFileNameWithoutExtension(const StringView& path)
{
String filename = GetFileName(path);
const int32 num = filename.FindLast('.');
@@ -325,14 +323,14 @@ String StringUtils::GetFileNameWithoutExtension(const String& path)
return filename;
}
-String StringUtils::GetPathWithoutExtension(const String& path)
+String StringUtils::GetPathWithoutExtension(const StringView& path)
{
const int32 num = path.FindLast('.');
if (num != -1)
{
return path.Substring(0, num);
}
- return path;
+ return String(path);
}
void StringUtils::PathRemoveRelativeParts(String& path)
diff --git a/Source/Engine/Platform/StringUtils.h b/Source/Engine/Platform/StringUtils.h
index 7e0b7b422..9d812bc47 100644
--- a/Source/Engine/Platform/StringUtils.h
+++ b/Source/Engine/Platform/StringUtils.h
@@ -207,19 +207,19 @@ public:
// Returns the directory name of the specified path string
// @param path The path string from which to obtain the directory name
// @returns Directory name
- static String GetDirectoryName(const String& path);
+ static String GetDirectoryName(const StringView& path);
// Returns the file name and extension of the specified path string
// @param path The path string from which to obtain the file name and extension
// @returns File name with extension
- static String GetFileName(const String& path);
+ static String GetFileName(const StringView& path);
// Returns the file name without extension of the specified path string
// @param path The path string from which to obtain the file name
// @returns File name without extension
- static String GetFileNameWithoutExtension(const String& path);
+ static String GetFileNameWithoutExtension(const StringView& path);
- static String GetPathWithoutExtension(const String& path);
+ static String GetPathWithoutExtension(const StringView& path);
static void PathRemoveRelativeParts(String& path);