1/* StringsEntry 2 3 Copyright (C) 2002 Free Software Foundation, Inc. 4 5 Written by: Alexander Malmberg <alexander@malmberg.org> 6 Created: 2002 7 8 This file is part of the GNUstep Project 9 10 This program is free software; you can redistribute it and/or 11 modify it under the terms of the GNU General Public License 12 as published by the Free Software Foundation; either 13 version 3 of the License, or (at your option) any later version. 14 15 You should have received a copy of the GNU General Public 16 License along with this program; see the file COPYINGv3. 17 If not, write to the Free Software Foundation, 18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 20*/ 21 22#include <Foundation/NSObject.h> 23#include <Foundation/NSArray.h> 24#include <Foundation/NSEnumerator.h> 25#include <Foundation/NSString.h> 26 27#include "StringsEntry.h" 28 29#include "SourceEntry.h" 30 31 32@implementation StringsEntry 33 34+ stringsEntryFromSourceEntry: (SourceEntry *)e 35{ 36 return AUTORELEASE([[self alloc] initWithKey: [e key] comment: [e comment] translated: [e key] userComment: nil 37 flags: FLAG_UNTRANSLATED file: [e file] line: [e line]]); 38} 39 40 41- initWithKey: (NSString *)k comment: (NSString *)c translated: (NSString *)t userComment: (NSString *)uc 42 flags: (int)f file: (NSString *)filename line: (int)l 43{ 44 self=[super init]; 45 ASSIGN(key,k); 46 ASSIGN(comment,c); 47 ASSIGN(translated,t); 48 ASSIGN(user_comment,uc); 49 flags=f; 50 ASSIGN(file,filename); 51 line=l; 52 return self; 53} 54 55-(void) dealloc 56{ 57 DESTROY(key); 58 DESTROY(comment); 59 DESTROY(translated); 60 DESTROY(user_comment); 61 DESTROY(file); 62 [super dealloc]; 63} 64 65-(NSString *) key { return key; } 66-(NSString *) comment { return comment; } 67-(NSString *) translated { return translated; } 68-(NSString *) userComment { return user_comment; } 69 70-(int) flags { return flags; } 71 72-(NSString *) file { return file; } 73-(unsigned int) line { return line; } 74 75 76-(int) compareFileLine: (StringsEntry *)e 77{ 78 int res=[[self file] compare: [e file]]; 79 if (res!=NSOrderedSame) return res; 80 if ([self line]<[e line]) 81 return NSOrderedAscending; 82 else 83 return NSOrderedDescending; 84} 85 86-(int) compareFileKeyComment: (StringsEntry *)e 87{ 88 int res; 89 90 res=[[self file] compare: [e file]]; 91 if (res!=NSOrderedSame) return res; 92 93 res=[[self key] compare: [e key]]; 94 if (res!=NSOrderedSame) return res; 95 96 if (![self comment]) 97 return NSOrderedAscending; 98 if (![e comment]) 99 return NSOrderedDescending; 100 return [[self comment] compare: [e comment]]; 101} 102 103 104-(void) setKey: (NSString *)k { ASSIGN(key,k); } 105-(void) setComment: (NSString *)c { ASSIGN(comment,c); } 106-(void) setTranslated: (NSString *)t { ASSIGN(translated,t); } 107-(void) setUserComment: (NSString *)uc { ASSIGN(user_comment,uc); } 108 109-(void) setFlags: (int)f { flags=f; } 110-(void) addFlag: (int)f { flags|=f; } 111 112-(void) setFile: (NSString *)f { ASSIGN(file,f); } 113-(void) setLine: (unsigned int)l { line=l; } 114 115 116-(NSString *) description 117{ 118 return [NSString 119 stringWithFormat: @"(key='%@' comment='%@' at '%@':%i userComment='%@' translated='%@' flags=%02x)", 120 key,comment,file,line,user_comment,translated,flags]; 121} 122 123@end 124 125