[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] /srv/bzr/gnash/trunk r12155: parse properties of array an
From: |
Rob Savoye |
Subject: |
[Gnash-commit] /srv/bzr/gnash/trunk r12155: parse properties of array and object, building a vector of NPVariant pointers. |
Date: |
Wed, 14 Apr 2010 21:46:50 -0600 |
User-agent: |
Bazaar (2.0.3) |
------------------------------------------------------------
revno: 12155
committer: Rob Savoye <address@hidden>
branch nick: trunk
timestamp: Wed 2010-04-14 21:46:50 -0600
message:
parse properties of array and object, building a vector of NPVariant pointers.
modified:
plugin/npapi/external.cpp
plugin/npapi/external.h
plugin/npapi/test.cpp
=== modified file 'plugin/npapi/external.cpp'
--- a/plugin/npapi/external.cpp 2010-04-15 01:22:09 +0000
+++ b/plugin/npapi/external.cpp 2010-04-15 03:46:50 +0000
@@ -232,9 +232,29 @@
STRINGN_TO_NPVARIANT(data, length, *value);
} else if (tag == "<array>") {
NPObject *obj = (NPObject *)NPN_MemAlloc(sizeof(NPObject));
+ start = end;
+ end = xml.find("</array");
+ std::string str = xml.substr(start, end-start);
+ std::map<std::string, NPVariant *> props = parseProperties(str);
+ std::map<std::string, NPVariant *>::iterator it;
+ for (it=props.begin(); it != props.end(); ++it) {
+ NPIdentifier id = NPN_GetStringIdentifier(it->first.c_str());
+ NPVariant *value = it->second;
+ NPN_SetProperty(NULL, obj, id, value);
+ }
OBJECT_TO_NPVARIANT(obj, *value);
} else if (tag == "<object>") {
NPObject *obj = (NPObject *)NPN_MemAlloc(sizeof(NPObject));
+ start = end;
+ end = xml.find("</object");
+ std::string str = xml.substr(start, end-start);
+ std::map<std::string, NPVariant *> props = parseProperties(str);
+ std::map<std::string, NPVariant *>::iterator it;
+ for (it=props.begin(); it != props.end(); ++it) {
+ NPIdentifier id = NPN_GetStringIdentifier(it->first.c_str());
+ NPVariant *value = it->second;
+ NPN_SetProperty(NULL, obj, id, value);
+ }
OBJECT_TO_NPVARIANT(obj, *value);
}
}
@@ -274,6 +294,34 @@
return ss.str();
}
+std::map<std::string, NPVariant *>
+ExternalInterface::parseProperties(const std::string &xml)
+{
+ std::map<std::string, NPVariant *> props;
+
+ std::string::size_type start = 0;
+ std::string::size_type end;
+
+ std::string id;
+ start = xml.find(" id=");
+ while (start != std::string::npos) {
+ // Extract the id from the property tag
+ start++;
+ end = xml.find(">", start) - 1;
+ id = xml.substr(start, end-start);
+ id.erase(0, 4);
+
+ // Extract the data
+ start = end + 2;
+ end = xml.find("</property>", start) ;
+ std::string data = xml.substr(start, end-start);
+ props[id] = parseXML(data);
+ start = xml.find(" id=", end);
+ }
+
+ return props;
+}
+
// local Variables:
// mode: C++
// indent-tabs-mode: nil
=== modified file 'plugin/npapi/external.h'
--- a/plugin/npapi/external.h 2010-04-15 00:35:38 +0000
+++ b/plugin/npapi/external.h 2010-04-15 03:46:50 +0000
@@ -54,8 +54,8 @@
std::string makeObject (std::map<std::string, std::string> &args);
NPVariant *parseXML(const std::string &xml);
+ std::map<std::string, NPVariant *> parseProperties(const std::string &xml);
std::string convertNPVariant (NPVariant *npv);
-
};
#endif // GNASH_PLUGIN_EXTERNAL_H
=== modified file 'plugin/npapi/test.cpp'
--- a/plugin/npapi/test.cpp 2010-04-15 01:22:09 +0000
+++ b/plugin/npapi/test.cpp 2010-04-15 03:46:50 +0000
@@ -33,18 +33,8 @@
TestState runtest;
-void* NPN_MemAlloc(uint32_t size)
-{
- void * rv = NULL;
- rv = malloc(size);
- return rv;
-}
-
-void NPN_MemFree(void* ptr)
-{
- free(ptr);
-}
-
+std::map<NPIdentifier, NPVariant *> _properties;
+std::map<NPIdentifier, NPInvokeFunctionPtr> _methods;
int
main(int argc, char *argv[])
@@ -229,6 +219,16 @@
runtest.fail("ExternalInterface::parseXML(void)");
}
+ xml = "<property id=\"0\"><string>foobar</string></property><property
id=\"1\"><number>12.34</number></property><property
id=\"2\"><number>56</number></property>";
+ std::map<std::string, NPVariant *> props = ei.parseProperties(xml);
+ np = props["0"];
+ data = NPVARIANT_TO_STRING(np[0]).UTF8Characters;
+ if ((props.size() == 3) && (data == "foobar")) {
+ runtest.pass("ExternalInterface::parseProperties()");
+ } else {
+ runtest.fail("ExternalInterface::parseProperties()");
+ }
+
xml = "<object><property
id=\"test1\"><string>foobar</string></property><property
id=\"test2\"><number>12.34</number></property><property
id=\"test3\"><number>56</number></property></object>";
np = ei.parseXML(xml);
if (NPVARIANT_IS_OBJECT(*np)) {
@@ -239,14 +239,43 @@
}
+void* NPN_MemAlloc(uint32_t size)
+{
+ void * rv = NULL;
+ rv = malloc(size);
+ return rv;
+}
+
+void NPN_MemFree(void* ptr)
+{
+ free(ptr);
+}
+
// These are just stubs to get the test case to link standalone.
NPIdentifier NPN_GetStringIdentifier(const NPUTF8 *name)
{
}
-bool NPN_SetProperty(NPP npp, NPObject* obj, NPIdentifier propertyName,
- const NPVariant *value)
-{
+bool NPN_SetProperty(NPP npp, NPObject* obj, NPIdentifier name,
+ const NPVariant *value)
+{
+ _properties[name] = const_cast<NPVariant *>(value);
+}
+
+bool NPN_GetProperty(NPP npp, NPObject* obj, NPIdentifier name,
+ const NPVariant *value)
+{
+ return _properties[name];
+}
+
+bool NPN_HasProperty(NPP npp, NPObject* obj, NPIdentifier name,
+ const NPVariant *value)
+{
+ std::map<NPIdentifier, NPVariant *>::iterator it;
+ it = _properties.find(name);
+ if (it != _properties.end()) {
+ return true;
+ }
}
nsPluginInstanceBase *
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] /srv/bzr/gnash/trunk r12155: parse properties of array and object, building a vector of NPVariant pointers.,
Rob Savoye <=