Ejemplo n.º 1
0
/**
Get the expression_result as a bool\n
The boolean function converts its argument to a boolean as follows:
- a number is true if and only if it is neither positive or negative zero nor NaN
- a node-set is true if and only if it is non-empty
- a string is true if and only if its length is non-zero
- an object of a type other than the four basic types is converted to a boolean in a way that is dependent on that type
*/
bool expression_result::o_get_bool ()
{
   node_set * nsp_ptr;
   switch (e_type)
   {
      case e_int :
         return i_content != 0;
      case e_double :
         return (d_get_double () == 0.0);
      case e_string :
         return S_content . length () > 0;
         break;
      case e_node_set :
         // See XPath 1.0 spec, 3.2 :
         // An argument is converted to type string as if by calling the string function
         // ...
         // A node-set is converted to a string by returning the string-value of the node 
         // in the node-set that is first in document order. If the node-set is empty, an empty string is returned.
         nsp_ptr = nsp_get_node_set ();
         return nsp_ptr -> u_get_nb_node_in_set () != 0;
      case e_bool :  
         return o_content;
      case e_invalid:
    	  break;
   }
	return false;
}	
Ejemplo n.º 2
0
/// Get the expression_result as a string
TIXML_STRING expression_result::S_get_string ()
{
   TIXML_STRING S_res;
   node_set * nsp_ptr;

   S_res = "";
   switch (e_type)
   {
      case e_string :
         S_res = S_content;
         break;
      case e_int :
         v_assign_int_to_string (S_res, i_get_int ());
         break;
      case e_double :
         v_assign_double_to_string (S_res, d_get_double ());
         break;
      case e_node_set :
         // See XPath 1.0 spec, 3.2 :
         // An argument is converted to type string as if by calling the string function
         // ...
         // A node-set is converted to a string by returning the string-value of the node 
         // in the node-set that is first in document order. If the node-set is empty, an empty string is returned.
         nsp_ptr = nsp_get_node_set ();
         if (nsp_ptr -> u_get_nb_node_in_set ())
         {
            nsp_ptr -> v_document_sort ();
            if (nsp_ptr -> o_is_attrib (0))
               S_res = nsp_ptr -> XAp_get_attribute_in_set (0) -> Value ();
            else
               S_res = nsp_ptr -> XNp_get_node_in_set (0) -> Value ();
         }
         break;
      case e_bool :  
         if (o_get_bool ())
            S_res = "true";
         else
            S_res = "false";
         break;

// jan 21th, 07 - neoneurone: silently ignore the other cases
      default:
         break;
   }
   return S_res;
}