Created destructive removeTrailingZeros() method on ZString.
This commit is contained in:
parent
faa794cf6b
commit
bf4ff3fdac
11
ZString.cpp
11
ZString.cpp
@ -544,7 +544,16 @@ namespace coreutils {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
ZString ZString::removeTrailingZeros() {
|
||||
if(length > 2) {
|
||||
while((*(data + length - 1)) == '0')
|
||||
--length;
|
||||
if(*(data + length - 1) == '.')
|
||||
--length;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
void ZString::nextChar() {
|
||||
if(!eod())
|
||||
++cursor;
|
||||
|
@ -423,6 +423,12 @@ namespace coreutils {
|
||||
///
|
||||
|
||||
bool boolValue();
|
||||
|
||||
///
|
||||
///
|
||||
///
|
||||
|
||||
ZString removeTrailingZeros();
|
||||
|
||||
protected:
|
||||
char *data;
|
||||
|
@ -107,5 +107,9 @@ int main(int argc, char **argv) {
|
||||
coreutils::ZString test20(NULL);
|
||||
std::cout << "[" << test20 << "]" << std::endl;
|
||||
std::cout << "Comparisons with null value: " << (test20 == "true") << std::endl;
|
||||
|
||||
coreutils::ZString test21("10.00000000");
|
||||
std::cout << "Trailing Zeros: " << test21.removeTrailingZeros() << std::endl;
|
||||
std::cout << " " << test21 << std::endl;
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user