==============================================================================
| 601 | |
| 602 | //============================================================================== |
| 603 | File File::getNonexistentChildFile (const String& suggestedPrefix, |
| 604 | const String& suffix, |
| 605 | bool putNumbersInBrackets) const |
| 606 | { |
| 607 | auto f = getChildFile (suggestedPrefix + suffix); |
| 608 | |
| 609 | if (f.exists()) |
| 610 | { |
| 611 | int number = 1; |
| 612 | auto prefix = suggestedPrefix; |
| 613 | |
| 614 | // remove any bracketed numbers that may already be on the end.. |
| 615 | if (prefix.trim().endsWithChar (')')) |
| 616 | { |
| 617 | putNumbersInBrackets = true; |
| 618 | |
| 619 | auto openBracks = prefix.lastIndexOfChar ('('); |
| 620 | auto closeBracks = prefix.lastIndexOfChar (')'); |
| 621 | |
| 622 | if (openBracks > 0 |
| 623 | && closeBracks > openBracks |
| 624 | && prefix.substring (openBracks + 1, closeBracks).containsOnly ("0123456789")) |
| 625 | { |
| 626 | number = prefix.substring (openBracks + 1, closeBracks).getIntValue(); |
| 627 | prefix = prefix.substring (0, openBracks); |
| 628 | } |
| 629 | } |
| 630 | |
| 631 | do |
| 632 | { |
| 633 | auto newName = prefix; |
| 634 | |
| 635 | if (putNumbersInBrackets) |
| 636 | { |
| 637 | newName << '(' << ++number << ')'; |
| 638 | } |
| 639 | else |
| 640 | { |
| 641 | if (CharacterFunctions::isDigit (prefix.getLastCharacter())) |
| 642 | newName << '_'; // pad with an underscore if the name already ends in a digit |
| 643 | |
| 644 | newName << ++number; |
| 645 | } |
| 646 | |
| 647 | f = getChildFile (newName + suffix); |
| 648 | |
| 649 | } while (f.exists()); |
| 650 | } |
| 651 | |
| 652 | return f; |
| 653 | } |
| 654 | |
| 655 | File File::getNonexistentSibling (const bool putNumbersInBrackets) const |
| 656 | { |
no test coverage detected