RosettaCodeData/Task/Strip-block-comments/FutureBasic/strip-block-comments.basic

40 lines
1.2 KiB
Plaintext

include "NSLog.incl"
local fn StripBlockComments( string as CFStringRef, openStr as CFStringRef, closeStr as CFStringRef ) as CFStringRef
if ( len( openStr ) == 0 || len( closeStr ) == 0 ) then return string
CFMutableStringRef ret = fn MutableStringWithString( string )
CFRange range
while ( YES )
range = fn StringRangeOfString( ret, openStr )
if ( range.location == NSNotFound ) then exit while
CFRange endRange = fn StringRangeOfStringWithOptionsInRange( ret, closeStr, NULL, fn CFRangeMake( range.location + range.length, len(ret) - (range.location + range.length ) ) )
if ( endRange.location == NSNotFound )
break
end if
CFRange fullRange = fn CFRangeMake( range.location, endRange.location + endRange.length - range.location )
MutableStringDeleteCharacters( ret, fullRange )
wend
end fn = ret
CFStringRef test = @"/**\n¬
* Some comments\n¬
* longer comments here that we can parse.\n¬
*\n¬
* Rahoo \n¬
*/\n¬
local fn Subroutine( b as int, c as int ) as int\n¬
int a = /* inline comment */ b + c \n¬
end fn = a\n¬
/*/ <-- tricky comments */\n¬
\n¬
/**\n¬
* Another comment.\n¬
*/\n¬
local fn DoSomething\n¬
end fn\n¬
"
NSLog( @"%@", fn StripBlockComments( test, @"/*", @"*/" ) )
HandleEvents