| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ios/chrome/common/string_util.h" | 5 #include "ios/chrome/common/string_util.h" |
| 6 | 6 |
| 7 #import <UIKit/UIKit.h> | 7 #import <UIKit/UIKit.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/mac/scoped_block.h" | 10 #include "base/mac/scoped_block.h" |
| 11 #include "base/mac/scoped_nsobject.h" | 11 #include "base/mac/scoped_nsobject.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
| 14 | 14 |
| 15 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 16 #error "This file requires ARC support." |
| 17 #endif |
| 18 |
| 15 namespace { | 19 namespace { |
| 16 typedef BOOL (^ArrayFilterProcedure)(id object, NSUInteger index, BOOL* stop); | 20 typedef BOOL (^ArrayFilterProcedure)(id object, NSUInteger index, BOOL* stop); |
| 17 typedef NSString* (^SubstringExtractionProcedure)(NSUInteger); | 21 typedef NSString* (^SubstringExtractionProcedure)(NSUInteger); |
| 18 } | 22 } |
| 19 | 23 |
| 20 NSString* ParseStringWithLink(NSString* text, NSRange* out_link_range) { | 24 NSString* ParseStringWithLink(NSString* text, NSRange* out_link_range) { |
| 21 // Find the range within |text| and create a substring without the link tags. | 25 // Find the range within |text| and create a substring without the link tags. |
| 22 NSRange begin_range = [text rangeOfString:@"BEGIN_LINK[ \t]*" | 26 NSRange begin_range = [text rangeOfString:@"BEGIN_LINK[ \t]*" |
| 23 options:NSRegularExpressionSearch]; | 27 options:NSRegularExpressionSearch]; |
| 24 NSRange link_text_range = NSMakeRange(NSNotFound, 0); | 28 NSRange link_text_range = NSMakeRange(NSNotFound, 0); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 else { | 173 else { |
| 170 substring = getSubstring.get()(characters - increment); | 174 substring = getSubstring.get()(characters - increment); |
| 171 break; // Growing the string, found the right size. | 175 break; // Growing the string, found the right size. |
| 172 } | 176 } |
| 173 } | 177 } |
| 174 prevWidth = thisWidth; | 178 prevWidth = thisWidth; |
| 175 } while (characters > 0 && characters < [string length]); | 179 } while (characters > 0 && characters < [string length]); |
| 176 | 180 |
| 177 return substring; | 181 return substring; |
| 178 } | 182 } |
| OLD | NEW |