Move StripTrailingZeros to kicad_string.h
This commit is contained in:
parent
e928b2d8fd
commit
133b011124
|
@ -36,6 +36,7 @@
|
||||||
|
|
||||||
#include <base_units.h>
|
#include <base_units.h>
|
||||||
#include <common.h>
|
#include <common.h>
|
||||||
|
#include <kicad_string.h>
|
||||||
#include <math/util.h> // for KiROUND
|
#include <math/util.h> // for KiROUND
|
||||||
#include <macros.h>
|
#include <macros.h>
|
||||||
#include <title_block.h>
|
#include <title_block.h>
|
||||||
|
@ -205,31 +206,6 @@ wxString MessageTextFromValue( EDA_UNITS aUnits, double aValue, bool aAddUnitLab
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Remove trailing 0 from a string containing a converted float number.
|
|
||||||
* the trailing 0 are removed if the mantissa has more
|
|
||||||
* than aTrailingZeroAllowed digits and some trailing 0
|
|
||||||
*/
|
|
||||||
void StripTrailingZeros( wxString& aStringValue, unsigned aTrailingZeroAllowed )
|
|
||||||
{
|
|
||||||
struct lconv * lc = localeconv();
|
|
||||||
char sep = lc->decimal_point[0];
|
|
||||||
unsigned sep_pos = aStringValue.Find( sep );
|
|
||||||
|
|
||||||
if( sep_pos > 0 )
|
|
||||||
{
|
|
||||||
// We want to keep at least aTrailingZeroAllowed digits after the separator
|
|
||||||
unsigned min_len = sep_pos + aTrailingZeroAllowed + 1;
|
|
||||||
|
|
||||||
while( aStringValue.Len() > min_len )
|
|
||||||
{
|
|
||||||
if( aStringValue.Last() == '0' )
|
|
||||||
aStringValue.RemoveLast();
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Convert a value to a string using double notation.
|
/* Convert a value to a string using double notation.
|
||||||
* For readability, the mantissa has 3 or more digits,
|
* For readability, the mantissa has 3 or more digits,
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
* @brief Some useful functions to handle strings.
|
* @brief Some useful functions to handle strings.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <clocale>
|
||||||
#include <macros.h>
|
#include <macros.h>
|
||||||
#include <richio.h> // StrPrintf
|
#include <richio.h> // StrPrintf
|
||||||
#include <kicad_string.h>
|
#include <kicad_string.h>
|
||||||
|
@ -813,3 +814,25 @@ void wxStringSplit( const wxString& aText, wxArrayString& aStrings, wxChar aSpli
|
||||||
aStrings.Add( tmp );
|
aStrings.Add( tmp );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void StripTrailingZeros( wxString& aStringValue, unsigned aTrailingZeroAllowed )
|
||||||
|
{
|
||||||
|
struct lconv* lc = localeconv();
|
||||||
|
char sep = lc->decimal_point[0];
|
||||||
|
unsigned sep_pos = aStringValue.Find( sep );
|
||||||
|
|
||||||
|
if( sep_pos > 0 )
|
||||||
|
{
|
||||||
|
// We want to keep at least aTrailingZeroAllowed digits after the separator
|
||||||
|
unsigned min_len = sep_pos + aTrailingZeroAllowed + 1;
|
||||||
|
|
||||||
|
while( aStringValue.Len() > min_len )
|
||||||
|
{
|
||||||
|
if( aStringValue.Last() == '0' )
|
||||||
|
aStringValue.RemoveLast();
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -74,15 +74,6 @@ inline int Mils2mm( double x ) { return KiROUND( x * 25.4 / 1000. ); }
|
||||||
*/
|
*/
|
||||||
std::string Double2Str( double aValue );
|
std::string Double2Str( double aValue );
|
||||||
|
|
||||||
/**
|
|
||||||
* Function StripTrailingZeros
|
|
||||||
* Remove trailing 0 from a string containing a converted float number.
|
|
||||||
* The trailing 0 are removed if the mantissa has more
|
|
||||||
* than aTrailingZeroAllowed digits and some trailing 0
|
|
||||||
*/
|
|
||||||
void StripTrailingZeros( wxString& aStringValue, unsigned aTrailingZeroAllowed = 1 );
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function To_User_Unit
|
* Function To_User_Unit
|
||||||
* convert \a aValue in internal units to the appropriate user units defined by \a aUnit.
|
* convert \a aValue in internal units to the appropriate user units defined by \a aUnit.
|
||||||
|
|
|
@ -310,5 +310,12 @@ inline void AccumulateDescription( wxString& aDesc, const wxString& aItem )
|
||||||
*/
|
*/
|
||||||
void wxStringSplit( const wxString& aText, wxArrayString& aStrings, wxChar aSplitter );
|
void wxStringSplit( const wxString& aText, wxArrayString& aStrings, wxChar aSplitter );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function StripTrailingZeros
|
||||||
|
* Remove trailing 0 from a string containing a converted float number.
|
||||||
|
* The trailing 0 are removed if the mantissa has more
|
||||||
|
* than aTrailingZeroAllowed digits and some trailing 0
|
||||||
|
*/
|
||||||
|
void StripTrailingZeros( wxString& aStringValue, unsigned aTrailingZeroAllowed = 1 );
|
||||||
|
|
||||||
#endif // KICAD_STRING_H_
|
#endif // KICAD_STRING_H_
|
||||||
|
|
Loading…
Reference in New Issue