3 * Copyright (c) 2007, Blue Static <http://www.bluestatic.org>
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.
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.
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
19 @interface Word (Private
)
20 - (void)createAlphagram
;
27 * Creates a new word object
29 - (id)initWithWord
:(NSString
*)aWord
31 if (self = [super init
])
33 word
= [aWord retain
];
49 * Initialize an object from a keyed archive
51 - (id)initWithCoder
:(NSCoder
*)coder
54 word
= [[coder decodeObjectForKey
:@
"KAWord"] retain
];
55 alphagram
= [[coder decodeObjectForKey
:@
"KAAlphagram"] retain
];
60 * Encodes an object for serialization in a keyed archiver
62 - (void)encodeWithCoder
:(NSCoder
*)coder
64 [coder encodeObject
:word forKey
:@
"KAWord"];
65 [coder encodeObject
:alphagram forKey
:@
"KAAlphagram"];
77 * Gets the length of the word
85 * Returns the alphagram
87 - (NSString
*)alphagram
93 * Generates the alphagram for the word
95 - (void)createAlphagram
97 char *str
= (char *)[word UTF8String
];
100 for (int i
= 1; i
< [word length
]; i
++)
103 for (j
= i
; j
> 0 && temp
< str
[j
- 1]; j
--)
110 alphagram
= [[NSString stringWithUTF8String
:str
] retain
];
116 - (NSString
*)description
118 return [NSString stringWithFormat
:@
"<Word:%@/%@>", word
, alphagram
];