Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 5e3afaa783
Fetching contributors…

Cannot retrieve contributors at this time

file 91 lines (79 sloc) 2.356 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
//
// CPTestMapCSSTokenisingDelegate.m
// CoreParse
//
// Created by Tom Davie on 15/03/2011.
// Copyright 2011 In The Beginning... All rights reserved.
//

#import "CPTestMapCSSTokenisingDelegate.h"

@implementation CPTestMapCSSTokenisingDelegate
{
    NSCharacterSet *symbolsSet;
    int nestingDepth;
    BOOL justTokenisedObject;
    BOOL inRange;
}

- (id)init
{
    self = [super init];
    
    if (nil != self)
    {
        symbolsSet = [[NSCharacterSet characterSetWithCharactersInString:@"*[]{}().,;@|-!=<>:!"] retain];
    }
    
    return self;
}

- (void)dealloc
{
    [symbolsSet release];
    
    [super dealloc];
}

- (BOOL)tokeniser:(CPTokeniser *)tokeniser shouldConsumeToken:(CPToken *)token
{
    NSString *name = [token name];
    if ([name isEqualToString:@"{"] || [name isEqualToString:@"["])
    {
        nestingDepth++;
    }
    else if ([name isEqualToString:@"}"] || [name isEqualToString:@"]"])
    {
        nestingDepth--;
    }
    else if ([name isEqualToString:@"|z"])
    {
        inRange = YES;
    }
    else if (inRange && ![token isNumberToken] && ![name isEqualToString:@"-"])
    {
        inRange = NO;
    }
    else if (inRange && [token isNumberToken])
    {
        return [[(CPNumberToken *)token number] floatValue] >= 0;
    }
    else if ([token isKeywordToken])
    {
        return 0 == nestingDepth || [symbolsSet characterIsMember:[name characterAtIndex:0]] || [name isEqualToString:@"eval"] || [name isEqualToString:@"url"] || [name isEqualToString:@"set"] || [name isEqualToString:@"pt"] || [name isEqualToString:@"px"];
    }
    
    return YES;
}

- (void)tokeniser:(CPTokeniser *)tokeniser requestsToken:(CPToken *)token pushedOntoStream:(CPTokenStream *)stream
{
    if ([token isWhiteSpaceToken])
    {
        if (justTokenisedObject)
        {
            [stream pushToken:token];
        }
    }
    else
    {
        NSString *name = [token name];
        justTokenisedObject = ([name isEqualToString:@"node"] || [name isEqualToString:@"way" ] || [name isEqualToString:@"relation"] ||
                               [name isEqualToString:@"area"] || [name isEqualToString:@"line"] || [name isEqualToString:@"canvas"] || [name isEqualToString:@"*"]);
        
        if (![name isEqualToString:@"Comment"])
        {
            [stream pushToken:token];
        }
    }
}

@end
Something went wrong with that request. Please try again.