Skip to content

Commit

Permalink
Utils: Added a bunch of helper text cleaning funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
Aemony committed Jun 9, 2024
1 parent 67114db commit 8f17bdb
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 8 deletions.
12 changes: 12 additions & 0 deletions include/utility/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,24 @@ std:: string SKIF_Util_ToLower (std:: string_view input);
std::wstring SKIF_Util_ToLowerW (std::wstring_view input);
std:: string SKIF_Util_ToUpper (std:: string_view input);
std::wstring SKIF_Util_ToUpperW (std::wstring_view input);
void SKIF_Util_CleanString (std:: string& input);
void SKIF_Util_CleanStringW (std::wstring& input);
void SKIF_Util_StripNulls (std:: string& input);
void SKIF_Util_StripNullsW (std::wstring& input);
void SKIF_Util_StripCarriageReturns (std:: string& input);
void SKIF_Util_StripCarriageReturnsW (std::wstring& input);
void SKIF_Util_TrimSpaces (std:: string& input);
void SKIF_Util_TrimSpacesW (std::wstring& input);
void SKIF_Util_TrimLeadingSpaces (std:: string& input);
void SKIF_Util_TrimLeadingSpacesW (std::wstring& input);
void SKIF_Util_TrimTrailingSpaces (std:: string& input);
void SKIF_Util_TrimTrailingSpacesW (std::wstring& input);
void SKIF_Util_TrimNewLines (std:: string& input);
void SKIF_Util_TrimNewLinesW (std::wstring& input);
void SKIF_Util_TrimLeadingNewlines (std:: string& input);
void SKIF_Util_TrimLeadingNewlinesW (std::wstring& input);
void SKIF_Util_TrimTrailingNewlines (std:: string& input);
void SKIF_Util_TrimTrailingNewlinesW (std::wstring& input);
std::wstring SKIF_Util_GetErrorAsWStr (DWORD error = GetLastError ( ), HMODULE module = NULL);
void SKIF_Util_GetErrorAsMsgBox (std::wstring winTitle = L"Error detected", std::wstring preMsg = L"", DWORD error = GetLastError ( ), HMODULE module = NULL);
DWORD SKIF_Util_timeGetTime (void);
Expand Down
94 changes: 86 additions & 8 deletions src/utility/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,42 +119,120 @@ SKIF_Util_ToUpperW (std::wstring_view input)
return copy;
}

void
SKIF_Util_CleanString (std::string& input)
{
SKIF_Util_StripNulls (input);
SKIF_Util_StripCarriageReturns (input);
SKIF_Util_TrimSpaces (input);
}

void
SKIF_Util_CleanStringW (std::wstring& input)
{
SKIF_Util_StripNullsW (input);
SKIF_Util_StripCarriageReturnsW (input);
SKIF_Util_TrimSpacesW (input);
}

void
SKIF_Util_StripNulls (std::string& input)
{
input.erase (std::find (input.begin(), input.end(), '\0'), input.end());
}

void
SKIF_Util_StripNullsW (std::wstring& input)
{
input.erase (std::find (input.begin(), input.end(), L'\0'), input.end());
}

void
SKIF_Util_StripCarriageReturns (std::string& input)
{
input.erase (std::find (input.begin(), input.end(), '\r'), input.end());
}

void
SKIF_Util_StripCarriageReturnsW (std::wstring& input)
{
input.erase (std::find (input.begin(), input.end(), L'\r'), input.end());
}

void
SKIF_Util_TrimSpaces (std::string& input)
{
SKIF_Util_TrimLeadingSpaces (input);
SKIF_Util_TrimTrailingSpaces (input);
SKIF_Util_TrimLeadingSpaces (input);
SKIF_Util_TrimTrailingSpaces (input);
}

void
SKIF_Util_TrimSpacesW (std::wstring& input)
{
SKIF_Util_TrimLeadingSpacesW (input);
SKIF_Util_TrimTrailingSpacesW (input);
SKIF_Util_TrimLeadingSpacesW (input);
SKIF_Util_TrimTrailingSpacesW (input);
}

void
SKIF_Util_TrimLeadingSpaces (std::string& input)
{
input.erase (input.begin(), std::find_if (input.begin(), input.end(), [](unsigned char ch) { return !std::isspace (ch); }));
input.erase (input.begin(), std::find_if (input.begin(), input.end(), [](const unsigned char ch) { return !std::isspace (ch); }));
}

void
SKIF_Util_TrimLeadingSpacesW (std::wstring& input)
{
input.erase (input.begin(), std::find_if (input.begin(), input.end(), []( wchar_t ch) { return !std::iswspace (ch); }));
input.erase (input.begin(), std::find_if (input.begin(), input.end(), [](const wchar_t ch) { return !std::iswspace (ch); }));
}

void
SKIF_Util_TrimTrailingSpaces (std::string& input)
{
input.erase (std::find_if (input.rbegin(), input.rend(), [](unsigned char ch) { return !std::isspace (ch); }).base(), input.end());
input.erase (std::find_if (input.rbegin(), input.rend(), [](const unsigned char ch) { return !std::isspace (ch); }).base(), input.end());
}

void
SKIF_Util_TrimTrailingSpacesW (std::wstring& input)
{
input.erase (std::find_if (input.rbegin(), input.rend(), []( wchar_t ch) { return !std::iswspace (ch); }).base(), input.end());
input.erase (std::find_if (input.rbegin(), input.rend(), [](const wchar_t ch) { return !std::iswspace (ch); }).base(), input.end());
}

void
SKIF_Util_TrimNewLines (std::string& input)
{
SKIF_Util_TrimLeadingNewlines (input);
SKIF_Util_TrimTrailingNewlines (input);
}

void
SKIF_Util_TrimNewLinesW (std::wstring& input)
{
SKIF_Util_TrimLeadingNewlinesW (input);
SKIF_Util_TrimTrailingNewlinesW (input);
}

void
SKIF_Util_TrimLeadingNewlines (std::string& input)
{
input.erase (input.begin(), std::find_if (input.begin(), input.end(), [](const unsigned char ch) { return (ch != '\n'); }));
}

void
SKIF_Util_TrimLeadingNewlinesW (std::wstring& input)
{
input.erase (input.begin(), std::find_if (input.begin(), input.end(), [](const wchar_t ch) { return (ch != L'\n'); }));
}

void
SKIF_Util_TrimTrailingNewlines (std::string& input)
{
input.erase (std::find_if (input.rbegin(), input.rend(), [](const unsigned char ch) { return (ch != '\n'); }).base(), input.end());
}

void
SKIF_Util_TrimTrailingNewlinesW (std::wstring& input)
{
input.erase (std::find_if (input.rbegin(), input.rend(), [](const wchar_t ch) { return (ch != L'\n'); }).base(), input.end());
}


Expand Down

0 comments on commit 8f17bdb

Please sign in to comment.