forked from tomaz/appledoc
/
NSString+GBString.h
112 lines (82 loc) · 3.75 KB
/
NSString+GBString.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//
// NSString+GBString.h
// appledoc
//
// Created by Tomaz Kragelj on 31.7.10.
// Copyright (C) 2010, Gentle Bytes. All rights reserved.
//
#import <Foundation/Foundation.h>
/** Provides string extensions that make the rest of parsing code simpler. */
@interface NSString (GBString)
///---------------------------------------------------------------------------------------
/// @name Simplifying strings
///---------------------------------------------------------------------------------------
/** Trims all characters from the given set from the string end.
Works the same way as `[NSString(GBString) stringByTrimmingCharactersInSetFromEnd:]` except it trims from end only.
@param set The set of characters to trim.
@return Returns trimmed string.
@exception NSException Thrown if the given set is `nil`.
*/
- (NSString *)stringByTrimmingCharactersInSetFromEnd:(NSCharacterSet *)set;
/** Splits the string to words and returns all words separed by single space.
@return Returns wordified string.
*/
- (NSString *)stringByWordifyingWithSpaces;
/** Trims all whitespace from the start and end of the string and returns trimmed value.
@return Returns trimmed string.
@see stringByTrimmingWhitespaceAndNewLine
*/
- (NSString *)stringByTrimmingWhitespace;
/** Trims all whitespace and new lines from the start and end of the string and returns trimmed value.
@return Returns trimmed string.
@see stringByTrimmingWhitespace
*/
- (NSString *)stringByTrimmingWhitespaceAndNewLine;
///---------------------------------------------------------------------------------------
/// @name Preparing nice descriptions
///---------------------------------------------------------------------------------------
/** Returns normalized description from the receiver.
The main purpose of this method is to strip and wordifiy long descriptions by making them suitable for logging and debug messages.
@return Returns stripped description.
@see normalizedDescriptionWithMaxLength:
@see defaultNormalizedDescriptionLength
*/
- (NSString *)normalizedDescription;
/** Returns normalized description from the receiver.
The main purpose of this method is to strip and wordifiy long descriptions by making them suitable for logging and debug messages.
@param length Maximum length of the description.
@return Returns stripped description.
@see normalizedDescriptionWithMaxLength:
@see defaultNormalizedDescriptionLength
*/
- (NSString *)normalizedDescriptionWithMaxLength:(NSUInteger)length;
/** Returns default maximum length of normalized string.
*/
+ (NSUInteger)defaultNormalizedDescriptionLength;
///---------------------------------------------------------------------------------------
/// @name Getting information
///---------------------------------------------------------------------------------------
/** Creates a new `NSString` composed from all given lines delimited with the given delimiter.
@param lines Array of lines to combine.
@param delimiter Delimiter to use to separate lines.
@return Returns autoreleased string containing all lines.
*/
+ (NSString *)stringByCombiningLines:(NSArray *)lines delimitWith:(NSString *)delimiter;
/** Returns the array of all lines in the receiver.
@return Returns the array of all lines.
@see numberOfLines
*/
- (NSArray *)arrayOfLines;
/** Returns the number of all lines in the receiver.
@return Returns the number of all lines in the receiver.
@see numberOfLinesInRange:
*/
- (NSUInteger)numberOfLines;
/** Calculates the numer of lines in the given range of the receiver.
@param range The range to use for calculation.
@return Returns the number of lines in the given range.
@exception NSException Thrown if the given range is invalid.
@see numberOfLines
*/
- (NSUInteger)numberOfLinesInRange:(NSRange)range;
@end