aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorlloyd <lloyd@randombit.net>2009-03-31 03:38:10 +0000
committerlloyd <lloyd@randombit.net>2009-03-31 03:38:10 +0000
commit58bcc7e7c08badf1a11735129704b1d38fa8abad (patch)
treeae37dd8fccb7814777ec0f0037c20d12ddda0093 /src/utils
parent1309862b2d60622129ba5f3fdaadc8b763d842a8 (diff)
Add a new version of SCAN_Name::arg that returns a default value if the
param isn't set.
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/scan_name.cpp9
-rw-r--r--src/utils/scan_name.h10
2 files changed, 17 insertions, 2 deletions
diff --git a/src/utils/scan_name.cpp b/src/utils/scan_name.cpp
index b867a0462..3425425e2 100644
--- a/src/utils/scan_name.cpp
+++ b/src/utils/scan_name.cpp
@@ -54,11 +54,18 @@ SCAN_Name::SCAN_Name(const std::string& algo_spec)
std::string SCAN_Name::arg(u32bit i) const
{
- if(i > arg_count())
+ if(i >= arg_count())
throw std::range_error("SCAN_Name::argument");
return name[i+1];
}
+std::string SCAN_Name::arg(u32bit i, const std::string& def_value) const
+ {
+ if(i >= arg_count())
+ return def_value;
+ return name[i+1];
+ }
+
u32bit SCAN_Name::arg_as_u32bit(u32bit i, u32bit def_value) const
{
if(i >= arg_count())
diff --git a/src/utils/scan_name.h b/src/utils/scan_name.h
index 5607599dc..9e7af40d6 100644
--- a/src/utils/scan_name.h
+++ b/src/utils/scan_name.h
@@ -56,7 +56,15 @@ class SCAN_Name
/**
@param i which argument
- @return the ith argument as a u32bit, or a default value
+ @param def_value the default value
+ @return the ith argument or the default value
+ */
+ std::string arg(u32bit i, const std::string& def_value) const;
+
+ /**
+ @param i which argument
+ @param def_value the default value
+ @return the ith argument as a u32bit, or the default value
*/
u32bit arg_as_u32bit(u32bit i, u32bit def_value) const;
private: