Added GetNumInput() and sHint argument to GetInput

git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@209 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
prozacx
2005-04-30 11:02:10 +00:00
parent 0013ab2c0c
commit 3abf42228d
2 changed files with 40 additions and 5 deletions
+38 -4
View File
@@ -260,13 +260,12 @@ bool CUtils::GetBoolInput(const string& sPrompt, bool bDefault) {
bool CUtils::GetBoolInput(const string& sPrompt, bool *pbDefault) {
string sRet, sDefault;
string sExtra = " (yes/no)";
if (pbDefault) {
sDefault = (*pbDefault) ? "yes" : "no";
}
GetInput(sPrompt + sExtra, sRet, sDefault);
GetInput(sPrompt, sRet, sDefault, "yes/no");
if (strcasecmp(sRet.c_str(), "yes") == 0) {
return true;
@@ -277,8 +276,43 @@ bool CUtils::GetBoolInput(const string& sPrompt, bool *pbDefault) {
return GetBoolInput(sPrompt, pbDefault);
}
bool CUtils::GetInput(const string& sPrompt, string& sRet, const string& sDefault) {
string sExtra = (!sDefault.empty()) ? (" [" + sDefault + "]") : "";
bool CUtils::GetNumInput(const string& sPrompt, unsigned int& uRet, unsigned int uMin, unsigned int uMax, unsigned int uDefault) {
if (uMin > uMax) {
return false;
}
string sDefault = (uDefault != (unsigned int) ~0) ? CUtils::ToString(uDefault) : "";
string sNum, sHint;
if (uMax != (unsigned int) ~0) {
sHint = CUtils::ToString(uMin) + " to " + CUtils::ToString(uMax);
} else if (uMin > 0) {
sHint = CUtils::ToString(uMin) + " and up";
}
while (true) {
GetInput(sPrompt, sNum, sDefault, sHint);
if (sNum.empty()) {
return false;
}
uRet = atoi(sNum.c_str());
if ((uRet >= uMin && uRet <= uMax)) {
break;
}
CUtils::PrintError("Number must be " + sHint);
}
return true;
}
bool CUtils::GetInput(const string& sPrompt, string& sRet, const string& sDefault, const string& sHint) {
string sExtra;
sExtra += (!sHint.empty()) ? (" (" + sHint + ")") : "";
sExtra += (!sDefault.empty()) ? (" [" + sDefault + "]") : "";
PrintPrompt(sPrompt + sExtra);
char szBuf[1024];
memset(szBuf, 0, 1024);