MCPcopy Create free account
hub / github.com/RomanKubiak/ctrlr / getNonexistentChildFile

Method getNonexistentChildFile

JUCE/modules/juce_core/files/juce_File.cpp:603–653  ·  view source on GitHub ↗

==============================================================================

Source from the content-addressed store, hash-verified

601
602//==============================================================================
603File 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
655File File::getNonexistentSibling (const bool putNumbersInBrackets) const
656{

Callers 11

restoreStateMethod · 0.80
writeLuaMethodMethod · 0.80
createTempFileFunction · 0.80
getNonexistentSiblingMethod · 0.80
runTestMethod · 0.80
moveToTrashMethod · 0.80
startRecordingFunction · 0.80
startRecordingMethod · 0.80
imageReceivedMethod · 0.80
saveSchemeMethod · 0.80

Calls 8

endsWithCharMethod · 0.80
lastIndexOfCharMethod · 0.80
containsOnlyMethod · 0.80
getLastCharacterMethod · 0.80
existsMethod · 0.45
trimMethod · 0.45
substringMethod · 0.45
getIntValueMethod · 0.45

Tested by

no test coverage detected