mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 19:57:57 +01:00
[PowerRename] Add option for Capitalization (#10213)
* Add camelcase instances + helper translation * Add camel case testing * Update Helpers.cpp * Update PowerRenameUI.cpp * Update src/modules/powerrename/ui/PowerRenameUI.cpp Co-authored-by: Enrico Giordani <enricogior@users.noreply.github.com> * Change camel case to capitalized, move ui * Update PowerRenameManagerTests.cpp * Update PowerRenameUI.base.rc * Update PowerRenameUI.base.rc Co-authored-by: Enrico Giordani <enricogior@users.noreply.github.com>
This commit is contained in:
@@ -159,6 +159,42 @@ HRESULT GetTransformedFileName(_Out_ PWSTR result, UINT cchMax, _In_ PCWSTR sour
|
||||
{
|
||||
hr = StringCchCopy(result, cchMax, source);
|
||||
}
|
||||
}
|
||||
else if (flags & Capitalized)
|
||||
{
|
||||
if (!(flags & ExtensionOnly))
|
||||
{
|
||||
std::wstring stem = fs::path(source).stem().wstring();
|
||||
std::wstring extension = fs::path(source).extension().wstring();
|
||||
|
||||
size_t stemLength = stem.length();
|
||||
|
||||
while (stemLength > 0 && (iswspace(stem[stemLength - 1]) || iswpunct(stem[stemLength - 1])))
|
||||
{
|
||||
stemLength--;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < stemLength; i++)
|
||||
{
|
||||
if (!i || iswspace(stem[i - 1]) || iswpunct(stem[i - 1]))
|
||||
{
|
||||
if (iswspace(stem[i]) || iswpunct(stem[i]))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
stem[i] = towupper(stem[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
stem[i] = towlower(stem[i]);
|
||||
}
|
||||
}
|
||||
hr = StringCchPrintf(result, cchMax, L"%s%s", stem.c_str(), extension.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
hr = StringCchCopy(result, cchMax, source);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user