Compare
@param XPath2Context $context
@param object $a
@param object $b
@param string $collation
@return object
343239
public static function CompareWithCollation( $context, $a, $b, $collation )
	{
		if ( $a instanceof Undefined || $b instanceof Undefined )
		{
			return Undefined::getValue();
		}

		if ( $collation == XmlReservedNs::collationCodepoint )
		{
			$s1 = \normalizer_normalize( $a, \Normalizer::FORM_C );
			$s2 = \normalizer_normalize( $b, \Normalizer::FORM_C );

			// On Windows the strcmp function return -1, 0, 1 but on Linux the strcmp function
			// returns a value which is the difference in the ascii value of the first mismatched char
			// This function makes sure both return -1, 0, 1
			return ( $x = strcmp( $s1, $s2 ) ) == 0 ? 0 : ( $x >= 1 ? 1 : -1  );
			// return strcmp( $s1, $s2 );
		}
		else
		{
			$s1 = $a . "";
			$s2 = $b . "";

			$result = setlocale( LC_COLLATE, $collation );
			if ( ! $result )
			{
				throw XPath2Exception::withErrorCodeAndParam( "FOCH0002", Resources::FOCH0002, $collation );
			}
			// On Windows the strcoll function return -1, 0, 1 but on Linux the strcoll function
			// returns a value which is the difference in the ascii value of the first mismatched char
			// This function makes sure both return -1, 0, 1
			return ( $x = strcoll( $s1, $s2 ) ) == 0 ? 0 : ( $x >= 1 ? 1 : -1  );
			// return strcoll( $s1, $s2 );
		}
	}
696815
public function versionCompare($a, $b, $operator, $compareBranches = false)
    {
        if (!isset(self::$transOpStr[$operator])) {
            throw new \InvalidArgumentException(sprintf(
                'Invalid operator "%s" given, expected one of: %s',
                $operator,
                implode(', ', self::getSupportedOperators())
            ));
        }

        $aIsBranch = 'dev-' === substr($a, 0, 4);
        $bIsBranch = 'dev-' === substr($b, 0, 4);

        if ($aIsBranch && $bIsBranch) {
            return $operator === '==' && $a === $b;
        }

        // when branches are not comparable, we make sure dev branches never match anything
        if (!$compareBranches && ($aIsBranch || $bIsBranch)) {
            return false;
        }

        return version_compare($a, $b, $operator);
    }
551108
public function compareByPrefix(Argument $a, Argument $b)
    {
        if ($this->prefixCompareString($a) < $this->prefixCompareString($b)) {
            return -1;
        }

        return 1;
    }
839608
public static function compare($a, $b)
    {
        if ($a->getRow() == $b->getRow()) {
            return $a->getCell() - $b->getCell();
        }

        return $a->getRow() - $b->getRow();
    }
647939
public function evaluate(Context $context) {
		$opL = $this->operands[0]->evaluate($context);
		$opR = $this->operands[1]->evaluate($context);

		if ($opL instanceof \DOMNode) {
		    $opL = $opL->nodeValue;
		}
		if ($opR instanceof \DOMNode) {
		    $opR = $opR->nodeValue;
		}

		switch($this->comparator) {
			case 'gt' : return ($opL >  $opR);
			case 'gte': return ($opL >= $opR);
			case 'lt' : return ($opL <  $opR);
			case 'lte': return ($opL <= $opR);

			case '==' :
				//First: let's check for empty variables:
				if(
						(empty($opL) && ! empty($opR)) ||
						(empty($opR) && ! empty($opL))
					) {
					return false;
				}

				//If one of the operands is a string,
				//we must do a string comparison.
				if(is_string($opL) || is_string($opR)) {
					if(is_array($opL) || is_array($opR)) {
						//But if the other is an array, we cannot convert Array to String
						//to perform the comparison, so we throw an error.
						throw new LexerArrayToStringConversionException();
					} else {
						return (0 === strcmp($opL, $opR));
					}
				} else {
					return $opL == $opR;
				}

			case '!=' :
				if(is_float($opL)) {
					return ($opL . '' != $opR . '');
				} else {
					return ($opL != $opR);
				}

      // the "default:" case is not a possible branch.
      // I am required to write a default for the switch statement,
      // but it can never happen because the TokenComparisonBinop is only valid
      // for the above operators.
      // @codeCoverageIgnoreStart
			default: return false;
		}
    // @codeCoverageIgnoreEnd
    // I place this end annotation after the } of the switch, otherwise the } is
    // considered not covered!
    // I hate these hacks, but so far this is all what PHPUnit Coverage as to offer.
	}
273921
private ComparisonState compareDocuments(final Document control,
                                             final XPathContext controlContext,
                                             final Document test,
                                             final XPathContext testContext) {
        final DocumentType controlDt = filterNode(control.getDoctype());
        final DocumentType testDt = filterNode(test.getDoctype());

        return compare(new Comparison(ComparisonType.HAS_DOCTYPE_DECLARATION,
                                      control, getXPath(controlContext),
                                      Boolean.valueOf(controlDt != null), getParentXPath(controlContext),
                                      test, getXPath(testContext),
                                      Boolean.valueOf(testDt != null), getParentXPath(testContext)))
            .andIfTrueThen(controlDt != null && testDt != null,
                           new DeferredComparison() {
                               @Override
                               public ComparisonState apply() {
                                   return compareNodes(controlDt, controlContext,
                                                       testDt, testContext);
                               }
                           })
            .andThen(compareDeclarations(control, controlContext,
                                         test, testContext));
    }
444915
public static function compare_plugins(editor_tinymce_plugin $a, editor_tinymce_plugin $b) {
        // Use sort order first.
        $order = $a->get_sort_order() - $b->get_sort_order();
        if ($order != 0) {
            return $order;
        }

        // Then sort alphabetically.
        return strcmp($a->plugin, $b->plugin);
    }
802129
public static function CreateQName( $context, $ns, $qname )
	{
		if ( $ns instanceof Undefined )
		{
			$ns = "";
		}

		$ns = trim( $ns );
		$qname = trim( $qname );

		if ( empty( $ns ) && strpos( $qname, ":" ) )
		{
			throw XPath2Exception::withErrorCodeAndParam( "FOCA0002", Resources::FOCA0002, $qname );
		}

		// $qn = \lyquidity\xml\qname( $ns, $qname );
		if ( strpos( $qname, ":") !== false )
		{
			$parts = explode( ":", $qname );
			$qn = new \lyquidity\xml\qname( $parts[0], $ns, $parts[1] );
		}
		else
		{
			$prefix = $context->NamespaceManager->lookupPrefix( $ns );
			$qn = new \lyquidity\xml\qname( $prefix ? $prefix : "", $ns, $qname );
		}
		return QNameValue::fromQName( $qn );
	}
862147
public function set(string $locale, string $collate): bool {
    $auth = false;
    try {
      if (!empty($locale)) {
        $_locale = preg_replace("/^(\w{2})-(\w{2})$/", "$1_$2", $locale);
        locale_set_default($_locale);
        if (!empty($collate)) {
          $_locale .= "." . strtoupper($collate);
        }
        setlocale(LC_ALL, $_locale);
        $auth = true;
      }
    } catch (Exception $ex) {
      $auth = false;
      throw $ex;
    }
    return $auth;
  }
170761
public function compareTo($other)
    {
        if ($other === null) {
            return false;
        }
        if (!($other instanceof PostfixOperatorNode)) {
            return false;
        }

        return $this->getOperator() == $other->getOperator();
    }
1080597
public function compareTo($other)
    {
        if ($other === null) {
            return false;
        }
        if (!($other instanceof SubExpressionNode)) {
            return false;
        }

        return $this->getValue() == $other->getValue();
    }
263317
public static function GetBaseUri( $context, $nav )
	{
		if ( is_null( $nav ) )
		    return Undefined::getValue();

		if ( !( $nav->getNodeType() == XPathNodeType::Element ||
			 $nav->getNodeType() == XPathNodeType::Attribute ||
			 $nav->getNodeType() == XPathNodeType::Root ||
			 $nav->getNodeType() == XPathNodeType::NamespaceURI ) )
		    return Undefined::getValue();

		$nav = $nav->CloneInstance();
		$uri = array();
		do
		{
		    $baseUri = $nav->getBaseURI();
		    if ( $baseUri != "" )
			   $uri[] = $baseUri;
		}
		while ( $nav->MoveToParent() );

		$res = is_null( $context->RunningContext->BaseUri )
			? null
			: $context->RunningContext->BaseUri;

		for ( $k = count( $uri ) - 1; $k >= 0; $k-- )
		{
		    $res = is_null( $res )
		    	? uri[k]
		    	: SchemaTypes::resolve_path( $res, $uri[k] );
		}

		return is_null( $res )
			? Undefined::getValue()
			: new AnyUriValue( $res );
	}
777963
static public function parseFragment($text, $context = null, $builder = null) {
        $tokenizer = new HTML5_Tokenizer($text, $builder);
        $tokenizer->parseFragment($context);
        return $tokenizer->save();
    }
1259313
public static function ResolveUriFromContext( $context, $relative )
	{
		if ( $relative instanceof Undefined )
		    return Undefined::getValue();

		$rel = $relative . "";
		if ( is_null( $context->RunningContext->BaseUri ) )
		    throw XPath2Exception::withErrorCode( "FONS0005", Resources::FONS0005 );
		try
		{
		    return new AnyUriValue( SchemaTypes::resolve_path( $context->RunningContext->getBaseUri(), $rel ) );
		}
		catch ( UriFormatException $ex )
		{
		    throw XPath2Exception::withErrorCode( "FORG0009", Resources::FORG0009 );
		}
	}
1042411
public static function fromParts( $context, $nodeTest, $matchSelf, $iter )
	{
		$result = new AncestorNodeIterator();
		$result->fromAxisNodeIteratorParts( $context, $nodeTest, $matchSelf, $iter );
		return $result;
	}
1256290
public function visit($query, $node, string $context)
    {
        if ($node instanceof $this->node) {
            $bindings = [];
            $sql = [];

            $child0 = $node->getChildByIndex(0);
            $child1 = $node->getChildByIndex(1);

            if ($child0 instanceof Nodes\KeyNode) {
                $context === Nodes\OrNode::class && $query->orWhereNotNull($this->parseKey($child0->getValue()));
                $context === Nodes\AndNode::class && $query->whereNotNull($this->parseKey($child0->getValue()));
            }
        }
    }
155792
public function find($context, $original = '')
    {
        if ($context instanceof Translation) {
            $id = $context->getId();
        } else {
            $id = Translation::generateId($context, $original);
        }

        return $this->offsetExists($id) ? $this[$id] : false;
    }