@ -2,6 +2,7 @@
*
*
* Copyright 2015 - 2016 , Teo Mrnjavac < teo @ kde . org >
* Copyright 2015 - 2016 , Teo Mrnjavac < teo @ kde . org >
* Copyright 2018 , Adriaan de Groot < groot @ kde . org >
* Copyright 2018 , Adriaan de Groot < groot @ kde . org >
* Copyright 2019 , Collabora Ltd < arnaud . ferraris @ collabora . com >
*
*
* Calamares is free software : you can redistribute it and / or modify
* Calamares is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU General Public License as published by
@ -458,6 +459,56 @@ findFS( QString fsName, FileSystem::Type* fsType )
return fsName ;
return fsName ;
}
}
double
parseSizeString ( const QString & sizeString , SizeUnit * unit )
{
double value ;
bool ok ;
QString valueString ;
QString unitString ;
QRegExp rx ( " [KkMmGg%] " ) ;
int pos = rx . indexIn ( sizeString ) ;
if ( pos > 0 )
{
valueString = sizeString . mid ( 0 , pos ) ;
unitString = sizeString . mid ( pos ) ;
}
else
valueString = sizeString ;
value = valueString . toDouble ( & ok ) ;
if ( ! ok )
{
/*
* In case the conversion fails , a size of 100 % allows a few cases to pass
* anyway ( e . g . when it is the last partition of the layout )
*/
* unit = SizeUnit : : Percent ;
return 100.0 L ;
}
if ( unitString . length ( ) > 0 )
{
if ( unitString . at ( 0 ) = = ' % ' )
* unit = SizeUnit : : Percent ;
else if ( unitString . at ( 0 ) . toUpper ( ) = = ' K ' )
* unit = SizeUnit : : KiB ;
else if ( unitString . at ( 0 ) . toUpper ( ) = = ' M ' )
* unit = SizeUnit : : MiB ;
else if ( unitString . at ( 0 ) . toUpper ( ) = = ' G ' )
* unit = SizeUnit : : GiB ;
else
* unit = SizeUnit : : Byte ;
}
else
{
* unit = SizeUnit : : Byte ;
}
return value ;
}
} // nmamespace PartUtils
} // nmamespace PartUtils
/* Implementation of methods for FstabEntry, from OsproberEntry.h */
/* Implementation of methods for FstabEntry, from OsproberEntry.h */