Author: aschnell
Date: Sat Jul 26 15:12:32 2008
New Revision: 49430
URL: http://svn.opensuse.org/viewcvs/yast?rev=49430&view=rev
Log:
- moved some code around
Modified:
trunk/storage/libstorage/src/AppUtil.cc
trunk/storage/libstorage/src/AppUtil.h
trunk/storage/libstorage/src/Storage.cc
trunk/storage/libstorage/src/Volume.cc
Modified: trunk/storage/libstorage/src/AppUtil.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/storage/libstorage/src/AppUtil.cc?rev=49430&r1=49429&r2=49430&view=diff
==============================================================================
--- trunk/storage/libstorage/src/AppUtil.cc (original)
+++ trunk/storage/libstorage/src/AppUtil.cc Sat Jul 26 15:12:32 2008
@@ -10,6 +10,9 @@
#include
#include
+#include <locale>
+#include
+
#include
#include
#include
@@ -595,6 +598,106 @@
return str;
}
+
+int numSuffixes()
+{
+ return 6;
+}
+
+
+string getSuffix(int i, bool classic)
+{
+ switch (i)
+ {
+ case 0:
+ /* Byte abbreviated */
+ return classic ? "B" : _("B");
+
+ case 1:
+ /* KiloByte abbreviated */
+ return classic ? "kB" : _("kB");
+
+ case 2:
+ /* MegaByte abbreviated */
+ return classic ? "MB" : _("MB");
+
+ case 3:
+ /* GigaByte abbreviated */
+ return classic ? "GB" : _("GB");
+
+ case 4:
+ /* TeraByte abbreviated */
+ return classic ? "TB" : _("TB");
+
+ case 5:
+ /* PetaByte abbreviated */
+ return classic ? "PB" : _("PB");
+ }
+
+ return string("error");
+}
+
+
+string byteToHumanString(unsigned long long size, bool classic, int precision,
+ bool omit_zeroes)
+{
+ const locale loc = classic ? locale::classic() : locale();
+
+ double f = (double)(size);
+ int i = 0;
+
+ while (f >= 1024.0 && i + 1 < numSuffixes())
+ {
+ f /= 1024.0;
+ i++;
+ }
+
+ if (omit_zeroes && (f == (unsigned long long)(f)))
+ {
+ precision = 0;
+ }
+
+ ostringstream s;
+ s.imbue(loc);
+ s.setf(ios::fixed);
+ s.precision(precision);
+
+ s << f << ' ' << getSuffix(i, classic);
+
+ return s.str();
+}
+
+
+bool humanStringToByte(const string& str, bool classic, unsigned long long& size)
+{
+ const locale loc = classic ? locale::classic() : locale();
+
+ istringstream s(boost::trim_copy(str, loc));
+ s.imbue(loc);
+
+ double f;
+ string suffix;
+ s >> f >> suffix;
+
+ if (s.fail() || !s.eof() || f < 0.0)
+ return false;
+
+ boost::to_lower(suffix, loc);
+
+ for(int i = 0; i < numSuffixes(); i++)
+ {
+ if (suffix == boost::to_lower_copy(getSuffix(i, classic)))
+ {
+ size = f;
+ return true;
+ }
+
+ f *= 1024.0;
+ }
+
+ return false;
+}
+
bool system_cmd_testmode = false;
const string app_ws = " \t\n";
Modified: trunk/storage/libstorage/src/AppUtil.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/storage/libstorage/src/AppUtil.h?rev=49430&r1=49429&r2=49430&view=diff
==============================================================================
--- trunk/storage/libstorage/src/AppUtil.h (original)
+++ trunk/storage/libstorage/src/AppUtil.h Sat Jul 26 15:12:32 2008
@@ -82,6 +82,11 @@
string sformat(const char* format, ...);
+string byteToHumanString(unsigned long long size, bool classic, int precision,
+ bool omit_zeroes);
+
+bool humanStringToByte(const string& str, bool classic, unsigned long long& size);
+
inline const char* _(const char* msgid)
{
return dgettext("storage", msgid);
Modified: trunk/storage/libstorage/src/Storage.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/storage/libstorage/src/Storage.cc?rev=49430&r1=49429&r2=49430&view=diff
==============================================================================
--- trunk/storage/libstorage/src/Storage.cc (original)
+++ trunk/storage/libstorage/src/Storage.cc Sat Jul 26 15:12:32 2008
@@ -12,13 +12,11 @@
#include
#include
#include
+#include
#include <fstream>
#include <sstream>
#include <iostream>
-#include
-
-#include
#include
#include
@@ -6536,103 +6534,16 @@
}
-static int numSuffixes()
-{
- return 6;
-}
-
-
-static string suffixes(int i, bool classic)
-{
- switch (i)
- {
- case 0:
- /* Byte abbreviated */
- return classic ? "B" : _("B");
-
- case 1:
- /* KiloByte abbreviated */
- return classic ? "kB" : _("kB");
-
- case 2:
- /* MegaByte abbreviated */
- return classic ? "MB" : _("MB");
-
- case 3:
- /* GigaByte abbreviated */
- return classic ? "GB" : _("GB");
-
- case 4:
- /* TeraByte abbreviated */
- return classic ? "TB" : _("TB");
-
- case 5:
- /* PetaByte abbreviated */
- return classic ? "PB" : _("PB");
- }
-
- return string("error");
-}
-
-
string Storage::byteToHumanString(unsigned long long size, bool classic, int precision,
bool omit_zeroes) const
{
- const locale loc = classic ? locale::classic() : locale();
-
- double f = (double)(size);
- int suffix = 0;
-
- while (f >= 1024.0 && suffix + 1 < numSuffixes())
- {
- f /= 1024.0;
- suffix++;
- }
-
- if (omit_zeroes && (f == (unsigned long long)(f)))
- {
- precision = 0;
- }
-
- ostringstream s;
- s.imbue(loc);
- s.setf(ios::fixed);
- s.precision(precision);
-
- s << f << ' ' << suffixes(suffix, classic);
-
- return s.str();
+ return storage::byteToHumanString(size, classic, precision, omit_zeroes);
}
bool Storage::humanStringToByte(const string& str, bool classic, unsigned long long& size) const
{
- const locale loc = classic ? locale::classic() : locale();
-
- istringstream s(boost::trim_copy(str, loc));
- s.imbue(loc);
-
- double f;
- string suffix;
- s >> f >> suffix;
-
- if (s.fail() || !s.eof() || f < 0.0)
- return false;
-
- boost::to_lower(suffix, loc);
-
- for(int i = 0; i < numSuffixes(); i++)
- {
- if (suffix == boost::to_lower_copy(suffixes(i, classic)))
- {
- size = f;
- return true;
- }
-
- f *= 1024.0;
- }
-
- return false;
+ return storage::humanStringToByte(str, classic, size);
}
Modified: trunk/storage/libstorage/src/Volume.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/storage/libstorage/src/Volume.cc?rev=49430&r1=49429&r2=49430&view=diff
==============================================================================
--- trunk/storage/libstorage/src/Volume.cc (original)
+++ trunk/storage/libstorage/src/Volume.cc Sat Jul 26 15:12:32 2008
@@ -2588,7 +2588,7 @@
string Volume::sizeString() const
{
- return cont->getStorage()->byteToHumanString(1024 * size_k, false, 2, false);
+ return byteToHumanString(1024 * size_k, false, 2, false);
}
bool Volume::canUseDevice() const
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org