Exemplo n.º 1
0
/* static */ double
XPath_Value::AsNumberL (const uni_char *string, unsigned string_length)
{
  TempBuffer buffer; ANCHOR (TempBuffer, buffer);
  buffer.AppendL (string, string_length);

  uni_char *endptr;
  return uni_strtod (buffer.GetStorage (), &endptr);
}
Exemplo n.º 2
0
XMLTreeAccessor::Node *
XPath_Node::GetTreeNodeByIdL (const uni_char *id, unsigned id_length)
{
  TempBuffer buffer; ANCHOR (TempBuffer, buffer);
  buffer.AppendL (id, id_length);

  XMLTreeAccessor::Node *node;
  LEAVE_IF_ERROR (tree->GetElementById (node, buffer.GetStorage ()));

  return node;
}
Exemplo n.º 3
0
void
XPath_Node::GetQualifiedNameL (TempBuffer &qname)
{
  OP_ASSERT (type == XP_NODE_ELEMENT || type == XP_NODE_ATTRIBUTE);

  XMLCompleteName temporary, *completename;

  if (type == XP_NODE_ELEMENT)
    {
      tree->GetName (temporary, treenode);
      completename = &temporary;
    }
  else
    completename = &name;

  const uni_char *prefix = completename->GetPrefix ();
  if (prefix)
    {
      qname.AppendL (prefix);
      qname.AppendL (":");
    }

  qname.AppendL (completename->GetLocalPart ());
}
Exemplo n.º 4
0
void
XPath_Node::GetStringValueL (TempBuffer &value)
{
  XMLTreeAccessor::Node *iter = treenode, *first = 0;
  const uni_char *data = 0;
  BOOL id, specified;

  switch (type)
    {
    case XP_NODE_ROOT:
    case XP_NODE_ELEMENT:
      LEAVE_IF_ERROR (tree->GetCharacterDataContent (data, treenode, &value));
      break;

    case XP_NODE_TEXT:
      while (XPath_Utils::GetNodeType (tree, iter) == XP_NODE_TEXT)
        {
          first = iter;

          if (XMLTreeAccessor::Node *previous = tree->GetPreviousSibling (iter))
            iter = previous;
          else
            break;
        }
      while (first && XPath_Utils::GetNodeType (tree, first) == XP_NODE_TEXT)
        {
          LEAVE_IF_ERROR (tree->GetData (data, first, &value));
          if (data != value.GetStorage ())
            /* Tree accessor returned text without generating into 'value' as
               an optimization.  But we really want it in 'value'. */
            value.AppendL (data);
          first = tree->GetNextSibling (first);
        }
      return;

    case XP_NODE_ATTRIBUTE:
      LEAVE_IF_ERROR (tree->GetAttribute (tree->GetAttributes (treenode, FALSE, TRUE), name, data, id, specified, &value));
      break;

    case XP_NODE_NAMESPACE:
      {
        const uni_char *uri = name.GetUri ();
        if (uri)
          value.AppendL (uri);
        return;
      }

    case XP_NODE_PI:
    case XP_NODE_COMMENT:
      LEAVE_IF_ERROR (tree->GetData (data, iter, &value));
      break;
    }

  /* Common case for XP_NODE_ROOT, XP_NODE_ELEMENT, XP_NODE_ATTRIBUTE,
     XP_NODE_PI and XP_NODE_COMMENT: check if the tree accessor generated the
     returned string into the buffer or if it returned a pointer to a string
     owned by the tree accessor. */

  if (data != value.GetStorage ())
    value.AppendL (data);
}
Exemplo n.º 5
0
/* static */ const uni_char *
XPath_Value::AsStringL (double number, TempBuffer &buffer)
{
  char *storage8;

  buffer.ExpandL (33);
  buffer.SetCachedLengthPolicy (TempBuffer::UNTRUSTED);
  storage8 = reinterpret_cast<char *> (buffer.GetStorage ());

  if (op_isnan (number))
    return UNI_L ("NaN");
  else if (number == 0)
    return UNI_L ("0");
  else
    {
      if (!OpDoubleFormat::ToString (storage8, number))
        LEAVE (OpStatus::ERR_NO_MEMORY);

      char *e = 0, *p = 0;
      for (unsigned index = 0; storage8[index]; ++index)
        if (storage8[index] == '.')
          p = &storage8[index];
        else if (storage8[index] == 'e' || storage8[index] == 'E')
          e = &storage8[index];

      if (e)
        {
          TempBuffer b; ANCHOR (TempBuffer, b);

          if (number < 0)
            b.AppendL ("-");

          int exp = op_atoi (e + 1), index;
          *e = 0;
          if (exp > 0)
            {
              if (storage8[0] != '0')
                b.AppendL (storage8[0]);
              if (p)
                {
                  b.AppendL (p + 1, MIN (e - (p + 1), exp));
                  if (exp < e - (p + 1))
                    {
                      b.AppendL (".");
                      b.AppendL (p + 1 + exp, e - (p + 1 + exp));
                    }
                  else if (e - (p + 1) < exp)
                    for (index = exp; index < e - (p + 1); ++index)
                      b.AppendL ("0");
                }
              else
                for (index = 0; index < exp; ++index)
                  b.AppendL ("0");
            }
          else if (exp < 0)
            {
              b.AppendL ("0.");
              for (index = 1; index < -exp; ++index)
                b.AppendL ("0");
              for (index = 0; storage8[index]; ++index)
                if (op_isdigit (storage8[index]) && storage8[index] != '0')
                  break;
              for (; storage8[index]; ++index)
                if (op_isdigit (storage8[index]))
                  b.AppendL (storage8[index]);
            }

          buffer.Clear ();
          buffer.AppendL (b.GetStorage ());
        }
      else
        make_doublebyte_in_place (buffer.GetStorage (), op_strlen (storage8));
    }

  return buffer.GetStorage ();
}