Don't get range from nil

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@16532 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2003-04-24 17:34:06 +00:00
parent efaef5b924
commit d9807b8983

View file

@ -1185,29 +1185,32 @@ static BOOL snuggleStart(NSString *t)
unitName = name; unitName = name;
} }
r = [comment rangeOfString: @"<standards>"]; if (comment != nil)
if (comment != nil && r.length > 0)
{ {
unsigned i = r.location; r = [comment rangeOfString: @"<standards>"];
r = NSMakeRange(i, [comment length] - i);
r = [comment rangeOfString: @"</standards>"
options: NSLiteralSearch
range: r];
if (r.length > 0) if (r.length > 0)
{ {
NSMutableString *m; unsigned i = r.location;
r = NSMakeRange(i, NSMaxRange(r) - i); r = NSMakeRange(i, [comment length] - i);
standards = [comment substringWithRange: r]; r = [comment rangeOfString: @"</standards>"
m = [comment mutableCopy]; options: NSLiteralSearch
[m deleteCharactersInRange: r]; range: r];
comment = m; if (r.length > 0)
AUTORELEASE(m); {
} NSMutableString *m;
else
{ r = NSMakeRange(i, NSMaxRange(r) - i);
NSLog(@"unterminated <standards> in comment for %@", name); standards = [comment substringWithRange: r];
m = [comment mutableCopy];
[m deleteCharactersInRange: r];
comment = m;
AUTORELEASE(m);
}
else
{
NSLog(@"unterminated <standards> in comment for %@", name);
}
} }
} }
if (standards == nil) if (standards == nil)
@ -1219,49 +1222,53 @@ static BOOL snuggleStart(NSString *t)
* Make sure we have a 'unit' part and a class 'desc' part (comment) * Make sure we have a 'unit' part and a class 'desc' part (comment)
* to be output. * to be output.
*/ */
r = [comment rangeOfString: @"<unit>"]; if (comment != nil)
if (comment != nil && r.length > 0)
{ {
unsigned pos = r.location; r = [comment rangeOfString: @"<unit>"];
if (r.length > 0)
{
unsigned pos = r.location;
r = [comment rangeOfString: @"</unit>"]; r = [comment rangeOfString: @"</unit>"];
if (r.length == 0 || r.location < pos) if (r.length == 0 || r.location < pos)
{
NSLog(@"Unterminated <unit> in comment for %@", name);
return;
}
if (pos == 0)
{
if (NSMaxRange(r) == [comment length])
{ {
unit = comment; NSLog(@"Unterminated <unit> in comment for %@", name);
comment = nil; return;
}
if (pos == 0)
{
if (NSMaxRange(r) == [comment length])
{
unit = comment;
comment = nil;
}
else
{
unit = [comment substringToIndex: NSMaxRange(r)];
comment = [comment substringFromIndex: NSMaxRange(r)];
}
} }
else else
{ {
unit = [comment substringToIndex: NSMaxRange(r)]; if (NSMaxRange(r) == [comment length])
comment = [comment substringFromIndex: NSMaxRange(r)]; {
} unit = [comment substringFromIndex: pos];
} comment = [comment substringToIndex: pos];
else }
{ else
if (NSMaxRange(r) == [comment length]) {
{ unsigned end = NSMaxRange(r);
unit = [comment substringFromIndex: pos];
comment = [comment substringToIndex: pos];
}
else
{
unsigned end = NSMaxRange(r);
r = NSMakeRange(pos, end-pos); r = NSMakeRange(pos, end-pos);
unit = [comment substringWithRange: r]; unit = [comment substringWithRange: r];
comment = [[comment substringToIndex: pos] comment = [[comment substringToIndex: pos]
stringByAppendingString: [comment substringFromIndex: end]]; stringByAppendingString: [comment substringFromIndex: end]];
}
} }
unit = [unit stringByReplacingString: @"unit>"
withString: @"chapter>"];
} }
unit = [unit stringByReplacingString: @"unit>" withString: @"chapter>"];
} }
else else
{ {