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 ) )
70 name.Remove( ii + 1 );
73 outputFormat.Printf( wxS(
"%%0%dld" ), dCount );
76 outputNumber.Printf( outputFormat, number );
77 name << outputNumber << suffix;
87 size_t aRightIndex )
const
92 wxString remaining = aStr;
93 std::vector<std::pair<wxString, STRING_PART_TYPE>> parts;
97 while( goodParts < ( aRightIndex + 1 ) && !remaining.IsEmpty() )
99 static const std::regex integerRegex( R
"(\d+$)" );
102 static const std::regex sameCaseAlphabetRegex( R
"(([a-z]+|[A-Z]+)$)" );
105 static const std::regex skipRegex( R
"([^a-zA-Z0-9]+$)" );
107 std::string remainingStr = remaining.ToStdString();
110 if( std::regex_search( remainingStr, match, integerRegex ) )
113 remaining = remaining.Left( remaining.Len() - match.str().size() );
116 else if( std::regex_search( remainingStr, match, sameCaseAlphabetRegex ) )
119 remaining = remaining.Left( remaining.Len() - match.str().size() );
122 else if( std::regex_search( remainingStr, match, skipRegex ) )
125 remaining = remaining.Left( remaining.Len() - match.str().size() );
135 if( goodParts < aRightIndex + 1 )
139 bool didIncrement =
incrementPart( parts.back().first, parts.back().second, aDelta );
145 wxString result = remaining;
147 for(
auto it = parts.rbegin(); it != parts.rend(); ++it )
158 static const wxString iosqxz =
"IOSQXZ";
160 for(
const wxUniChar& c : aStr )
162 if( iosqxz.Contains( c ) )
177 bool zeroPadded = aPart.StartsWith(
'0' );
178 size_t oldLen = aPart.Len();
180 if( aPart.ToLong( &number ) )
189 aPart.Printf(
"%ld", number );
194 aPart = wxString(
"0", oldLen - aPart.Len() ) + aPart;
205 wxString upper = aPart.Upper();
206 bool wasUpper = aPart == upper;
208 static const wxString alphabetFull =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
209 static const wxString alphaNoIOSQXZ =
"ABCDEFGHJKLMNPRTUVWY";
211 const wxString& alpha =
232 newStr = newStr.Lower();
248 const int radix = aAlphabet.Length();
250 for(
size_t i = 0; i < aStr.Len(); i++ )
252 int alphaIndex = aAlphabet.Find( aStr[i] );
254 if( alphaIndex == wxNOT_FOUND )
257 if( i != aStr.Len() - 1 )
260 index += alphaIndex * pow( radix, aStr.Len() - 1 - i );
268 bool aZeroBasedNonUnitCols )
271 bool firstRound =
true;
272 const int radix = aAlphabet.Length();
276 int modN = aN % radix;
278 if( aZeroBasedNonUnitCols && !firstRound )
281 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",...