NSExpression+FBFormat.m 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /**
  2. * Copyright (c) 2015-present, Facebook, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. */
  9. #import "NSExpression+FBFormat.h"
  10. #import "FBElementUtils.h"
  11. @implementation NSExpression (FBFormat)
  12. + (instancetype)fb_wdExpressionWithExpression:(NSExpression *)input
  13. {
  14. if ([input expressionType] != NSKeyPathExpressionType) {
  15. return input;
  16. }
  17. NSString *propName = [input keyPath];
  18. NSUInteger dotPos = [propName rangeOfString:@"."].location;
  19. NSString *wdPropName;
  20. if (NSNotFound == dotPos) {
  21. wdPropName = [FBElementUtils wdAttributeNameForAttributeName:propName];
  22. } else {
  23. NSString *actualPropName = [propName substringToIndex:dotPos];
  24. NSString *suffix = [propName substringFromIndex:(dotPos + 1)];
  25. wdPropName = [NSString stringWithFormat:@"%@.%@", [FBElementUtils wdAttributeNameForAttributeName:actualPropName], suffix];
  26. }
  27. return [NSExpression expressionForKeyPath:wdPropName];
  28. }
  29. @end