//---------------------------------------------------------------------------------------
//	NSCharacterSet+MIME.m created by erik on Sun 23-Mar-1997
//	This code is part of the Alexandra Newsreader Project. For copyright details see
//	GNU public license version 2 or above. No warranties implied. Use at own risk.
//	More information can be found at <http://www.object-factory.com/Alexandra>.
//	@(#)$Id: NSCharacterSet+MIME.m,v 1.6 1998/09/28 12:28:36 erik Exp $
//---------------------------------------------------------------------------------------

#import "Utilities.h"
#import "NSCharacterSet+MIME.h"


//---------------------------------------------------------------------------------------
    @implementation NSCharacterSet (MessageExtensions_Alexandra)
//---------------------------------------------------------------------------------------

+ (NSCharacterSet *)standardASCIICharacterSet;
{
    static NSCharacterSet *set = nil;

    if(set == nil)
        set = [[NSCharacterSet characterSetWithRange:NSMakeRange(0, 127)] retain];

    return set;
}


//---------------------------------------------------------------------------------------
//	character sets for RFC822
//---------------------------------------------------------------------------------------

+ (NSCharacterSet *)MASpecialCharacterSet;
{
    static NSCharacterSet *set = nil;

    if(set == nil)
        set = [[NSCharacterSet characterSetWithCharactersInString:@"()<>@.,;:\\\"[]"] retain];

    return set;
}

+ (NSCharacterSet *)MAEncodedAtomCharacterSet;
{
    static NSCharacterSet *set = nil;

    if(set == nil)
        {
        NSMutableCharacterSet	*cs;

        cs = [[[NSMutableCharacterSet controlCharacterSet] mutableCopy] autorelease];
        [cs formUnionWithCharacterSet:[self MASpecialCharacterSet]];
        [cs formUnionWithCharacterSet:[self whitespaceCharacterSet]];
        [cs invert];
        set = [cs copy];
        }
    
    return set;
}

+ (NSCharacterSet *)MAAtomCharacterSet;
{
    static NSCharacterSet *set = nil;

    if(set == nil)
        {
        NSMutableCharacterSet	*cs;

        cs = [[[NSMutableCharacterSet controlCharacterSet] mutableCopy] autorelease];
        [cs formUnionWithCharacterSet:[self MASpecialCharacterSet]];
        [cs formUnionWithCharacterSet:[self whitespaceCharacterSet]];
        [cs invert];
        [cs formIntersectionWithCharacterSet:[self standardASCIICharacterSet]];
        set = [cs copy];
        }
    
    return set;
}

+ (NSCharacterSet *)MADomainCharacterSet;
{
    static NSCharacterSet *set = nil;

    if(set == nil)
        {
        NSMutableCharacterSet *cs;

        cs = [[[self standardASCIICharacterSet] mutableCopy] autorelease];
        [cs removeCharactersInString:@"[]\n\\"];
        set = [cs copy];
        }

    return set;
}


//---------------------------------------------------------------------------------------
//	character sets for RFC1521/22
//---------------------------------------------------------------------------------------

+ (NSCharacterSet *)MIMETSpecialsCharacterSet;
{
    static NSCharacterSet *set = nil;

    if(set == nil)
        set = [[NSCharacterSet characterSetWithCharactersInString:@"()<>@,;:\\\"/[]?="] retain];
    
    return set;
}




+ (NSCharacterSet *)MIMETokenCharacterSet;
{
    static	NSCharacterSet *set = nil;

    if(set == nil)
        {
        NSMutableCharacterSet *tmpCharacterSet;
		NSCharacterSet *xs, *mts;

		mts = [self MIMETSpecialsCharacterSet];
        tmpCharacterSet = [[mts mutableCopy] autorelease];
        [tmpCharacterSet invert];
		xs = [NSCharacterSet characterSetWithRange:NSMakeRange(32, 95)];
        [tmpCharacterSet formIntersectionWithCharacterSet:xs];
        set = [tmpCharacterSet copy];
        }

    return set;
}


+ (NSCharacterSet *)MIMENonTokenCharacterSet;
{
    static	NSCharacterSet *set = nil;

    if(set == nil)
        set = [[[self MIMETokenCharacterSet] invertedSet] retain];

    return set;
}


+ (NSCharacterSet *)MIME1522DefaultLiteralCharacterSet;
{
    static	NSCharacterSet *set = nil;

    if(set == nil)
        {
        NSMutableCharacterSet *tmpCharacterSet;

        tmpCharacterSet = [[[NSCharacterSet characterSetWithRange:NSMakeRange(32, 95)] mutableCopy] autorelease];
        [tmpCharacterSet removeCharactersInString:@"=?_ "];
        set = [tmpCharacterSet copy];
        }

    return set;
}


//---------------------------------------------------------------------------------------
    @end
//---------------------------------------------------------------------------------------
