40 wxString outputFormat;
41 wxString outputNumber;
42 int ii =
name.Len() - 1;
45 while( ii >= 0 && !wxIsdigit(
name.GetChar( ii ) ) )
47 suffix =
name.GetChar( ii ) + suffix;
51 while( ii >= 0 && wxIsdigit(
name.GetChar( ii ) ) )
53 digits =
name.GetChar( ii ) + digits;
58 if( digits.IsEmpty() )
63 if( digits.ToLong( &number ) )
71 name.Remove( ii + 1 );
73 outputFormat.Printf( wxS(
"%%0%dld" ), dCount );
75 outputNumber.Printf( outputFormat, number );
76 name << outputNumber << suffix;
86 size_t aRightIndex )
const
91 wxString remaining = aStr;
92 std::vector<std::pair<wxString, STRING_PART_TYPE>> parts;
96 while( goodParts < ( aRightIndex + 1 ) && !remaining.IsEmpty() )
98 static const std::regex integerRegex( R
"(\d+$)" );
100 static const std::regex sameCaseAlphabetRegex( R
"(([a-z]+|[A-Z]+)$)" );
102 static const std::regex skipRegex( R
"([^a-zA-Z0-9]+$)" );
104 std::string remainingStr = remaining.ToStdString();
106 if( std::regex_search( remainingStr, match, integerRegex ) )
109 remaining = remaining.Left( remaining.Len() - match.str().size() );
112 else if( std::regex_search( remainingStr, match, sameCaseAlphabetRegex ) )
115 remaining = remaining.Left( remaining.Len() - match.str().size() );
118 else if( std::regex_search( remainingStr, match, skipRegex ) )
121 remaining = remaining.Left( remaining.Len() - match.str().size() );
131 if( goodParts < aRightIndex + 1 )
135 bool didIncrement =
incrementPart( parts.back().first, parts.back().second, aDelta );
141 wxString result = remaining;
142 for(
auto it = parts.rbegin(); it != parts.rend(); ++it )
152 static const wxString iosqxz =
"IOSQXZ";
153 for(
const wxUniChar& c : aStr )
155 if( iosqxz.Contains( c ) )
169 bool zeroPadded = aPart.StartsWith(
'0' );
170 size_t oldLen = aPart.Len();
172 if( aPart.ToLong( &number ) )
181 aPart.Printf(
"%ld", number );
186 aPart = wxString(
"0", oldLen - aPart.Len() ) + aPart;
196 wxString upper = aPart.Upper();
197 bool wasUpper = aPart == upper;
199 static const wxString alphabetFull =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
200 static const wxString alphaNoIOSQXZ =
"ABCDEFGHJKLMNPRTUVWY";
202 const wxString& alpha =
223 newStr = newStr.Lower();
239 const int radix = aAlphabet.Length();
241 for(
size_t i = 0; i < aStr.Len(); i++ )
243 int alphaIndex = aAlphabet.Find( aStr[i] );
245 if( alphaIndex == wxNOT_FOUND )
248 if( i != aStr.Len() - 1 )
251 index += alphaIndex * pow( radix, aStr.Len() - 1 - i );
259 bool aZeroBasedNonUnitCols )
262 bool firstRound =
true;
263 const int radix = aAlphabet.Length();
267 int modN = aN % radix;
269 if( aZeroBasedNonUnitCols && !firstRound )
272 itemNum.insert( 0, 1, aAlphabet[modN] );
bool incrementPart(wxString &aPart, STRING_PART_TYPE aType, int aDelta) const
std::optional< wxString > Increment(const wxString &aStr, int aDelta, size_t aRightIndex) const
Increment the n-th part from the right of the given string.
KICOMMON_API int IndexFromAlphabetic(const wxString &aStr, const wxString &aAlphabet)
Attempt to convert a string to an integer, assuming it is an alphabetic string like "A",...
wxString KICOMMON_API AlphabeticFromIndex(size_t aN, const wxString &aAlphabet, bool aZeroBasedNonUnitCols)
Get an alphabetic string like A, B, ... Z, AA, AB, ... ZZ, AAA, ...
static bool containsIOSQXZ(const wxString &aStr)
KICOMMON_API bool IncrementString(wxString &name, int aIncrement)
Generic string incrementer.
KICOMMON_API wxString AlphabeticFromIndex(size_t aN, const wxString &aAlphabet, bool aZeroBasedNonUnitCols)
Get an alphabetic string like A, B, ... Z, AA, AB, ... ZZ, AAA, ...
KICOMMON_API int IndexFromAlphabetic(const wxString &aStr, const wxString &aAlphabet)
Attempt to convert a string to an integer, assuming it is an alphabetic string like "A",...