xor method

  1. @override
Variant xor(
  1. Variant value1,
  2. Variant value2
)
override

Performs XOR operation for two variants.

  • value1 The first operand for this operation.
  • value2 The second operand for this operation. Returns A result variant object.

Implementation

@override
Variant xor(Variant value1, Variant value2) {
  var result = Variant();

  // Processes VariantType.Null values.
  if (value1.type == VariantType.Null || value2.type == VariantType.Null) {
    return result;
  }

  // Converts second operant to the type of the first operand.
  value2 = convert(value2, value1.type);

  // Performs operation.
  switch (value1.type) {
    case VariantType.Integer:
      result.asInteger = value1.asInteger ^ value2.asInteger;
      return result;
    case VariantType.Long:
      result.asLong = value1.asLong ^ value2.asLong;
      return result;
    case VariantType.Boolean:
      result.asBoolean = (value1.asBoolean && !value2.asBoolean) ||
          (!value1.asBoolean && value2.asBoolean);
      return result;

    default:
      throw Exception('Operation XOR is not supported for type ' +
          typeToString(value1.type));
  }
}