MakeSupport.cpp 973 B

1234567891011121314151617181920212223242526272829303132333435
  1. //===-- MakeSuport.cpp --------------------------------------------------*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #include "clang/Basic/MakeSupport.h"
  9. void clang::quoteMakeTarget(StringRef Target, SmallVectorImpl<char> &Res) {
  10. for (unsigned i = 0, e = Target.size(); i != e; ++i) {
  11. switch (Target[i]) {
  12. case ' ':
  13. case '\t':
  14. // Escape the preceding backslashes
  15. for (int j = i - 1; j >= 0 && Target[j] == '\\'; --j)
  16. Res.push_back('\\');
  17. // Escape the space/tab
  18. Res.push_back('\\');
  19. break;
  20. case '$':
  21. Res.push_back('$');
  22. break;
  23. case '#':
  24. Res.push_back('\\');
  25. break;
  26. default:
  27. break;
  28. }
  29. Res.push_back(Target[i]);
  30. }
  31. }