/** * as_ref_string_assign: * @rstr_ptr: (out): a #AsRefString * @rstr: a #AsRefString * * This function unrefs and clears @rstr_ptr if set, then sets @rstr if * non-NULL. If @rstr and @rstr_ptr are the same string the action is ignored. * * This function can ONLY be used when @str is guaranteed to be a * refcounted string and is suitable for use when getting strings from * methods without a fixed API. * * This function is slightly faster than as_ref_string_assign_safe() as no * hash table lookup is done on the @rstr pointer. * * Since: 0.6.6 */ void as_ref_string_assign (AsRefString **rstr_ptr, AsRefString *rstr) { g_return_if_fail (rstr_ptr != NULL); if (*rstr_ptr == rstr) return; if (*rstr_ptr != NULL) { as_ref_string_unref (*rstr_ptr); *rstr_ptr = NULL; } if (rstr != NULL) *rstr_ptr = as_ref_string_ref (rstr); }
/** * as_review_node_parse: * @review: a #AsReview instance. * @node: a #GNode. * @ctx: a #AsNodeContext. * @error: A #GError or %NULL. * * Populates the object from a DOM node. * * Returns: %TRUE for success * * Since: 0.6.1 **/ gboolean as_review_node_parse (AsReview *review, GNode *node, AsNodeContext *ctx, GError **error) { AsReviewPrivate *priv = GET_PRIVATE (review); AsNode *c; const gchar *tmp; gint itmp; itmp = as_node_get_attribute_as_int (node, "rating"); if (itmp != G_MAXINT) as_review_set_rating (review, itmp); tmp = as_node_get_attribute (node, "date"); if (tmp != NULL) { g_autoptr(GDateTime) dt = as_utils_iso8601_to_datetime (tmp); if (dt != NULL) as_review_set_date (review, dt); } tmp = as_node_get_attribute (node, "id"); if (tmp != NULL) as_review_set_id (review, tmp); for (c = node->children; c != NULL; c = c->next) { if (as_node_get_tag (c) == AS_TAG_SUMMARY) { as_review_set_summary (review, as_node_get_data (c)); continue; } if (as_node_get_tag (c) == AS_TAG_PRIORITY) { gint64 prio = g_ascii_strtoll (as_node_get_data (c), NULL, 10); as_review_set_priority (review, (gint) prio); continue; } if (as_node_get_tag (c) == AS_TAG_DESCRIPTION) { g_autoptr(GString) xml = NULL; xml = as_node_to_xml (c->children, AS_NODE_TO_XML_FLAG_INCLUDE_SIBLINGS); as_review_set_description (review, xml->str); continue; } if (as_node_get_tag (c) == AS_TAG_VERSION) { as_review_set_version (review, as_node_get_data (c)); continue; } if (as_node_get_tag (c) == AS_TAG_REVIEWER_ID) { as_review_set_reviewer_id (review, as_node_get_data (c)); continue; } if (as_node_get_tag (c) == AS_TAG_REVIEWER_NAME) { as_review_set_reviewer_name (review, as_node_get_data (c)); continue; } if (as_node_get_tag (c) == AS_TAG_LANG) { as_review_set_locale (review, as_node_get_data (c)); continue; } if (as_node_get_tag (c) == AS_TAG_METADATA) { AsNode *c2; for (c2 = c->children; c2 != NULL; c2 = c2->next) { AsRefString *key; AsRefString *value; if (as_node_get_tag (c2) != AS_TAG_VALUE) continue; key = as_node_get_attribute (c2, "key"); value = as_node_get_data (c2); if (value == NULL) { g_hash_table_insert (priv->metadata, as_ref_string_ref (key), as_ref_string_new_static ("")); } else { g_hash_table_insert (priv->metadata, as_ref_string_ref (key), as_ref_string_ref (value)); } } continue; } } return TRUE; }