コード例 #1
0
ファイル: kobject.cpp プロジェクト: jonnymind/kroll
	void KObject::GetStringList(const char *name, std::vector<std::string> &list)
	{
		SharedValue prop = this->Get(name);
		if(!prop->IsUndefined() && prop->IsList())
		{
			SharedKList values = prop->ToList();
			if (values->Size() > 0)
			{
				for (unsigned int c = 0; c < values->Size(); c++)
				{
					SharedValue v = values->At(c);
					if (v->IsString())
					{
						const char *s = v->ToString();
						list.push_back(s);
					}
				}
			}
		}
	}
コード例 #2
0
ファイル: ruby_utils.cpp プロジェクト: maccman/kroll
	static VALUE RubyKListEach(VALUE self)
	{
		SharedValue* dval = NULL;
		Data_Get_Struct(self, SharedValue, dval);
		SharedKList list = (*dval)->ToList();

		if (list.isNull() || !rb_block_given_p())
			return Qnil;

		for (unsigned int i = 0; i < list->Size(); i++)
		{
			VALUE rubyValue = RubyUtils::ToRubyValue(list->At(i));
			rb_yield(rubyValue);
		}
		return self;
	}
コード例 #3
0
ファイル: ruby_utils.cpp プロジェクト: maccman/kroll
	static VALUE RubyKListLength(int argc, VALUE *argv, VALUE self)
	{
		SharedValue* dval = NULL;
		Data_Get_Struct(self, SharedValue, dval);
		SharedKList klist = (*dval)->ToList();

		// TODO: We should raise an exception instead
		if (klist.isNull())
			return Qnil;

		if (argc > 0)
		{
			rb_raise(rb_eNoMethodError, "wrong number of arguments (%d for 0)", argc);
			return Qnil;
		}
		else
		{
			return INT2NUM(klist->Size());
		}
	}
コード例 #4
0
ファイル: user_window.cpp プロジェクト: pctj101/titanium
void UserWindow::ReadChooserDialogObject(
	SharedKObject o,
	bool& multiple,
	std::string& title,
	std::string& path,
	std::string& defaultName,
	std::vector<std::string>& types,
	std::string& typesDescription)

{
	// Pass in a set of properties for chooser dialogs like this:
	// var selected = Titanium.UI.OpenFileChooserDialog(callback,
	// {
	//    multiple:true,
	//    title: "Select file to delete...",
	//    defaultFile: "autoexec.bat",
	//    path: "C:\"
	//    types:['js','html']
	// });
	multiple = o->GetBool("multiple", true);
	title = o->GetString("title", title);
	path = o->GetString("path", path);
	defaultName = o->GetString("defaultName", defaultName);

	SharedKList listTypes = new StaticBoundList();
	listTypes = o->GetList("types", listTypes);
	for (size_t i = 0; i < listTypes->Size(); i++)
	{
		if (listTypes->At(i)->IsString())
		{
			types.push_back(listTypes->At(i)->ToString());
			std::cout << "Found " << listTypes->At(i)->ToString() << std::endl;
		}
	}
	typesDescription = o->GetString("typesDescription", defaultName);

}
コード例 #5
0
ファイル: ruby_utils.cpp プロジェクト: maccman/kroll
	static VALUE RubyKListGetElt(int argc, VALUE *argv, VALUE self)
	{
		SharedValue* dval = NULL;
		Data_Get_Struct(self, SharedValue, dval);
		SharedKList list = (*dval)->ToList();

		// TODO: We should raise an exception instead
		if (list.isNull() || argc < 1)
			return Qnil;

		int idx = -1;
		if (TYPE(argv[0]) != T_FIXNUM || ((idx = NUM2INT(argv[0])) < 0))
			return Qnil;

		if (idx >= 0 && idx < (int) list->Size())
		{
			SharedValue v = list->At(idx);
			return RubyUtils::ToRubyValue(v);
		}
		else
		{
			return Qnil;
		}
	}
コード例 #6
0
ファイル: blob.cpp プロジェクト: jonnymind/kroll
	void Blob::Split(const ValueList& args, SharedValue result)
	{
		// This method now follows the spec located at:
		// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String/split
		// Except support for regular expressions
		args.VerifyException("Blob.split", "?s,i");

		SharedKList list = new StaticBoundList();
		result->SetList(list);

		std::string target = "";
		if (this->length > 0)
		{
			target = this->buffer;
		}
		else
		{
			list->Append(Value::NewString(target));
			return;
		}

		if (args.size() <= 0)
		{
			list->Append(Value::NewString(target));
			return;
		}

		std::string separator = args.GetString(0);
		int limit = INT_MAX;
		if (args.size() > 1)
		{
			limit = args.GetInt(1);
		}

		// We could use Poco's tokenizer here, but it doesn't split strings
		// like "abc,def,," -> ['abc', 'def', '', ''] correctly. It produces
		// ['abc', 'def', ''] which is a different behavior than the JS split.
		// So we roll our own for now -- it's not very efficient right now, but
		// it should be correct.
		size_t next = target.find(separator);
		while (target.size() > 0 && next != std::string::npos)
		{
			std::string token;
			if (separator.size() == 0)
			{
				token = target.substr(0, 1);
			}
			else
			{
				token = target.substr(0, next);
			}
			target = target.substr(next + 1);
			next = target.find(separator);

			if ((int) list->Size() >= limit)
				return;

			list->Append(Value::NewString(token));
		}

		if ((int) list->Size() < limit && separator.size() != 0)
			list->Append(Value::NewString(target));
	}