Archived
1
This repository has been archived on 2022-08-08. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
mathpad/MathPad/MPParseError.m
2014-09-28 23:50:18 +02:00

50 lines
1.2 KiB
Objective-C

//
// MPParseError.m
// MathPad
//
// Created by Kim Wittenburg on 08.09.14.
// Copyright (c) 2014 Kim Wittenburg. All rights reserved.
//
#import "MPParseError.h"
#import "MPRangePath.h"
#import "NSIndexPath+MPAdditions.h"
@implementation MPParseError
- (instancetype)initWithErrorRange:(NSRange)errorRange errorMessageKey:(NSString *)key
{
self = [super init];
if (self) {
_errorRange = errorRange;
_localizedErrorMessage = NSLocalizedString(key, nil);
}
return self;
}
- (instancetype)initWithErrorRange:(NSRange)errorRange localizederrorMessage:(NSString *)errorMessage
{
self = [super init];
if (self) {
_errorRange = errorRange;
_localizedErrorMessage = errorMessage;
}
return self;
}
- (MPRangePath *)rangePath
{
NSIndexPath *location = self.pathToExpression;
location = [location indexPathByPreceedingIndex:self.errorRange.location];
MPRangePath *rangePath = [MPRangePath rangePathWithLocation:location length:self.errorRange.length];
return rangePath;
}
- (NSString *)description
{
return [NSString stringWithFormat:@"MPParseError<at=(%ld, %ld) message=\"%@\">", self.errorRange.location, self.errorRange.length, self.localizedErrorMessage];
}
@end