コード例 #1
0
ファイル: rdf_storage_trees.c プロジェクト: njh/librdf
static int
librdf_storage_trees_node_compare(librdf_node* n1, librdf_node* n2)
{
  if (n1 == n2) {
    return 0;
  } else if (n1->type != n2->type) {
    return n2->type - n1->type;
  } else {
    switch (n1->type) {
      case LIBRDF_NODE_TYPE_RESOURCE:
        return librdf_uri_compare(librdf_node_get_uri(n1), librdf_node_get_uri(n2));
      case LIBRDF_NODE_TYPE_LITERAL:
        if (1) {
          const char *s;
          size_t l1;
          size_t l2;
          size_t l;
          int r;

          s = librdf_node_get_literal_value_language(n1);
          l1 = s ? strlen(s) : 0;
          s = librdf_node_get_literal_value_language(n2);
          l2 = s ? strlen(s) : 0;

          l = (l1 < l2) ? l1 : l2;

          /* compare first by data type */
          r = librdf_uri_compare(librdf_node_get_literal_value_datatype_uri(n1),
                                 librdf_node_get_literal_value_datatype_uri(n2));
          if (r)
            return r;

          /* if data type is equal, compare by value */
          r = strcmp((const char*)librdf_node_get_literal_value(n1),
                     (const char*)librdf_node_get_literal_value(n2));
          if (r)
            return r;

          /* if both data type and value are equal, compare by language */
          if (l) {
            return strncmp(librdf_node_get_literal_value_language(n1),
                           librdf_node_get_literal_value_language(n2),
                           (size_t)l);
          } else {
            /* if l == 0 strncmp will always return 0; in that case
             * consider the node with no language to be lesser. */
            return l1 - l2;
          }
        }
      case LIBRDF_NODE_TYPE_BLANK:
        return strcmp((char*)n1->value.blank.identifier,
                      (char*)n2->value.blank.identifier);
      case LIBRDF_NODE_TYPE_UNKNOWN:
      default:
        return (char*)n2-(char*)n1; /* ? */
    }
  }
}
コード例 #2
0
ファイル: rdf_storage_trees.c プロジェクト: njh/librdf
static int
librdf_storage_trees_node_compare(librdf_node* n1, librdf_node* n2)
{
  if (n1 == n2) {
    return 0;
  } else if (n1->type != n2->type) {
    return n2->type - n1->type;
  } else {
    switch (n1->type) {
      case RAPTOR_TERM_TYPE_URI:
        return librdf_uri_compare(n1->value.uri, n2->value.uri);

      case RAPTOR_TERM_TYPE_LITERAL:
        if(1) {
          const unsigned char l1 = n1->value.literal.language_len;
          const unsigned char l2 = n2->value.literal.language_len;
          const unsigned char l  = (l1 < l2) ? l1 : l2;

          /* compare first by data type */
          int r = raptor_uri_compare(n1->value.literal.datatype,
                                     n2->value.literal.datatype);
          if(r)
            return r;

          /* if data type is equal, compare by value */
          r = strcmp((const char*)n1->value.literal.string,
                     (const char*)n2->value.literal.string);
          if(r)
            return r;

          /* if both data type and value are equal, compare by language */
          if(l) {
            return strncmp((const char*)n1->value.literal.language,
                           (const char*)n2->value.literal.language, (size_t)l);
          } else {
            /* if l == 0 strncmp will always return 0; in that case
             * consider the node with no language to be lesser. */
            return l1 - l2;
          }
        }
      case RAPTOR_TERM_TYPE_BLANK:
        return strcmp((char*)n1->value.blank.string,
                      (char*)n2->value.blank.string);

      case RAPTOR_TERM_TYPE_UNKNOWN:
      default:
        return (char*)n2-(char*)n1; /* ? */
    }
  }
}
コード例 #3
0
static int
librdf_storage_trees_node_compare(librdf_node* n1, librdf_node* n2)
{
  if (n1 == n2) {
    return 0;
  } else if (n1->type != n2->type) {
    return n2->type - n1->type;
  } else {
    switch (n1->type) {
      case LIBRDF_NODE_TYPE_RESOURCE:
        return librdf_uri_compare(n1->value.resource.uri, n2->value.resource.uri);
      case LIBRDF_NODE_TYPE_LITERAL:
        return strcmp((char*)n1->value.literal.string, (char*)n2->value.literal.string);
      case LIBRDF_NODE_TYPE_BLANK:
        return strcmp((char*)n1->value.blank.identifier, (char*)n2->value.blank.identifier);
      case LIBRDF_NODE_TYPE_UNKNOWN:
      default:
        return (char*)n2-(char*)n1; /* ? */
    }
  }
}