コード例 #1
0
ファイル: LuaEngine.cpp プロジェクト: donggx/mobilelua
/**
 * Helper function that escapes a string.
 */
static MAUtil::String EscapeHelper(const MAUtil::String& str)
{
	// The encoded string.
	MAUtil::String result = "";
    char buf[8];

    for (int i = 0; i < str.length(); ++i)
    {
    	char c = str[i];
        if ((48 <= c && c <= 57) ||  // 0-9
            (65 <= c && c <= 90) ||  // a..z
            (97 <= c && c <= 122))   // A..Z
        {
        	result.append(&str[i], 1);
        }
        else
        {
        	result += "%";
            sprintf(buf, "%02X", str[i]);
            result += buf;
        }
    }

    return result;
}
コード例 #2
0
ファイル: FacebookWebView.cpp プロジェクト: Felard/MoSync
/**
	 * Widget override.
	 * Get a widget property as a string, setting also the result code.
	 */
MAUtil::String FacebookWebView::getPropertyString( const MAUtil::String& property ) const
{
	char *buffer = new char[BUFFER_SIZE];

	int result = maWidgetGetProperty(this->getWidgetHandle(), property.c_str(), buffer, BUFFER_SIZE);

	MAUtil::String temp;

	if( result == MAW_RES_INVALID_STRING_BUFFER_SIZE)
	{
		delete []buffer;
		int newBufferSize = 2*BUFFER_SIZE;
		buffer = new char[newBufferSize];
		result = maWidgetGetProperty(this->getWidgetHandle(), property.c_str(), buffer, newBufferSize);
	}

	if( result == RES_OK)
	{
		temp.append(buffer, BUFFER_SIZE);
	}

	delete []buffer;
	return temp;
}
コード例 #3
0
	/**
	 * \brief This function is used for reading the settings from the settings file
	 */
	void SettingsManager::_readSettings()
	{
		char settingsFileContent[Model::BUFF_SIZE];
		MAUtil::String content;

		int fileSize = maFileSize(_settingsFile);

		maFileRead(_settingsFile, settingsFileContent, fileSize);

		content.append(settingsFileContent, strlen(settingsFileContent));

		int offset = 0;
		int position = content.find("|", offset);
		_coin = content.substr(offset, position); //read the coin

		offset = position + 1;
		position = content.find("|", offset);

		int day = MAUtil::stringToInteger(content.substr(offset, position - offset), 10); //read the reset day

		offset = position + 1;
		position = content.find("|", offset);

		MAUtil::String dateString = content.substr(offset, position - offset); //read the dateString

		offset = position + 1;
		position = content.find("|", offset);

		MAUtil::String binaryMask = content.substr(offset, position - offset); //read the binary mask
		offset = position + 1;
		_debtValue = MAUtil::stringToDouble(content.substr(offset, content.length() - offset));

		if(binaryMask ==  "100")
		{
			_showAll = true;
			_showMonthly = false;
			_showFromDate = false;
		}
		else if(binaryMask == "010")
		{
			_showAll = false;
			_showMonthly = true;
			_showFromDate = false;
		}
		else if(binaryMask == "001")
		{
			_showAll = false;
			_showMonthly = false;
			_showFromDate = true;
		}

		if(_showMonthly)
		{
			_date._day = day;

			struct tm * dateTime = new tm;
			split_time(maTime(), dateTime);

			_date._mounth = dateTime->tm_mon + 1;
			_date._year = dateTime->tm_year + 1900;

			delete dateTime;
		}
		else if(_showFromDate)
		{
			offset = 0;
			position = dateString.find("-", offset);

			_date._year = MAUtil::stringToInteger(dateString.substr(offset, position), 10);

			offset = position + 1;
			position = dateString.find("-", offset);

			_date._mounth = MAUtil::stringToInteger(dateString.substr(offset, position - offset), 10);

			offset = position + 1;
			_date._day = MAUtil::stringToInteger(dateString.substr(offset, dateString.length() - offset), 10);
		}
		else if(_showAll)
		{
			_date._day = 1;
			_date._mounth = 1;
			_date._year = 1601;
		}
	}