@@ -24,8 +24,8 @@ @implementation DTLocalizableStringScanner
2424
2525 unichar *_characters;
2626 NSString *_charactersAsString;
27- NSUInteger _stringLength;
2827 NSUInteger _currentIndex;
28+ NSRange _charactersRange;
2929}
3030
3131@synthesize entryFoundCallback=_entryFoundCallback;
@@ -41,13 +41,10 @@ - (id)initWithContentsOfURL:(NSURL *)url encoding:(NSStringEncoding)encoding val
4141 if (!_charactersAsString)
4242 {
4343 return nil ;
44- }
45-
46- _stringLength = [_charactersAsString length ];
47- _characters = calloc (_stringLength, sizeof (unichar ));
48- [_charactersAsString getCharacters: _characters range: NSMakeRange (0 , _stringLength)];
49- _currentIndex = 0 ;
44+ }
5045
46+ _characters = nil ;
47+
5148 _url = [url copy ]; // to have a reference later
5249
5350 _validMacros = validMacros;
@@ -107,7 +104,7 @@ - (NSString *)_scanQuotedString
107104
108105 BOOL isEscaping = NO ;
109106 BOOL keepGoing = YES ;
110- while (keepGoing && _currentIndex < _stringLength )
107+ while (keepGoing && _currentIndex < _charactersRange. length )
111108 {
112109 unichar character = _characters[_currentIndex];
113110
@@ -152,7 +149,7 @@ - (NSString *)_scanParameter
152149
153150 NSInteger parenCount = 0 ;
154151
155- while (keepGoing && _currentIndex < _stringLength )
152+ while (keepGoing && _currentIndex < _charactersRange. length )
156153 {
157154 unichar character = _characters[_currentIndex];
158155 if (character == ' ,' )
@@ -196,12 +193,14 @@ - (NSString *)_scanParameter
196193}
197194
198195- (BOOL )_processMacroAtRange : (NSRange )range
199- {
200- NSString *macroName = [_charactersAsString substringWithRange: range];
201-
202- _currentIndex = range.location + range.length ;
203-
204196 NSMutableArray *parameters = [[NSMutableArray alloc] initWithCapacity :10];
197+ {
198+ if (_characters == nil ) {
199+ _charactersRange = NSMakeRange (range.location , [_charactersAsString length ] - range.location );
200+ _characters = calloc (_charactersRange.length , sizeof (unichar ));
201+ [_charactersAsString getCharacters: _characters range: _charactersRange];
202+ }
203+ _currentIndex = range.location + range.length - _charactersRange.location ;
205204
206205
207206 // skip any whitespace between here and the (
@@ -212,7 +211,7 @@ - (BOOL)_processMacroAtRange:(NSRange)range
212211 // read the opening parenthesis
213212 _currentIndex++;
214213
215- while (_currentIndex < _stringLength )
214+ while (_currentIndex < _charactersRange. length )
216215 {
217216 // skip any leading whitespace
218217 [self _scanWhitespace ];
0 commit comments