NSDictionary+FBUtf8SafeDictionary.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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 <Foundation/Foundation.h>
  10. NS_ASSUME_NONNULL_BEGIN
  11. @interface NSString (FBUtf8SafeString)
  12. /**
  13. Converts the string, so it could be properly represented in UTF-8 encoding. All non-encodable characters are replaced with
  14. the given `replacement`
  15. @param replacement The character to use a a replacement for the lossy encoding
  16. @returns Either the same string or a string with non-encodable chars replaced
  17. */
  18. - (instancetype)fb_utf8SafeStringWithReplacement:(unichar)replacement;
  19. @end
  20. @interface NSDictionary (FBUtf8SafeDictionary)
  21. /**
  22. Converts the dictionary, so it could be properly represented in UTF-8 encoding. All non-encodable characters
  23. in string values are replaced with the Unocde question mark characters. Nested dictionaries and arrays are
  24. processed recursively.
  25. @returns Either the same dictionary or a dictionary with non-encodable chars in string values replaced
  26. */
  27. - (instancetype)fb_utf8SafeDictionary;
  28. @end
  29. NS_ASSUME_NONNULL_END