Beispiel #1
0
bool Facebook::extractConnectionTypeAndId(FacebookRequest *req, MAUtil::String &connectionType, MAUtil::String &id) const
{
	const MAUtil::String path = req->getPath();

	int found = path.findFirstOf('/');
	if(String::npos == found)
	{
		return false;
	}
	id = path.substr(0, found);
	connectionType = path.substr(found+1);

    return (connectionType.size()>0 && id.size()>0);
}
Beispiel #2
0
	void string() {
		MAUtil::String str = "test";
		assert("String::==", str == "test");
		assert("String::!=", str != "fest");
		assert("String::<", !(str < "fest") && (MAUtil::String("fest") < str));
		assert("String::>", !(MAUtil::String("fest") > str) && (str > "fest"));
		assert("String::<=", str <= "test" && str <= "west");
		assert("String::>=", str >= "test" && str >= "fest");
		assert("String::+", (str + "ing") == "testing");
		str+="ing";
		assert("String::+=", str == "testing");
		assert("String::find()", str.find("ing") == 4 && str.find("1") == MAUtil::String::npos);
		str+=" string";
		assert("String::findLastOf()", str.findLastOf('g') == 13 && str.findLastOf('1') == MAUtil::String::npos);
		assert("String::findFirstOf()", str.findFirstOf('g') == 6 && str.findFirstOf('1') == MAUtil::String::npos);
		assert("String::findFirstNotOf()", str.findFirstNotOf('t') == 1 && str.findFirstNotOf('1') == 0);
		str.insert(7, " MAUtil::");
		assert("String::insert(string)", str == "testing MAUtil:: string");

		str.remove(16, 2);
		assert("String::remove()", str == "testing MAUtil::tring");

		str.insert(16, 'S');
		assert("String::insert(char)", str == "testing MAUtil::String");

		assert("String::substr()", str.substr(8, 6) == "MAUtil");

		assert("String::length()", str.length() == 22);

		str.reserve(32);
		assert("String::reserve()", str == "testing MAUtil::String" && str.length() == 22);
		assert("String::capacity()", str.capacity() == 32);

		str.clear();
		assert("String::clear()", str.length() == 0 && str == "");
	}
void SettingsScreen::loadSettings() {
	MAUtil::String filename = getLocalPath() + SETTINGS_FILE_NAME;

	MAHandle file = maFileOpen(filename.c_str(), MA_ACCESS_READ);
	if(file < 0) {
		printf("Error opening file %i\n", file);
		return;
	}

	// Check if the file exists.
	int res = maFileExists(file);
	MAASSERT(res >= 0);
	if(!res) {
		printf("File does not exist.\n");
		maFileClose(file);
		return;
	}

	// Get the file size.
	int size = maFileSize(file);
	printf("Size: %i\n", size);
	MAASSERT(size >= 0);

	// Read the file data.
	static char data[200];
	MAASSERT(size < (int)sizeof(data));
	res = maFileRead(file, data, size);
	MAASSERT(res == 0);

	// Close the file.
	printf("Closing...\n");
	res = maFileClose(file);
	MAASSERT(res == 0);

	printf("Done.\n");

	MAUtil::String contents = data;

	printf("Loaded settings string %s", contents.c_str());

	if (contents.findFirstOf(',', 0) <= 0)
		return;

	int commaPosition = contents.findFirstOf(',', 0);
	MAUtil::String appCode = contents.substr(0, commaPosition);
	mAppCodeBox->setText(appCode);
	printf("app code: %s", appCode.c_str());

	int prevCommaPosition = commaPosition + 1;
	commaPosition = contents.findFirstOf(',', prevCommaPosition);
	MAUtil::String appUniq = contents.substr(prevCommaPosition, commaPosition-prevCommaPosition);
	mAppUniqBox->setText(appUniq);
	printf("app uniq: %s", appUniq.c_str());

	prevCommaPosition = commaPosition + 1;
	commaPosition = contents.findFirstOf(',', prevCommaPosition);
	MAUtil::String appPwd = contents.substr(prevCommaPosition, contents.length() - prevCommaPosition);
	//mAppPwdBox->setText(appPwd);
	printf("app pwd: %s", appPwd.c_str());

	//helper = CBHelper(appCode, appUniq);
	//helper.setPassword(appPwd);
	this->mScreen->initalizeHelper(appCode, appUniq, appPwd);
}