Improve handling of asterisks in comments

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@17073 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2003-06-30 09:42:27 +00:00
parent b86d12e184
commit 9f61c0e274
2 changed files with 47 additions and 14 deletions

View file

@ -2,6 +2,8 @@
* Source/Additions/Unicode.m: Add 'UTF-7' so iconv can be used to * Source/Additions/Unicode.m: Add 'UTF-7' so iconv can be used to
handle utf7 if available. handle utf7 if available.
* Tools/AGSParser.m: Don't always strip asterisks from comments,
Check first line of comment to see if it has one first.
2003-06-28 15:48 Alexander Malmberg <alexander@malmberg.org> 2003-06-28 15:48 Alexander Malmberg <alexander@malmberg.org>

View file

@ -325,7 +325,7 @@
} }
/** /**
* In spite of it's trivial name, this is one of the key methods - * In spite of its trivial name, this is one of the key methods -
* it parses and skips past comments, but it also recognizes special * it parses and skips past comments, but it also recognizes special
* comments (with an additional asterisk after the start of the block * comments (with an additional asterisk after the start of the block
* comment) and extracts their contents, accumulating them into the * comment) and extracts their contents, accumulating them into the
@ -388,6 +388,7 @@
unichar *end = &buffer[pos - 1]; unichar *end = &buffer[pos - 1];
unichar *ptr = start; unichar *ptr = start;
unichar *newLine = ptr; unichar *newLine = ptr;
BOOL stripAsterisks = NO;
/* /*
* Remove any asterisks immediately before end of comment. * Remove any asterisks immediately before end of comment.
@ -407,7 +408,11 @@
*end++ = '\n'; *end++ = '\n';
/* /*
* Strip parts of lines up to leading asterisks. * If next line in the comment starts with whitespace followed
* by an asterisk, we assume all the lines in the comment start
* in a similar way, and everything up to and including the
* asterisk on each line should be stripped.
* Otherwise we take the comment verbatim.
*/ */
while (ptr < end) while (ptr < end)
{ {
@ -415,23 +420,49 @@
if (c == '\n') if (c == '\n')
{ {
newLine = ptr; break;
} }
else if (c == '*' && newLine != 0) else if (c == '*')
{ {
unichar *out = newLine; stripAsterisks = YES;
break;
while (ptr < end)
{
*out++ = *ptr++;
}
end = out;
ptr = newLine;
newLine = 0;
} }
else if ([spaces characterIsMember: c] == NO) else if ([spaces characterIsMember: c] == NO)
{ {
newLine = 0; break;
}
}
if (stripAsterisks == YES)
{
/*
* Strip parts of lines up to leading asterisks.
*/
ptr = start;
while (ptr < end)
{
unichar c = *ptr++;
if (c == '\n')
{
newLine = ptr;
}
else if (c == '*' && newLine != 0)
{
unichar *out = newLine;
while (ptr < end)
{
*out++ = *ptr++;
}
end = out;
ptr = newLine;
newLine = 0;
}
else if ([spaces characterIsMember: c] == NO)
{
newLine = 0;
}
} }
} }