Example #1
0
void OptionsCtrl::setDateTimeStr(HANDLE hDateTime, const ext::string& strDateTime)
{
	if (strDateTime.empty())
		setDateTimeNone(hDateTime);
	else
		setDateTime(hDateTime, utils::parseDate(strDateTime));
}
Example #2
0
void SettingsTree::fromString(const ext::string& config)
{
	m_Keys.clear();

	ext::string::size_type i = 0;
	ext::string curKey;

	while (i < config.length()) {
		if (config[i] == '{') {
			++i;

			ValueMap& vals = m_Keys[curKey];

			ext::string curSetting;
			ext::string curVal;

			while (i < config.length() && config[i] != '}') {
				if (config[i] == ':') {
					curSetting = curVal;
					curVal = _T("");
				}
				else if (config[i] == ';') {
					vals[curSetting] = curVal;

					curSetting = _T("");
					curVal = _T("");
				}
				else if (config[i] == '\\') {
					++i;
					curVal += config[i];
				}
				else curVal += config[i];

				++i;
			}

			curKey = _T("");
		}
		else curKey += config[i];

		++i;
	}

	setKey(_T(""));
}
ext::string OptionsCtrlImpl::DateTime::getDTFormatString(const ext::string& strFormat)
{
	ext::string strOut, strPart;

	for (int i = 0; i < strFormat.length(); ++i) {
		if (strFormat[i] == '%' && i < strFormat.length() - 1) {
			++i;

			bool bSharp = (strFormat[i] == '#');
			ext::string strCode;

			if (bSharp && i < strFormat.length() - 1)
				++i;

			switch (strFormat[i]) {
			case 'a':
				strCode = L"ddd";
				break;

			case 'A':
				strCode = L"dddd";
				break;

			case 'b':
				strCode = L"MMM";
				break;

			case 'B':
				strCode = L"MMMM";
				break;

			case 'd':
				strCode = bSharp ? L"d" : L"dd";
				break;

			case 'H':
				strCode = bSharp ? L"H" : L"HH";
				break;

			case 'I':
				strCode = bSharp ? L"h" : L"hh";
				break;

			case 'm':
				strCode = bSharp ? L"M" : L"MM";
				break;

			case 'M':
				strCode = bSharp ? L"m" : L"mm";
				break;

			case 'p':
				strCode = L"tt"; // MEMO: seems not to work if current locale is 24-hour
				break;

			case 'y':
				strCode = L"yy";
				break;

			case 'Y':
				strCode = L"yyyy";
				break;

			case '%':
				strPart += L"%";
				break;
			}

			if (!strCode.empty()) {
				if (!strPart.empty()) {
					strOut += L"'";
					strOut += strPart;
					strOut += L"'";
					strPart = L"";
				}

				strOut += strCode;
			}
		}
		else {
			strPart += strFormat[i];

			if (strFormat[i] == '\'')
				strPart += L"'";
		}
	}

	if (!strPart.empty()) {
		strOut += L"'";
		strOut += strPart;
		strOut += L"'";
	}

	return strOut;
}