static void TNLAppendParameterValue()

in Source/TNLURLCoding.m [124:154]


static void TNLAppendParameterValue(NSMutableString *parameterString,
                                    NSString *encodedKey,
                                    id value,
                                    TNLURLEncodingOptions options,
                                    BOOL *inoutIsFirstEntry)
{
    TNLAssert(encodedKey != nil);
    NSString *stringValue = TNLStringValue(value, options, encodedKey);
    if (stringValue) {
        NSString *encodedValue = TNLURLEncodeString(stringValue);
        if (!encodedValue) {
            TNLLogError(@"Could not encode value for encoded key '%@': '%@'", encodedKey, stringValue);
            TNLAssertMessage(encodedValue != nil, @"Could not encode value for encoded key '%@': '%@'", encodedKey, stringValue);

            // Handle the unexpected encoding of the value as an unsupported value

            if (TNL_BITMASK_HAS_SUBSET_FLAGS(options, TNLURLEncodingOptionTreatUnsupportedValuesAsEmpty)) {
                encodedValue = @"";
            } else if (TNL_BITMASK_EXCLUDES_FLAGS(options, TNLURLEncodingOptionIgnoreUnsupportedValues)) {
                NSString *reason = [NSString stringWithFormat:@"parameter object cannot be URL Encoded (options=%@, object=%@, stringValue=%@, key=%@)", @(options), value, stringValue, encodedKey];
                @throw [NSException exceptionWithName:NSInvalidArgumentException
                                               reason:reason
                                             userInfo:@{ @"object" : (value) ?: [NSNull null], @"encodingOptions" : @(options) }];
            }
        }

        if (encodedKey && encodedValue) {
            TNLAppendEncodedKeyValuePair(parameterString, encodedKey, encodedValue, options, inoutIsFirstEntry);
        }
    }
}