mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-26 10:11:03 +00:00
Fix errors folding headers
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@26072 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
8ade11113a
commit
aa6a65309e
2 changed files with 36 additions and 7 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
2008-02-16 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
* Source/Additions/GSMime.m: Fix errors in code for folding header
|
||||||
|
lines.
|
||||||
|
|
||||||
2008-02-14 Richard Frith-Macdonald <rfm@gnu.org>
|
2008-02-14 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* Source/GSHTTPURLHandle.m: Remove self as observer of socket
|
* Source/GSHTTPURLHandle.m: Remove self as observer of socket
|
||||||
|
|
|
@ -3255,12 +3255,20 @@ static unsigned
|
||||||
appendBytes(NSMutableData *m, unsigned offset, unsigned fold,
|
appendBytes(NSMutableData *m, unsigned offset, unsigned fold,
|
||||||
const char *bytes, unsigned size)
|
const char *bytes, unsigned size)
|
||||||
{
|
{
|
||||||
if (offset + size > fold && size + 8 <= fold)
|
if (offset + size > fold && size + 8 <= fold)
|
||||||
{
|
{
|
||||||
|
unsigned len = [m length];
|
||||||
|
|
||||||
/* This would take the line beyond the folding limit,
|
/* This would take the line beyond the folding limit,
|
||||||
* so we fold at this point.
|
* so we fold at this point.
|
||||||
|
* If we already have space at the end of the line,
|
||||||
|
* we remove it because the wrapping counts as a space.
|
||||||
*/
|
*/
|
||||||
[m appendBytes: @"\r\n\t" length: 3];
|
if (len > 0 && ((unsigned char*)[m bytes])[len - 1] == ' ')
|
||||||
|
{
|
||||||
|
[m setLength: --len];
|
||||||
|
}
|
||||||
|
[m appendBytes: "\r\n\t" length: 3];
|
||||||
offset = 8;
|
offset = 8;
|
||||||
if (size > 0 && isspace(bytes[0]))
|
if (size > 0 && isspace(bytes[0]))
|
||||||
{
|
{
|
||||||
|
@ -3298,20 +3306,34 @@ appendString(NSMutableData *m, unsigned offset, unsigned fold,
|
||||||
r = [str rangeOfCharacterFromSet: whitespace
|
r = [str rangeOfCharacterFromSet: whitespace
|
||||||
options: NSLiteralSearch
|
options: NSLiteralSearch
|
||||||
range: r];
|
range: r];
|
||||||
if (r.length > 0 && r.location == 0)
|
if (r.length > 0 && r.location == pos)
|
||||||
{
|
{
|
||||||
/* Found space at the start of the string, so we reduce
|
/* Found space at the start of the string, so we reduce
|
||||||
* it to a single space in the output.
|
* it to a single space in the output, or omit it entirely
|
||||||
|
* if the string is nothing but space.
|
||||||
*/
|
*/
|
||||||
pos++;
|
pos++;
|
||||||
offset = appendBytes(m, offset, fold, " ", 1);
|
while (pos < size
|
||||||
|
&& [whitespace characterIsMember: [str characterAtIndex: pos]])
|
||||||
|
{
|
||||||
|
pos++;
|
||||||
|
}
|
||||||
|
if (pos < size)
|
||||||
|
{
|
||||||
|
offset = appendBytes(m, offset, fold, " ", 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (r.length == 0)
|
else if (r.length == 0)
|
||||||
{
|
{
|
||||||
|
NSString *sub;
|
||||||
NSData *d;
|
NSData *d;
|
||||||
|
|
||||||
|
/* No space found ... we must output the entire string without
|
||||||
|
* folding it.
|
||||||
|
*/
|
||||||
|
sub = [str substringWithRange: NSMakeRange(pos, size - pos)];
|
||||||
pos = size;
|
pos = size;
|
||||||
d = wordData(str);
|
d = wordData(sub);
|
||||||
offset = appendBytes(m, offset, fold, [d bytes], [d length]);
|
offset = appendBytes(m, offset, fold, [d bytes], [d length]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -3319,8 +3341,10 @@ appendString(NSMutableData *m, unsigned offset, unsigned fold,
|
||||||
NSString *sub;
|
NSString *sub;
|
||||||
NSData *d;
|
NSData *d;
|
||||||
|
|
||||||
|
/* Output the substring up to the first space.
|
||||||
|
*/
|
||||||
sub = [str substringWithRange: NSMakeRange(pos, r.location - pos)];
|
sub = [str substringWithRange: NSMakeRange(pos, r.location - pos)];
|
||||||
pos = r.location + 1;
|
pos = r.location;
|
||||||
d = wordData(sub);
|
d = wordData(sub);
|
||||||
offset = appendBytes(m, offset, fold, [d bytes], [d length]);
|
offset = appendBytes(m, offset, fold, [d bytes], [d length]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue