![]() |
CFStringGetLineBounds | Header: CFString.h |
Given a range of characters in a CFString object, obtains the line bounds, that is, the indexes of the first character and the final characters of the lines containing the range.
void CFStringGetLineBounds ( CFStringRef theString, CFRange range, CFIndex *lineBeginIndex, CFIndex *lineEndIndex, CFIndex *contentsEndIndex );
Pass a reference to the CFString object containing the specified range of characters.
Pass a sturcture of type CFRange that indicates the position of the first character to consider and the number of subsequent characters.
Pass the address of an integer variable of type CFIndex. On return, this variable contains the index of the first character of the containing line. Pass NULL if you are not interested in this result.
Pass the address of an integer variable of type CFIndex. On return, this variable contains the index of the first character of the line after the specified range. Pass NULL if you are not interested in this result.
Pass the address of an integer variable of type CFIndex. On return, this variable contains the index of the last character of the containing line, excluding any line-separator characters. Pass NULL if you are not interested in this result.
The CFStringGetLineBounds function is a convenience function for determining the beginning and ending indexes of one or more lines in the given range of a string. It is useful, for example, when each line represents a "record" of some sort; you might search for some substring, but want to extract the record of which the substring is a part.
To determine line separation, the function looks for the standard line-separator characters: carriage returns (CR and CRLF), linefeeds (LF), and Unicode line and paragraph separators. The three final parameters of the function indirectly return, in order, the index of the first character that starts the line, the index of the first character of the next line (including end-of-line characters), and the index of the last character of the line (excluding end-of-line characters). Pass NULL for any of these parameters if you aren't interested in the result.
To determine the number of characters in the line:
* Subract lineBeginIndex from lineEndIndex to find he number of characters in the line, including the line separators.
* Subtract lineBeginIndex from contentsEndIndex find the number of characters in the line, excluding the line separators.