diff options
author | srs5694 <srs5694@users.sourceforge.net> | 2010-08-22 22:44:42 -0400 |
---|---|---|
committer | srs5694 <srs5694@users.sourceforge.net> | 2010-08-22 22:44:42 -0400 |
commit | 9ddc14bb9b154518e2b8384d3f4571cf657c7920 (patch) | |
tree | f921f4c8287c9e4270bbd47e5a60cb536e51b3f9 /support.cc | |
parent | f9312b0ca9af86f280adad36eb660f6e74720c2c (diff) | |
download | sgdisk-9ddc14bb9b154518e2b8384d3f4571cf657c7920.tar.gz |
Revisions for 0.6.10 release
Diffstat (limited to 'support.cc')
-rw-r--r-- | support.cc | 43 |
1 files changed, 31 insertions, 12 deletions
@@ -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 |