Removing the NSCoder methods of the Word class
[scrabbalize.git] / Source / Word.m
1 /*
2 * Scrabbalize
3 * Copyright (c) 2007-2008, Blue Static <http://www.bluestatic.org>
4 *
5 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6 * General Public License as published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
10 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along with this program; if not,
14 * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
15 */
16
17 #import "Word.h"
18
19 @interface Word (Private)
20 - (void)createAlphagram;
21 @end
22
23
24 @implementation Word
25
26 /**
27 * Creates a new word object
28 */
29 - (id)initWithWord:(NSString *)aWord
30 {
31 if (self = [super init])
32 {
33 word = [aWord retain];
34 [self createAlphagram];
35 }
36 return self;
37 }
38
39 /**
40 * Destructor
41 */
42 - (void)dealloc
43 {
44 [word release];
45 [alphagram release];
46 [super dealloc];
47 }
48
49 /**
50 * Returns the word
51 */
52 - (NSString *)word
53 {
54 return word;
55 }
56
57 /**
58 * Gets the length of the word
59 */
60 - (int)length
61 {
62 return [word length];
63 }
64
65 /**
66 * Returns the alphagram
67 */
68 - (NSString *)alphagram
69 {
70 return alphagram;
71 }
72
73 /**
74 * Generates the alphagram for the word
75 */
76 - (void)createAlphagram
77 {
78 char *str = (char *)[word UTF8String];
79
80 int j;
81 for (int i = 1; i < [word length]; i++)
82 {
83 char temp = str[i];
84 for (j = i; j > 0 && temp < str[j - 1]; j--)
85 {
86 str[j] = str[j - 1];
87 }
88 str[j] = temp;
89 }
90
91 alphagram = [[NSString stringWithUTF8String:str] retain];
92 }
93
94 /**
95 * Description method
96 */
97 - (NSString *)description
98 {
99 return [NSString stringWithFormat:@"<Word:%@/%@>", word, alphagram];
100 }
101
102 @end