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
3 // found in the LICENSE file.
5 #ifndef IOS_CHROME_COMMON_STRING_UTIL_H_
6 #define IOS_CHROME_COMMON_STRING_UTIL_H_
8 #import <CoreGraphics/CoreGraphics.h>
9 #import <Foundation/Foundation.h>
12 // Parses a string with an embedded link inside, delineated by BEGIN_LINK and
13 // END_LINK. Returns the string without the link delimiters. If |out_link_range|
14 // is not null, then it is filled out with the range of the link in the returned
16 // If no link is found, then it returns |text| and sets |out_link_range| to
18 NSString
* ParseStringWithLink(NSString
* text
, NSRange
* out_link_range
);
20 // Utility method that returns an NSCharacterSet containing Unicode graphics
21 // and drawing characters (but not including the Braille Patterns characters).
22 NSCharacterSet
* GraphicCharactersSet();
24 // Cleans an NSString by collapsing whitespace and removing leading and trailing
25 // spaces. If |removeGraphicChars| is true, unicode graphic characters will also
26 // be removed from the string.
27 NSString
* CleanNSStringForDisplay(NSString
* dirty
, BOOL removeGraphicChars
);
29 // Cleans a std::string identically to CleanNSStringForDisplay()
30 std::string
CleanStringForDisplay(std::string dirty
, BOOL removeGraphicChars
);
32 // Find the longest leading substring of |string| that, when rendered with
33 // |attributes|, will fit on a single line inside |targetWidth|. If |trailing|
34 // is YES, then find the trailing (instead of leading) substring.
35 NSString
* SubstringOfWidth(NSString
* string
,
36 NSDictionary
* attributes
,
40 #endif // IOS_CHROME_COMMON_STRING_UTIL_H_