mirror of
https://github.com/RevenueCat/purchases-ios
synced 2026-11-11 22:55:55 +05:45
Splits a string into an array of fields, keeping empty ones, so rules can target locale subtags, product-id namespaces and similar composite values. A var path cannot index the result of an expression, so a positional field is read by wrapping the array in a one-element list and letting an iteration operator rebind scope to it. The array is also usable directly by in and by the iteration operators. Fields are never coerced to numbers, and a non-string operand or empty separator throws typeMismatch rather than splitting into characters. Co-authored-by: Cursor <cursoragent@cursor.com>
43 lines
1.1 KiB
Swift
43 lines
1.1 KiB
Swift
//
|
|
// CustomOperators.swift
|
|
//
|
|
// Created by Antonio Pallares.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
extension RulesEngine {
|
|
|
|
/// RevenueCat-specific JSON Logic operators.
|
|
///
|
|
/// Operators here are namespaced under `rc.` so they cannot collide with a
|
|
/// future standard JSON Logic operator.
|
|
enum CustomOperators {
|
|
|
|
static func dispatch(
|
|
op operatorName: String,
|
|
args: Value,
|
|
vars: Scope
|
|
) throws -> Value {
|
|
switch operatorName {
|
|
case "rc.length":
|
|
return try LengthOperator.opLength(args: args, vars: vars)
|
|
|
|
case "rc.lower":
|
|
return try CaseOperators.opLower(args: args, vars: vars)
|
|
case "rc.upper":
|
|
return try CaseOperators.opUpper(args: args, vars: vars)
|
|
|
|
case "rc.rootVar":
|
|
return try RootVarOperator.opRootVar(args: args, vars: vars)
|
|
|
|
case "rc.split":
|
|
return try SplitOperator.opSplit(args: args, vars: vars)
|
|
|
|
default:
|
|
throw EvaluationError.unsupportedOperator(name: operatorName)
|
|
}
|
|
}
|
|
}
|
|
}
|