4bf1293ee88570229c963a6f4cfcf5aa7ad6af576b9ed977002bd062d74b7d62562b6d0f8bf9f59d9836cf033f8a208f89edfbd5cf28044b7bd5ffa36eb2ae 1019 B

12345678910111213141516171819202122232425262728293031
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. /**
  6. * Returns:
  7. * - -1 => the line consists of whitespace
  8. * - otherwise => the indent level is returned value
  9. */
  10. export function computeIndentLevel(line, tabSize) {
  11. let indent = 0;
  12. let i = 0;
  13. const len = line.length;
  14. while (i < len) {
  15. const chCode = line.charCodeAt(i);
  16. if (chCode === 32 /* CharCode.Space */) {
  17. indent++;
  18. }
  19. else if (chCode === 9 /* CharCode.Tab */) {
  20. indent = indent - indent % tabSize + tabSize;
  21. }
  22. else {
  23. break;
  24. }
  25. i++;
  26. }
  27. if (i === len) {
  28. return -1; // line only consists of whitespace
  29. }
  30. return indent;
  31. }