NSString+FIRInterlaceStrings.m 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Copyright 2019 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <TargetConditionals.h>
  17. #if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_VISION
  18. #import "FirebaseInAppMessaging/Sources/Private/Util/NSString+FIRInterlaceStrings.h"
  19. @implementation NSString (InterlaceStrings)
  20. + (NSString *)fir_interlaceString:(NSString *)stringOne withString:(NSString *)stringTwo {
  21. NSMutableString *interlacedString = [NSMutableString string];
  22. NSUInteger count = MAX(stringOne.length, stringTwo.length);
  23. for (NSUInteger i = 0; i < count; i++) {
  24. if (i < stringOne.length) {
  25. NSString *firstComponentChar =
  26. [NSString stringWithFormat:@"%c", [stringOne characterAtIndex:i]];
  27. [interlacedString appendString:firstComponentChar];
  28. }
  29. if (i < stringTwo.length) {
  30. NSString *secondComponentChar =
  31. [NSString stringWithFormat:@"%c", [stringTwo characterAtIndex:i]];
  32. [interlacedString appendString:secondComponentChar];
  33. }
  34. }
  35. return interlacedString;
  36. }
  37. @end
  38. #endif // TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_VISION