summaryrefslogtreecommitdiff
path: root/support.cc
diff options
context:
space:
mode:
authorsrs5694 <srs5694@users.sourceforge.net>2010-08-22 22:44:42 -0400
committersrs5694 <srs5694@users.sourceforge.net>2010-08-22 22:44:42 -0400
commit9ddc14bb9b154518e2b8384d3f4571cf657c7920 (patch)
treef921f4c8287c9e4270bbd47e5a60cb536e51b3f9 /support.cc
parentf9312b0ca9af86f280adad36eb660f6e74720c2c (diff)
downloadsgdisk-9ddc14bb9b154518e2b8384d3f4571cf657c7920.tar.gz
Revisions for 0.6.10 release
Diffstat (limited to 'support.cc')
-rw-r--r--support.cc43
1 files changed, 31 insertions, 12 deletions
diff --git a/support.cc b/support.cc
index 11c6200..1711209 100644
--- a/support.cc
+++ b/support.cc
@@ -244,16 +244,35 @@ void ReverseBytes(void* theValue, int numBytes) {
} // if
} // ReverseBytes()
-// Compute (2 ^ value). Given the return type, value must be 63 or less.
-// Used in some bit-fiddling functions
-uint64_t PowerOf2(uint32_t value) {
- uint64_t retval = 1;
- uint32_t i;
-
- if (value < 64) {
- for (i = 0; i < value; i++) {
- retval *= 2;
- } // for
- } else retval = 0;
+// Extract integer data from argument string, which should be colon-delimited
+uint64_t GetInt(const string & argument, int itemNum) {
+ int startPos = -1, endPos = -1;
+ uint64_t retval = 0;
+
+ while (itemNum-- > 0) {
+ startPos = endPos + 1;
+ endPos = argument.find(':', startPos);
+ }
+ if (endPos == (int) string::npos)
+ endPos = argument.length();
+ endPos--;
+
+ istringstream inString(argument.substr(startPos, endPos - startPos + 1));
+ inString >> retval;
return retval;
-} // PowerOf2()
+} // GetInt()
+
+// Extract string data from argument string, which should be colon-delimited
+string GetString(const string & argument, int itemNum) {
+ int startPos = -1, endPos = -1;
+
+ while (itemNum-- > 0) {
+ startPos = endPos + 1;
+ endPos = argument.find(':', startPos);
+ }
+ if (endPos == (int) string::npos)
+ endPos = argument.length();
+ endPos--;
+
+ return argument.substr(startPos, endPos - startPos + 1);
+} // GetString() \ No newline at end of file