about summary refs log tree commit diff stats
path: root/data/maps/the_nuanced/rooms/N2 Room.txtpb
blob: eb9f67cbb4a4b4636845a88a018128675d1b7171 (plain) (blame)
1
2
3
4
5
6
name: "N2 Room"
letters {
  key: "n"
  level2: true
  path: "Components/Collectables/collectable"
}
f='#n214'>214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
//
//  CDataScanner.m
//  TouchCode
//
//  Created by Jonathan Wight on 04/16/08.
//  Copyright 2008 toxicsoftware.com. All rights reserved.
//
//  Permission is hereby granted, free of charge, to any person
//  obtaining a copy of this software and associated documentation
//  files (the "Software"), to deal in the Software without
//  restriction, including without limitation the rights to use,
//  copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the
//  Software is furnished to do so, subject to the following
//  conditions:
//
//  The above copyright notice and this permission notice shall be
//  included in all copies or substantial portions of the Software.
//
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
//  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
//  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
//  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
//  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
//  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
//  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
//  OTHER DEALINGS IN THE SOFTWARE.
//

#import "CDataScanner.h"

#import "CDataScanner_Extensions.h"

@interface CDataScanner ()
@end

#pragma mark -

inline static unichar CharacterAtPointer(void *start, void *end)
    {
    #pragma unused(end)

    const u_int8_t theByte = *(u_int8_t *)start;
    if (theByte & 0x80)
        {
        // TODO -- UNICODE!!!! (well in theory nothing todo here)
        }
    const unichar theCharacter = theByte;
    return(theCharacter);
    }

    static NSCharacterSet *sDoubleCharacters = NULL;

    @implementation CDataScanner

- (id)init
    {
    if ((self = [super init]) != NULL)
        {
        }
    return(self);
    }

- (id)initWithData:(NSData *)inData;
    {
    if ((self = [self init]) != NULL)
        {
        [self setData:inData];
        }
    return(self);
    }

    + (void)initialize
    {
    if (sDoubleCharacters == NULL)
        {
        sDoubleCharacters = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789eE-+."] retain];
        }
    }

- (void)dealloc
    {
    [data release];
    data = NULL;
    //
    [super dealloc];
    }

- (NSUInteger)scanLocation
    {
    return(current - start);
    }

- (NSUInteger)bytesRemaining
    {
    return(end - current);
    }

- (NSData *)data
    {
    return(data);
    }

- (void)setData:(NSData *)inData
    {
    if (data != inData)
        {
        [data release];
        data = [inData retain];
        }

    if (data)
        {
        start = (u_int8_t *)data.bytes;
        end = start + data.length;
        current = start;
        length = data.length;
        }
    else
        {
        start = NULL;
        end = NULL;
        current = NULL;
        length = 0;
        }
    }

- (void)setScanLocation:(NSUInteger)inScanLocation
    {
    current = start + inScanLocation;
    }

- (BOOL)isAtEnd
    {
    return(self.scanLocation >= length);
    }

- (unichar)currentCharacter
    {
    return(CharacterAtPointer(current, end));
    }

#pragma mark -

- (unichar)scanCharacter
    {
    const unichar theCharacter = CharacterAtPointer(current++, end);
    return(theCharacter);
    }

- (BOOL)scanCharacter:(unichar)inCharacter
    {
    unichar theCharacter = CharacterAtPointer(current, end);
    if (theCharacter == inCharacter)
        {
        ++current;
        return(YES);
        }
    else
        return(NO);
    }

- (BOOL)scanUTF8String:(const char *)inString intoString:(NSString **)outValue
    {
    const size_t theLength = strlen(inString);
    if ((size_t)(end - current) < theLength)
        return(NO);
    if (strncmp((char *)current, inString, theLength) == 0)
        {
        current += theLength;
        if (outValue)
            *outValue = [NSString stringWithUTF8String:inString];
        return(YES);
        }
    return(NO);
    }

- (BOOL)scanString:(NSString *)inString intoString:(NSString **)outValue
    {
    if ((size_t)(end - current) < inString.length)
        return(NO);
    if (strncmp((char *)current, [inString UTF8String], inString.length) == 0)
        {
        current += inString.length;
        if (outValue)
            *outValue = inString;
        return(YES);
        }
    return(NO);
    }

- (BOOL)scanCharactersFromSet:(NSCharacterSet *)inSet intoString:(NSString **)outValue
    {
    u_int8_t *P;
    for (P = current; P < end && [inSet characterIsMember:*P] == YES; ++P)
        ;

    if (P == current)
        {
        return(NO);
        }

    if (outValue)
        {
        *outValue = [[[NSString alloc] initWithBytes:current length:P - current encoding:NSUTF8StringEncoding] autorelease];
        }

    current = P;

    return(YES);
    }

- (BOOL)scanUpToString:(NSString *)inString intoString:(NSString **)outValue
    {
    const char *theToken = [inString UTF8String];
    const char *theResult = strnstr((char *)current, theToken, end - current);
    if (theResult == NULL)
        {
        return(NO);
        }

    if (outValue)
        {
        *outValue = [[[NSString alloc] initWithBytes:current length:theResult - (char *)current encoding:NSUTF8StringEncoding] autorelease];
        }

    current = (u_int8_t *)theResult;

    return(YES);
    }

- (BOOL)scanUpToCharactersFromSet:(NSCharacterSet *)inSet intoString:(NSString **)outValue
    {
    u_int8_t *P;
    for (P = current; P < end && [inSet characterIsMember:*P] == NO; ++P)
        ;

    if (P == current)
        {
        return(NO);
        }

    if (outValue)
        {
        *outValue = [[[NSString alloc] initWithBytes:current length:P - current encoding:NSUTF8StringEncoding] autorelease];
        }

    current = P;

    return(YES);
    }

- (BOOL)scanNumber:(NSNumber **)outValue
        {
        NSString *theString = NULL;
        if ([self scanCharactersFromSet:sDoubleCharacters intoString:&theString])
            {
            if ([theString rangeOfString:@"."].location != NSNotFound)
                {
                if (outValue)
                    {
                    *outValue = [NSDecimalNumber decimalNumberWithString:theString];
                    }
                return(YES);
                }
            else if ([theString rangeOfString:@"-"].location != NSNotFound)
                {
                if (outValue != NULL)
                    {
                    *outValue = [NSNumber numberWithLongLong:[theString longLongValue]];
                    }
                return(YES);
                }
            else
                {
                if (outValue != NULL)
                    {
                    *outValue = [NSNumber numberWithUnsignedLongLong:strtoull([theString UTF8String], NULL, 0)];
                    }
                return(YES);
                }
            
            }
        return(NO);
        }
            
- (BOOL)scanDecimalNumber:(NSDecimalNumber **)outValue;
        {
        NSString *theString = NULL;
        if ([self scanCharactersFromSet:sDoubleCharacters intoString:&theString])
            {
            if (outValue)
                {
                *outValue = [NSDecimalNumber decimalNumberWithString:theString];
                }
            return(YES);
            }
        return(NO);
        }

- (BOOL)scanDataOfLength:(NSUInteger)inLength intoData:(NSData **)outData;
        {
        if (self.bytesRemaining < inLength)
            {
            return(NO);
            }
        
        if (outData)
            {
            *outData = [NSData dataWithBytes:current length:inLength];
            }

        current += inLength;
        return(YES);
        }


- (void)skipWhitespace
    {
    u_int8_t *P;
    for (P = current; P < end && (isspace(*P)); ++P)
        ;

    current = P;
    }

- (NSString *)remainingString
    {
    NSData *theRemainingData = [NSData dataWithBytes:current length:end - current];
    NSString *theString = [[[NSString alloc] initWithData:theRemainingData encoding:NSUTF8StringEncoding] autorelease];
    return(theString);
    }

- (NSData *)remainingData;
    {
    NSData *theRemainingData = [NSData dataWithBytes:current length:end - current];
    return(theRemainingData);
    }

    @end