* unindent a line by a given number of tabsets * by erasing the leading whitespace from the line argument. * * @param line a reference to the line to unindent. * @param unindent the number of tabsets to erase. * @return the number of characters erased. */
| 644 | * @return the number of characters erased. |
| 645 | */ |
| 646 | int ASEnhancer::unindentLine(string& line, int unindent) const |
| 647 | { |
| 648 | size_t whitespace = line.find_first_not_of(" \t"); |
| 649 | |
| 650 | if (whitespace == string::npos) // if line is blank |
| 651 | whitespace = line.length(); // must remove padding, if any |
| 652 | |
| 653 | if (whitespace == 0) |
| 654 | return 0; |
| 655 | |
| 656 | size_t charsToErase; // number of chars to erase |
| 657 | |
| 658 | if (useTabs) // if formatted with tabs |
| 659 | { |
| 660 | charsToErase = unindent; // tabs to erase |
| 661 | if (charsToErase <= whitespace) // if there is enough whitespace |
| 662 | line.erase(0, charsToErase); // erase the tabs |
| 663 | else |
| 664 | charsToErase = 0; |
| 665 | } |
| 666 | else |
| 667 | { |
| 668 | charsToErase = unindent * indentLength; // compute chars to erase |
| 669 | if (charsToErase <= whitespace) // if there is enough whitespace |
| 670 | line.erase(0, charsToErase); // erase the spaces |
| 671 | else |
| 672 | charsToErase = 0; |
| 673 | } |
| 674 | |
| 675 | return charsToErase; |
| 676 | } |
| 677 | |
| 678 | |
| 679 | } // end namespace astyle |