Repository: microsoft/terminal
File: src/cascadia/TerminalControl/TermControl.cpp (C++)

Code before:
                        }
                    }

                    const auto quotesNeeded = isWSL || fullPath.find(L' ') != std::wstring::npos;
                    const auto quotesChar = isWSL ? L'\'' : L'"';

                    // Append fullPath and also wrap it in quotes if needed
                    if (quotesNeeded)
                    {
                        allPathsString.push_back(quotesChar);
                    }
                    if (isWSL)
                    {
                        // Fix quoted path for WSL
                        // Single quote is allowed on the Win32 subsystem and must be processed
                        // when we are quoting the path with single quotes (on WSL).
                        // Note that we assume that all paths are quoted for WSL.
                        size_t pos;
                        auto fullPathView = std::wstring_view(fullPath);
                        while ((pos = fullPathView.find(L"'")) != std::wstring_view::npos)
                        {
                            allPathsString.append(fullPathView.begin(), fullPathView.begin() + pos);
                            allPathsString.append(L"'\"'\"'");
                            fullPathView.remove_prefix(pos + 1);
                        }
                        allPathsString.append(fullPathView);
                    }
                    else
                    {
                        allPathsString.append(fullPath);
                    }
                    if (quotesNeeded)
                    {
                        allPathsString.push_back(quotesChar);
                    }
                }

                _pasteTextWithBroadcast(winrt::hstring{ allPathsString });
            }
        }
    }

    // Method Description:
    // - Paste this text, and raise a StringSent, to potentially broadcast this
    //   text to other controls in the app. For certain interactions, like
    //   drag/dropping a file, we want to act like we "pasted" the text (even if
    //   the text didn't come from the clipboard). This lets those interactions
    //   broadcast as well.
    void TermControl::_pasteTextWithBroadcast(const winrt::hstring& text)
    {
        // only broadcast if there's an actual listener. Saves the overhead of some object creation.

Review comment (suggestion):
There are two things that I believe must be changed:
* If `quotesNeeded` is false, then we must only insert `"'"` and not `'"'"'`, right? After all, there are no surrounding quotes.
* `find()` has an overload for single character searches that is much faster. So instead of `L"'"` I think we should use `L'\''`.

Afterwards, I think we can merge this. There's another thing though that's less important:
* As per our usual code style it would be better to write this:
  ```cpp
  std::wstring_view fullPathView{ fullPath };
  ```

Code after:
                    const auto translationStyle{ _core.Settings().PathTranslationStyle() };
                    _translatePathInPlace(fullPath, translationStyle);

                    // All translated paths get quotes, and all strings spaces get quotes; all translated paths get single quotes
                    const auto quotesNeeded = translationStyle != PathTranslationStyle::None || fullPath.find(L' ') != std::wstring::npos;
                    const auto quotesChar = translationStyle != PathTranslationStyle::None ? L'\'' : L'"';

                    // Append fullPath and also wrap it in quotes if needed
                    if (quotesNeeded)
                    {
                        allPathsString.push_back(quotesChar);
                    }
                    allPathsString.append(fullPath);
                    if (quotesNeeded)
                    {
                        allPathsString.push_back(quotesChar);
                    }
                }

                _pasteTextWithBroadcast(winrt::hstring{ allPathsString });
            }
        }
    }

    // Method Description:
    // - Paste this text, and raise a StringSent, to potentially broadcast this
    //   text to other controls in the app. For certain interactions, like
    //   drag/dropping a file, we want to act like we "pasted" the text (even if
    //   the text didn't come from the clipboard). This lets those interactions
    //   broadcast as well.
    void TermControl::_pasteTextWithBroadcast(const winrt::hstring& text)
    {
        // only broadcast if there's an actual listener. Saves the overhead of some object creation.
        if (StringSent)
        {
            StringSent.raise(*this, winrt::make<StringSentEventArgs>(text));
        }
        _core.PasteText(text);
    }

    // Method Description:
    // - Handle the DragOver event. We'll signal that the drag operation we
    //   support is the "copy" operation, and we'll also customize the
    //   appearance of the drag-drop UI, by removing the preview and setting a
    //   custom caption. For more information, see
    //   https://docs.microsoft.com/en-us/windows/uwp/design/input/drag-and-drop#customize-the-ui
    // Arguments:
    // - e: The DragEventArgs from the DragOver event
    // Return Value:
    // - <none>
    void TermControl::_DragOverHandler(const Windows::Foundation::IInspectable& /*sender*/,