Skip to content

Commit 9e6558e

Browse files
authored
Merge pull request #166 from end2endzone/feature-issue109
Replaced using CRLF by LF in IObject::ToLongString() implementations.
2 parents 5ffa505 + 1905766 commit 9e6558e

9 files changed

Lines changed: 35 additions & 28 deletions

File tree

src/core/ConfigFile.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -525,24 +525,22 @@ namespace shellanything
525525

526526
void ConfigFile::ToLongString(std::string& str, int indent) const
527527
{
528-
static const char* NEW_LINE = ra::environment::GetLineSeparator();
529528
const bool have_children = (mMenus.size() > 0);
530529
const std::string indent_str = std::string(indent, ' ');
531530

532531
const std::string short_string = ToShortString();
533532
str += indent_str + short_string;
534533
if (have_children)
535534
{
536-
str += " {";
537-
str += NEW_LINE;
535+
str += " {\n";
538536

539537
// print children
540538
for (size_t i = 0; i < mMenus.size(); i++)
541539
{
542540
Menu* menu = mMenus[i];
543541
menu->ToLongString(str, indent + 2);
544542

545-
str += NEW_LINE;
543+
str += "\n";
546544
}
547545

548546
str += indent_str + "}";

src/core/ConfigManager.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,24 +237,22 @@ namespace shellanything
237237

238238
void ConfigManager::ToLongString(std::string& str, int indent) const
239239
{
240-
static const char* NEW_LINE = ra::environment::GetLineSeparator();
241240
const bool have_children = (mConfigurations.size() > 0);
242241
const std::string indent_str = std::string(indent, ' ');
243242

244243
const std::string short_string = ToShortString();
245244
str += indent_str + short_string;
246245
if (have_children)
247246
{
248-
str += " {";
249-
str += NEW_LINE;
247+
str += " {\n";
250248

251249
// print config children
252250
for (size_t i = 0; i < mConfigurations.size(); i++)
253251
{
254252
ConfigFile* config = mConfigurations[i];
255253
config->ToLongString(str, indent + 2);
256254

257-
str += NEW_LINE;
255+
str += "\n";
258256
}
259257

260258
str += indent_str + "}";

src/core/IObject.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ namespace shellanything
4949

5050
/// <summary>
5151
/// Get a string representation of this object and its children.
52+
/// The output string is multiple lines. Each line separated by '\n' (LF) character.
5253
/// </summary>
5354
/// <param name="str">The string to append this object's description to.</param>
5455
/// <param name="indent">The indentation (spaces) to add before each line describing this object.</param>

src/core/Icon.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ namespace shellanything
175175

176176
void Icon::ToLongString(std::string& str, int indent) const
177177
{
178-
static const char* NEW_LINE = ra::environment::GetLineSeparator();
179178
const std::string indent_str = std::string(indent, ' ');
180179

181180
const std::string short_string = ToShortString();

src/core/Menu.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -516,50 +516,46 @@ namespace shellanything
516516

517517
void Menu::ToLongString(std::string& str, int indent) const
518518
{
519-
static const char* NEW_LINE = ra::environment::GetLineSeparator();
520519
const bool have_children = (mVisibilities.size() + mValidities.size() + mSubMenus.size() > 0);
521520
const std::string indent_str = std::string(indent, ' ');
522521

523522
const std::string short_string = ToShortString();
524523
str += indent_str + short_string;
525524
if (have_children)
526525
{
527-
str += " {";
528-
str += NEW_LINE;
526+
str += " {\n";
529527

530528
// print visibility children
531529
if (mVisibilities.size())
532530
{
533-
str += indent_str + " Visibilities:";
534-
str += NEW_LINE;
531+
str += indent_str + " Visibilities:\n";
535532
}
536533
for (size_t i = 0; i < mVisibilities.size(); i++)
537534
{
538535
Validator* validator = mVisibilities[i];
539536
validator->ToLongString(str, indent + 4);
540537

541-
str += NEW_LINE;
538+
str += "\n";
542539
}
543540
// print validity children
544541
if (mValidities.size())
545542
{
546-
str += indent_str + " Validities:";
547-
str += NEW_LINE;
543+
str += indent_str + " Validities:\n";
548544
}
549545
for (size_t i = 0; i < mValidities.size(); i++)
550546
{
551547
Validator* validator = mValidities[i];
552548
validator->ToLongString(str, indent + 4);
553549

554-
str += NEW_LINE;
550+
str += "\n";
555551
}
556552
// print menu children
557553
for (size_t i = 0; i < mSubMenus.size(); i++)
558554
{
559555
Menu* submenu = mSubMenus[i];
560556
submenu->ToLongString(str, indent + 2);
561557

562-
str += NEW_LINE;
558+
str += "\n";
563559
}
564560

565561
str += indent_str + "}";

src/core/Validator.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,6 @@ namespace shellanything
13231323

13241324
void Validator::ToLongString(std::string& str, int indent) const
13251325
{
1326-
static const char* NEW_LINE = ra::environment::GetLineSeparator();
13271326
const std::string indent_str = std::string(indent, ' ');
13281327

13291328
const std::string short_string = ToShortString();

src/shellextension/CContextMenu.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,23 @@ void CContextMenu::BuildTopMenuTree(HMENU hMenu)
321321
}
322322
}
323323

324+
void CContextMenu::PrintVerboseMenuStructure() const
325+
{
326+
if (!shellanything::LoggerHelper::IsVerboseLoggingEnabled())
327+
return;
328+
329+
SA_DECLARE_SCOPE_LOGGER_ARGS(sli);
330+
sli.verbose = true;
331+
sli.instance = this;
332+
shellanything::ScopeLogger logger(&sli);
333+
334+
shellanything::ConfigManager& cmgr = shellanything::ConfigManager::GetInstance();
335+
336+
std::string menu_tree;
337+
cmgr.ToLongString(menu_tree, 0);
338+
SA_VERBOSE_LOG(INFO) << __FUNCTION__ "(), Menu tree:\n" << menu_tree.c_str();
339+
}
340+
324341
CContextMenu::CContextMenu()
325342
{
326343
SA_VERBOSE_LOG(INFO) << __FUNCTION__ "(), new instance " << ToHexString(this);
@@ -421,13 +438,8 @@ HRESULT STDMETHODCALLTYPE CContextMenu::QueryContextMenu(HMENU hMenu, UINT menu_
421438
UINT num_menu_items = next_command_id - first_command_id;
422439
SA_VERBOSE_LOG(INFO) << __FUNCTION__ "(), statistics: first_command_id=" << first_command_id << " menu_last_command_id=" << menu_last_command_id << " next_command_id=" << next_command_id << " num_menu_items=" << num_menu_items << ".\n";
423440

424-
//debug the constructed menu tree
425-
if (shellanything::LoggerHelper::IsVerboseLoggingEnabled())
426-
{
427-
std::string menu_tree;
428-
cmgr.ToLongString(menu_tree, 0);
429-
SA_VERBOSE_LOG(INFO) << __FUNCTION__ "(), Menu tree:\n" << menu_tree.c_str();
430-
}
441+
//debug the constructed menu tree, if required
442+
PrintVerboseMenuStructure();
431443

432444
HRESULT hr = MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, num_menu_items);
433445
return hr;

src/shellextension/CContextMenu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class ATL_NO_VTABLE CContextMenu :
8181
private:
8282
void BuildTopMenuTree(HMENU hMenu);
8383
void BuildSubMenuTree(HMENU hMenu, shellanything::Menu* menu, UINT& insert_pos, bool& next_menu_is_column);
84+
void PrintVerboseMenuStructure() const;
8485

8586
CCriticalSection m_CS; //protects class members
8687
ULONG m_refCount;

src/tests/TestIObject.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "TestIObject.h"
2626
#include "ConfigManager.h"
2727
#include "ConfigFile.h"
28+
#include "LoggerHelper.h"
2829

2930
#include "rapidassist/strings.h"
3031
#include "rapidassist/testing.h"
@@ -281,7 +282,6 @@ namespace shellanything
281282
//Get actual
282283
std::string longstring_actual;
283284
cmgr.ToLongString(longstring_actual, 0);
284-
ra::strings::Replace(longstring_actual, "\r\n", "\n"); // Replace CRLF by LF to display properly in GoogleTest diff view
285285

286286
//Get expected long string from file
287287
std::string expected_source_path = std::string("test_files") + path_separator + test_name + ".expected.txt";
@@ -300,6 +300,9 @@ namespace shellanything
300300
//Do the actual comparison
301301
ASSERT_EQ(longstring_expected, longstring_actual);
302302

303+
// Add to logs to show how it prints
304+
SA_LOG(INFO) << __FUNCTION__ << "() Menu Tree:\n" << longstring_actual;
305+
303306
//Cleanup
304307
ASSERT_TRUE(workspace.Cleanup()) << "Failed deleting workspace directory '" << workspace.GetBaseDirectory() << "'.";
305308
}

0 commit comments

Comments
 (0)