/***************************************************************
 * Copyright © 2017 HERE Global B.V. All rights reserved. *
 **************************************************************/

#import "NSString+Utilities.h"

@implementation NSString (HereSDK_Utilities)

+ (nullable NSString *)hereSDK_jsonFromObject:(id)object
{
    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:object
                                                       options:0
                                                         error:&error];
    if (error != nil) {
        NSLog(@"hereSDK_jsonFromObject error: %@", error.debugDescription);
        return nil;
    }
    return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}

+ (NSString *)hereSDK_utilities_emptyOrString:(NSString *)string
{
    return string ?: @"";
}

- (NSString *)hereSDK_utilities_nilOrString
{
    return self.length > 0 ? self : nil;
}

@end
