2 // NSScanner_Extensions.m
5 // Created by Jonathan Wight on 12/08/2005.
6 // Copyright 2005 Toxic Software. All rights reserved.
9 #import "CDataScanner_Extensions.h"
11 #import "NSCharacterSet_Extensions.h"
13 @implementation CDataScanner (CDataScanner_Extensions)
15 - (BOOL)scanCStyleComment:(NSString **)outComment
17 if ([self scanString:@"/*" intoString:NULL] == YES)
19 NSString *theComment = NULL;
20 if ([self scanUpToString:@"*/" intoString:&theComment] == NO)
21 [NSException raise:NSGenericException format:@"Started to scan a C style comment but it wasn't terminated."];
23 if ([theComment rangeOfString:@"/*"].location != NSNotFound)
24 [NSException raise:NSGenericException format:@"C style comments should not be nested."];
26 if ([self scanString:@"*/" intoString:NULL] == NO)
27 [NSException raise:NSGenericException format:@"C style comment did not end correctly."];
29 if (outComment != NULL)
30 *outComment = theComment;
40 - (BOOL)scanCPlusPlusStyleComment:(NSString **)outComment
42 if ([self scanString:@"//" intoString:NULL] == YES)
44 NSString *theComment = NULL;
45 [self scanUpToCharactersFromSet:[NSCharacterSet linebreaksCharacterSet] intoString:&theComment];
46 [self scanCharactersFromSet:[NSCharacterSet linebreaksCharacterSet] intoString:NULL];
48 if (outComment != NULL)
49 *outComment = theComment;