fix on import or paste: target/name "qwerty01" -> "qwerty1"

This commit is contained in:
Garux 2024-02-02 16:00:32 +06:00
parent 70c63edd21
commit 8683d43b7a

View File

@ -26,7 +26,7 @@
#include "string/string.h" #include "string/string.h"
#include "generic/static.h" #include "generic/static.h"
#if 1 #if 0
class Postfix class Postfix
{ {
int m_value; // -1 is special value to handle empty postfix int m_value; // -1 is special value to handle empty postfix
@ -58,30 +58,21 @@ public:
#else #else
class Postfix class Postfix
{ {
std::pair<unsigned int, unsigned int> m_value; int m_value; // -1 is special value to handle empty postfix
int m_minWidth;
public: public:
Postfix( unsigned int number, unsigned int leading_zeros ) Postfix( const char* postfix ) : m_value( string_empty( postfix )? -1 : atoi( postfix ) ),
: m_value( leading_zeros, number ){ m_minWidth( postfix[0] == '0'? string_length( postfix ) : 0 ) {
} }
Postfix( const char* postfix ) int number() const {
: m_value( number_count_leading_zeros( postfix ), atoi( postfix ) ){ return m_value;
} }
unsigned int number() const { void write( char* buffer ) const {
return m_value.second; if( m_value != -1 )
} sprintf( buffer, "%0*i", m_minWidth, m_value );
unsigned int leading_zeros() const {
return m_value.first;
}
void write( char* buffer ){
for ( unsigned int count = 0; count < m_value.first; ++count, ++buffer )
*buffer = '0';
sprintf( buffer, "%u", m_value.second );
} }
Postfix& operator++(){ Postfix& operator++(){
++m_value.second; ++m_value;
if ( m_value.first != 0 && m_value.second % 10 == 0 ) {
--m_value.first;
}
return *this; return *this;
} }
bool operator<( const Postfix& other ) const { bool operator<( const Postfix& other ) const {