Eeschema: Add support for leading zeroes when auto-incrementing names (fixes #9831)
This commit is contained in:
parent
37d53a7147
commit
9f568d3658
|
@ -59,7 +59,10 @@ bool IncrementLabelMember( wxString& name, int aIncrement )
|
||||||
|
|
||||||
wxString suffix;
|
wxString suffix;
|
||||||
wxString digits;
|
wxString digits;
|
||||||
int ii = name.Len() - 1;
|
wxString outputFormat;
|
||||||
|
wxString outputNumber;
|
||||||
|
int ii = name.Len() - 1;
|
||||||
|
int dCount = 0;
|
||||||
|
|
||||||
while( ii >= 0 && !wxIsdigit( name.GetChar( ii ) ) )
|
while( ii >= 0 && !wxIsdigit( name.GetChar( ii ) ) )
|
||||||
{
|
{
|
||||||
|
@ -71,6 +74,7 @@ bool IncrementLabelMember( wxString& name, int aIncrement )
|
||||||
{
|
{
|
||||||
digits = name.GetChar( ii ) + digits;
|
digits = name.GetChar( ii ) + digits;
|
||||||
ii--;
|
ii--;
|
||||||
|
dCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( digits.IsEmpty() )
|
if( digits.IsEmpty() )
|
||||||
|
@ -87,7 +91,11 @@ bool IncrementLabelMember( wxString& name, int aIncrement )
|
||||||
if( number > -1 )
|
if( number > -1 )
|
||||||
{
|
{
|
||||||
name.Remove( ii + 1 );
|
name.Remove( ii + 1 );
|
||||||
name << number << suffix;
|
//write out a format string with correct number of leading zeroes
|
||||||
|
outputFormat.Printf( "%%0%dd", dCount );
|
||||||
|
//write out the number using the format string
|
||||||
|
outputNumber.Printf( outputFormat, number );
|
||||||
|
name << outputNumber << suffix;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue